From eb224ef236c2ab072f4c0d5f64a3812ab7058792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6reth?= Date: Mon, 20 Mar 2023 23:08:02 +0100 Subject: [PATCH] Re-add clang-format-15 formula from #4 --- Formula/clang-format@15.rb | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Formula/clang-format@15.rb diff --git a/Formula/clang-format@15.rb b/Formula/clang-format@15.rb new file mode 100644 index 0000000..57de289 --- /dev/null +++ b/Formula/clang-format@15.rb @@ -0,0 +1,82 @@ +class ClangFormatAT15 < Formula + desc "Formatting tools for C, C++, Obj-C, Java, JavaScript, TypeScript" + homepage "https://clang.llvm.org/docs/ClangFormat.html" + # The LLVM Project is under the Apache License v2.0 with LLVM Exceptions + license "Apache-2.0" + version_scheme 1 + head "https://github.com/llvm/llvm-project.git", branch: "main" + + stable do + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/llvm-15.0.7.src.tar.xz" + sha256 "4ad8b2cc8003c86d0078d15d987d84e3a739f24aae9033865c027abae93ee7a4" + + resource "clang" do + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang-15.0.7.src.tar.xz" + sha256 "a6b673ef15377fb46062d164e8ddc4d05c348ff8968f015f7f4af03f51000067" + end + + resource "cmake" do + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/cmake-15.0.7.src.tar.xz" + sha256 "8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea" + end + end + + livecheck do + url :stable + regex(%r{href=.*?/tag/llvmorg[._-]v?(\d+(?:\.\d+)+)}i) + strategy :github_latest + end + + depends_on "cmake" => [:build, :test] + + uses_from_macos "python" => [:build, :test], since: :catalina + uses_from_macos "libxml2" + uses_from_macos "ncurses" + uses_from_macos "zlib" + + on_linux do + keg_only "it conflicts with llvm" + end + + def install + llvmpath = if build.head? + ln_s buildpath/"clang", buildpath/"llvm/tools/clang" + + buildpath/"llvm" + else + (buildpath/"src").install buildpath.children + (buildpath/"src/tools/clang").install resource("clang") + (buildpath/"cmake").install resource("cmake") + + buildpath/"src" + end + + system "cmake", "-S", llvmpath, "-B", "build", + "-DLLVM_EXTERNAL_PROJECTS=clang", + "-DLLVM_INCLUDE_BENCHMARKS=OFF", + *std_cmake_args + system "cmake", "--build", "build", "--target", "clang-format" + + bin.install "build/bin/clang-format" => "clang-format-15" + bin.install llvmpath/"tools/clang/tools/clang-format/git-clang-format" => "git-clang-format-15" + # (share/"clang").install llvmpath.glob("tools/clang/tools/clang-format/clang-format*") + end + + test do + system "git", "init" + system "git", "commit", "--allow-empty", "-m", "initial commit", "--quiet" + + # NB: below C code is messily formatted on purpose. + (testpath/"test.c").write <<~EOS + int main(char *args) { \n \t printf("hello"); } + EOS + system "git", "add", "test.c" + + assert_equal "int main(char *args) { printf(\"hello\"); }\n", + shell_output("#{bin}/clang-format-15 -style=Google test.c") + + # Fails with 'error: cannot find executable "clang-format"'. + # ENV.prepend_path "PATH", bin + # assert_match "test.c", shell_output("git clang-format-15", 1) + end +end