Skip to content

Commit

Permalink
Re-add clang-format-15 formula from #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoereth committed Mar 20, 2023
1 parent c106a6a commit eb224ef
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions Formula/clang-format@15.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eb224ef

Please sign in to comment.