-
-
Save ffeu/0460bb1349fa7e4ab4c459a6192cbb25 to your computer and use it in GitHub Desktop.
class ClangFormatAT7 < Formula | |
desc "Formatting tool for C/C++/Java/JavaScript/Objective-C/Protobuf" | |
homepage "https://releases.llvm.org/7.0.0/tools/clang/docs/ClangFormat.html" | |
version "7.0.0" | |
if MacOS.version >= :sierra | |
url "https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_700/final/", :using => :svn | |
else | |
url "http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_700/final/", :using => :svn | |
end | |
depends_on "cmake" => :build | |
depends_on "ninja" => :build | |
depends_on "subversion" => :build | |
resource "clang" do | |
if MacOS.version >= :sierra | |
url "https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_700/final/", :using => :svn | |
else | |
url "http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_700/final/", :using => :svn | |
end | |
end | |
resource "libcxx" do | |
url "https://releases.llvm.org/7.0.0/libcxx-7.0.0.src.tar.xz" | |
sha256 "9b342625ba2f4e65b52764ab2061e116c0337db2179c6bce7f9a0d70c52134f0" | |
end | |
def install | |
(buildpath/"projects/libcxx").install resource("libcxx") | |
(buildpath/"tools/clang").install resource("clang") | |
mkdir "build" do | |
args = std_cmake_args | |
args << "-DCMAKE_OSX_SYSROOT=/" unless MacOS::Xcode.installed? | |
args << "-DLLVM_ENABLE_LIBCXX=ON" | |
args << ".." | |
system "cmake", "-G", "Ninja", *args | |
system "ninja", "clang-format" | |
bin.install "bin/clang-format" | |
end | |
bin.install "tools/clang/tools/clang-format/git-clang-format" | |
(share/"clang").install Dir["tools/clang/tools/clang-format/clang-format*"] | |
end | |
test do | |
# NB: below C code is messily formatted on purpose. | |
(testpath/"test.c").write <<~EOS | |
int main(char *args) { \n \t printf("hello"); } | |
EOS | |
assert_equal "int main(char *args) { printf(\"hello\"); }\n", | |
shell_output("#{bin}/clang-format -style=Google test.c") | |
# below code is messily formatted on purpose. | |
(testpath/"test2.h").write <<~EOS | |
#import "package/file.h" | |
@interface SomePlugin : NSObject < ParentPlugin > | |
@end | |
EOS | |
# NOTE! different formatting depending on version | |
# clang-format 5.x | |
# @interface SomePlugin : NSObject<ParentPlugin> | |
# clang-format 6.x, 7.x | |
# @interface SomePlugin : NSObject <ParentPlugin> | |
assert_equal "#import \"package/file.h\"\n@interface SomePlugin : NSObject <ParentPlugin>\n@end\n", | |
shell_output("#{bin}/clang-format -style=Google test2.h") | |
end | |
end |
Thank you so much for this! It saved my day months ago.
Now I have forked it since I need the version to match 6.0.0.
I couldn't find any Licence notice, so I hope you don't mind :)
I'm glad it was useful. You can use it and improve it.
I have another one for the 5.0.2 version but I never had to create one for the 6! :)
Hi @ffeu. Thanks for this. I'm stuck in the installation.
Could you please have a look and see if you can help me point the error at the top of your head.
The issue is I'm not able to move ahead of this step. It's over 4 hours since it has been cloning the repository.
I tried running brew install clang-format and it works fine. But the requirement dictates me to have version 7.0. Could you see what might be going wrong?
Thanks!
try taking a look where it clones the repository and try to do it manually (clone it manually), it's looks like the problem is related to that...
As llvm.org/svn seems not working (forbidden), one can use pre-built binary from https://releases.llvm.org/download.html
For example, for 7.0.0 and macOS:
- Download https://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-apple-darwin.tar.xz
- Extract archive
- Add
<path to extracted folder>/bin
to path - Use
clang-format
command!
To install this, download this formula locally and install it with brew. The formula will download the original
clang-format
code (version 7.0.0) from their SVN and build it locally - it takes about 15 minutes.Installing
These are the commands to download and install:
If you already have
clang-format
installed (for instance with a newer version), you'll need to run an additional command, that keep both versions installed but switches theclang-format
command line to point to the version 7.Validating
Run:
If the result is:
You're all set!!
Uninstalling
To uninstall it: