Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format@14: 14.0.6 #110

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class ClangFormatAT14 < Formula
desc "Formatting tools for C, C++, Obj-C, Java, JavaScript, TypeScript"
homepage "https://clang.llvm.org/docs/ClangFormat.html"
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/llvm-14.0.6.src.tar.xz"
sha256 "050922ecaaca5781fdf6631ea92bc715183f202f9d2f15147226f023414f619a"
license "Apache-2.0"

livecheck do
url :stable
regex(/llvmorg[._-]v?(\d+(?:\.\d+)+)/i)
strategy :github_latest
end

depends_on "cmake" => :build

uses_from_macos "libxml2"
uses_from_macos "ncurses"
uses_from_macos "python", since: :catalina
uses_from_macos "zlib"

on_linux do
keg_only "it conflicts with llvm"
end

resource "clang" do
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/clang-14.0.6.src.tar.xz"
sha256 "2b5847b6a63118b9efe5c85548363c81ffe096b66c3b3675e953e26342ae4031"
end

def install
resource("clang").stage do |r|
(buildpath/"llvm-#{version}.src/tools/clang").install Pathname("clang-#{r.version}.src").children
end

llvmpath = buildpath/"llvm-#{version}.src"

system "cmake", "-S", llvmpath, "-B", "build",
"-DLLVM_EXTERNAL_PROJECTS=clang",
"-DLLVM_INCLUDE_BENCHMARKS=OFF",
*std_cmake_args
system "cmake", "--build", "build", "--target", "clang-format"

git_clang_format = llvmpath/"tools/clang/tools/clang-format/git-clang-format"
inreplace git_clang_format, %r{^#!/usr/bin/env python$}, "#!/usr/bin/env python3"

bin.install buildpath/"build/bin/clang-format" => "clang-format-14"
bin.install git_clang_format => "git-clang-format-14"
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-14 -style=Google test.c")
end
end
Loading