107 lines
4.0 KiB
Ruby
107 lines
4.0 KiB
Ruby
class Bazel < Formula
|
|
desc "Google's own build tool"
|
|
homepage "https://bazel.build/"
|
|
url "https://github.com/bazelbuild/bazel/releases/download/5.2.0/bazel-5.2.0-dist.zip"
|
|
sha256 "820a94dbb14071ed6d8c266cf0c080ecb265a5eea65307579489c4662c2d582a"
|
|
license "Apache-2.0"
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(/^v?(\d+(?:\.\d+)+)$/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_monterey: "418ec820bfac74c2481c1a84cb4cbd0475a17d115a1ba4c73bd32c4e04f5f921"
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "91d8679263d8d0be9d1dcb119b8785c81614f6f75147f449ef56691811553d95"
|
|
sha256 cellar: :any_skip_relocation, monterey: "32308420766fc56b97477bb5b64106db142f1c38fd2c2599178aa03e72937754"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "ad90a53b89ef024228e2e860574396f1d72d08555e8b925abb23ce705cde116a"
|
|
sha256 cellar: :any_skip_relocation, catalina: "5041095436013f8ad8270a76bbb848712ce3fd4673ec71a987608af6c6dd5333"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "52143acfb0462a4e137d4e8f8c2be003a9796877616a7012d1a12b20e72a8f92"
|
|
end
|
|
|
|
depends_on "python@3.10" => :build
|
|
depends_on "openjdk@11"
|
|
|
|
uses_from_macos "unzip"
|
|
uses_from_macos "zip"
|
|
|
|
conflicts_with "bazelisk", because: "Bazelisk replaces the bazel binary"
|
|
|
|
def install
|
|
ENV["EMBED_LABEL"] = "#{version}-homebrew"
|
|
# Force Bazel ./compile.sh to put its temporary files in the buildpath
|
|
ENV["BAZEL_WRKDIR"] = buildpath/"work"
|
|
# Force Bazel to use openjdk@11
|
|
ENV["EXTRA_BAZEL_ARGS"] = "--host_javabase=@local_jdk//:jdk"
|
|
ENV["JAVA_HOME"] = Language::Java.java_home("11")
|
|
# Force Bazel to use Homebrew python
|
|
ENV.prepend_path "PATH", Formula["python@3.10"].opt_libexec/"bin"
|
|
|
|
# Bazel clears environment variables other than PATH during build, which
|
|
# breaks Homebrew shim scripts. We don't see this issue on macOS since
|
|
# the build uses a Bazel-specific wrapper for clang rather than the shim;
|
|
# specifically, it uses `external/local_config_cc/wrapped_clang`.
|
|
#
|
|
# The workaround here is to disable the Linux shim for C/C++ compilers.
|
|
# Remove this when a way to retain HOMEBREW_* variables is found.
|
|
if OS.linux?
|
|
ENV["CC"] = "/usr/bin/cc"
|
|
ENV["CXX"] = "/usr/bin/c++"
|
|
end
|
|
|
|
(buildpath/"sources").install buildpath.children
|
|
|
|
cd "sources" do
|
|
system "./compile.sh"
|
|
system "./output/bazel", "--output_user_root",
|
|
buildpath/"output_user_root",
|
|
"build",
|
|
"scripts:bash_completion"
|
|
|
|
bin.install "scripts/packages/bazel.sh" => "bazel"
|
|
ln_s libexec/"bin/bazel-real", bin/"bazel-#{version}"
|
|
(libexec/"bin").install "output/bazel" => "bazel-real"
|
|
bin.env_script_all_files libexec/"bin", Language::Java.java_home_env("11")
|
|
|
|
bash_completion.install "bazel-bin/scripts/bazel-complete.bash"
|
|
zsh_completion.install "scripts/zsh_completion/_bazel"
|
|
end
|
|
end
|
|
|
|
test do
|
|
touch testpath/"WORKSPACE"
|
|
|
|
(testpath/"ProjectRunner.java").write <<~EOS
|
|
public class ProjectRunner {
|
|
public static void main(String args[]) {
|
|
System.out.println("Hi!");
|
|
}
|
|
}
|
|
EOS
|
|
|
|
(testpath/"BUILD").write <<~EOS
|
|
java_binary(
|
|
name = "bazel-test",
|
|
srcs = glob(["*.java"]),
|
|
main_class = "ProjectRunner",
|
|
)
|
|
EOS
|
|
|
|
system bin/"bazel", "build", "//:bazel-test"
|
|
assert_equal "Hi!\n", pipe_output("bazel-bin/bazel-test")
|
|
|
|
# Verify that `bazel` invokes Bazel's wrapper script, which delegates to
|
|
# project-specific `tools/bazel` if present. Invoking `bazel-VERSION`
|
|
# bypasses this behavior.
|
|
(testpath/"tools"/"bazel").write <<~EOS
|
|
#!/bin/bash
|
|
echo "stub-wrapper"
|
|
exit 1
|
|
EOS
|
|
(testpath/"tools/bazel").chmod 0755
|
|
|
|
assert_equal "stub-wrapper\n", shell_output("#{bin}/bazel --version", 1)
|
|
assert_equal "bazel #{version}-homebrew\n", shell_output("#{bin}/bazel-#{version} --version")
|
|
end
|
|
end
|