Skip to content

Instantly share code, notes, and snippets.

@jayvdb
Forked from bvigueras/clang-format@6.rb
Last active June 6, 2021 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayvdb/3e680baf7c265d0b1bfe704d72315e49 to your computer and use it in GitHub Desktop.
Save jayvdb/3e680baf7c265d0b1bfe704d72315e49 to your computer and use it in GitHub Desktop.
clang-format version 6 (6.0.1) formula for brew
class ClangFormatAT6 < Formula
desc "Formatting tool for C/C++/Java/JavaScript/Objective-C/Protobuf"
homepage "https://releases.llvm.org/6.0.1/tools/clang/docs/ClangFormat.html"
version "6.0.1"
if MacOS.version >= :sierra
url "https://releases.llvm.org/6.0.1/llvm-6.0.1.src.tar.xz"
sha256 "b6d6c324f9c71494c0ccaf3dac1f16236d970002b42bb24a6c9e1634f7d0f4e2"
else
url "http://releases.llvm.org/6.0.1/llvm-6.0.1.src.tar.xz"
sha256 "b6d6c324f9c71494c0ccaf3dac1f16236d970002b42bb24a6c9e1634f7d0f4e2"
end
depends_on "cmake" => :build
depends_on "ninja" => :build
resource "clang" do
if MacOS.version >= :sierra
url "https://releases.llvm.org/6.0.1/cfe-6.0.1.src.tar.xz"
sha256 "7c243f1485bddfdfedada3cd402ff4792ea82362ff91fbdac2dae67c6026b667"
else
url "http://releases.llvm.org/6.0.1/cfe-6.0.1.src.tar.xz"
sha256 "7c243f1485bddfdfedada3cd402ff4792ea82362ff91fbdac2dae67c6026b667"
end
end
resource "libcxx" do
url "https://releases.llvm.org/6.0.1/libcxx-6.0.1.src.tar.xz"
sha256 "7654fbc810a03860e6f01a54c2297a0b9efb04c0b9aa0409251d9bdb3726fc67"
end
resource "clang-tools-extra" do
url "https://releases.llvm.org/6.0.1/clang-tools-extra-6.0.1.src.tar.xz"
sha256 "0d2e3727786437574835b75135f9e36f861932a958d8547ced7e13ebdda115f1"
end
def install
(buildpath/"projects/libcxx").install resource("libcxx")
(buildpath/"tools/clang").install resource("clang")
(buildpath/".."/"clang-tools-extra").install resource("clang-tools-extra")
mkdir "build" do
args = std_cmake_args
args << "-DCMAKE_OSX_SYSROOT=/" unless MacOS::Xcode.installed?
args << "-DLLVM_ENABLE_LIBCXX=ON"
args << "-DLLVM_ENABLE_PROJECTS=clang-tools-extra"
args << ".."
system "cmake", "-G", "Ninja", *args
system "ninja", "clang-format", "clang-tidy"
bin.install "bin/clang-format" => "clang-format-6.0"
bin.install "bin/clang-tidy" => "clang-tidy-6.0"
end
bin.install "tools/clang/tools/clang-format/git-clang-format" => "git-clang-format-6.0"
(share/"clang-format-6.0").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