Skip to content

Commit fc7c263

Browse files
committed
Add clang-format 18.1.8
1 parent 16112a1 commit fc7c263

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

Formula/clang-format@18.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
class ClangFormatAT18 < Formula
2+
desc "Formatting tools for C, C++, Obj-C, Java, JavaScript, TypeScript"
3+
homepage "https://clang.llvm.org/docs/ClangFormat.html"
4+
# The LLVM Project is under the Apache License v2.0 with LLVM Exceptions
5+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/llvm-18.1.8.src.tar.xz"
6+
sha256 "f68cf90f369bc7d0158ba70d860b0cb34dbc163d6ff0ebc6cfa5e515b9b2e28d"
7+
license "Apache-2.0"
8+
version_scheme 1
9+
head "https://github.com/llvm/llvm-project.git", branch: "main"
10+
11+
livecheck do
12+
url :stable
13+
regex(/llvmorg[._-]v?(\d+(?:\.\d+)+)/i)
14+
strategy :github_latest
15+
end
16+
17+
depends_on "cmake" => :build
18+
depends_on "ninja" => :build
19+
20+
uses_from_macos "libxml2"
21+
uses_from_macos "ncurses"
22+
uses_from_macos "python", since: :catalina
23+
uses_from_macos "zlib"
24+
25+
on_linux do
26+
keg_only "it conflicts with llvm"
27+
end
28+
29+
resource "clang" do
30+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang-18.1.8.src.tar.xz"
31+
sha256 "5724fe0a13087d5579104cedd2f8b3bc10a212fb79a0fcdac98f4880e19f4519"
32+
end
33+
34+
resource "cmake" do
35+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/cmake-18.1.8.src.tar.xz"
36+
sha256 "59badef592dd34893cd319d42b323aaa990b452d05c7180ff20f23ab1b41e837"
37+
end
38+
39+
resource "third-party" do
40+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/third-party-18.1.8.src.tar.xz"
41+
sha256 "b76b810f3d3dc5d08e83c4236cb6e395aa9bd5e3ea861e8c319b216d093db074"
42+
end
43+
44+
def install
45+
odie "clang resource needs to be updated" if build.stable? && version != resource("clang").version
46+
odie "cmake resource needs to be updated" if build.stable? && version != resource("cmake").version
47+
odie "third-party resource needs to be updated" if build.stable? && version != resource("third-party").version
48+
49+
llvmpath = if build.head?
50+
ln_s buildpath/"clang", buildpath/"llvm/tools/clang"
51+
52+
buildpath/"llvm"
53+
else
54+
(buildpath/"src").install buildpath.children
55+
(buildpath/"src/tools/clang").install resource("clang")
56+
(buildpath/"cmake").install resource("cmake")
57+
(buildpath/"third-party").install resource("third-party")
58+
59+
buildpath/"src"
60+
end
61+
62+
system "cmake", "-G", "Ninja", "-S", llvmpath, "-B", "build",
63+
"-DLLVM_EXTERNAL_PROJECTS=clang",
64+
"-DLLVM_INCLUDE_BENCHMARKS=OFF",
65+
"-DLLVM_INCLUDE_TESTS=OFF",
66+
*std_cmake_args
67+
system "cmake", "--build", "build", "--target", "clang-format"
68+
69+
git_clang_format = llvmpath/"tools/clang/tools/clang-format/git-clang-format"
70+
inreplace git_clang_format, /clang-format/, "clang-format-18"
71+
72+
bin.install "build/bin/clang-format" => "clang-format-18"
73+
bin.install git_clang_format => "git-clang-format-18"
74+
(share/"clang").install llvmpath.glob("tools/clang/tools/clang-format/clang-format*")
75+
end
76+
77+
test do
78+
system "git", "init"
79+
system "git", "commit", "--allow-empty", "-m", "initial commit", "--quiet"
80+
81+
# NB: below C code is messily formatted on purpose.
82+
(testpath/"test.c").write <<~EOS
83+
int main(char *args) { \n \t printf("hello"); }
84+
EOS
85+
system "git", "add", "test.c"
86+
87+
assert_equal "int main(char *args) { printf(\"hello\"); }\n",
88+
shell_output("#{bin}/clang-format-18 -style=Google test.c")
89+
90+
ENV.prepend_path "PATH", bin
91+
assert_match "test.c", shell_output("git clang-format-18", 1)
92+
end
93+
end

0 commit comments

Comments
 (0)