Created
October 9, 2019 01:04
-
-
Save elvizlai/28c88c0c4954b8e2a9f9c44b27d40306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClangFormatAT9 < Formula | |
desc "Formatting tool for C/C++/Java/JavaScript/Objective-C/Protobuf" | |
homepage "https://releases.llvm.org/9.0.0/tools/clang/docs/ClangFormat.html" | |
version "9.0.0" | |
if MacOS.version >= :sierra | |
url "https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_900/final/", :using => :svn | |
else | |
url "http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_900/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_900/final/", :using => :svn | |
else | |
url "http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_900/final/", :using => :svn | |
end | |
end | |
resource "libcxx" do | |
url "https://releases.llvm.org/9.0.0/libcxx-9.0.0.src.tar.xz" | |
sha256 "3c4162972b5d3204ba47ac384aa456855a17b5e97422723d4758251acf1ed28c" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install this, download this formula locally and install it with brew. The formula will download the original clang-format code (version 9.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 the clang-format command line to point to the version 9.
Validating
Run:
If the result is:
You're all set!!
Uninstalling
To uninstall it: