-
-
Notifications
You must be signed in to change notification settings - Fork 12.4k
/
bazel.rb
92 lines (77 loc) · 3.12 KB
/
bazel.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class Bazel < Formula
desc "Google's own build tool"
homepage "https://bazel.build/"
url "https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-dist.zip"
sha256 "d7f40d0cac95a06cea6cb5b7f7769085257caebc3ee84269dd9298da760d5615"
bottle do
cellar :any_skip_relocation
sha256 "779187b2f828f2df03cbac87bf37eb6751cc0e98d129af8c26a068e60357ab3d" => :catalina
sha256 "47174013d48223853e968c2b12fb24e702d14883453eaf8eaea23229ff0990a5" => :mojave
sha256 "166729984573d0f70b2e16322d5bdab350c7ddec411afa7c8330dfa20fa7be1e" => :high_sierra
end
depends_on "[email protected]" => :build
depends_on :java => "1.8"
depends_on :macos => :yosemite
uses_from_macos "zip"
def install
ENV["EMBED_LABEL"] = "#{version}-homebrew"
# Force Bazel ./compile.sh to put its temporary files in the buildpath
ENV["BAZEL_WRKDIR"] = buildpath/"work"
(buildpath/"sources").install buildpath.children
cd "sources" do
system "./compile.sh"
system "./output/bazel",
"--output_user_root",
buildpath/"output_user_root",
"build",
"--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8",
"--java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8",
"--host_javabase=@bazel_tools//tools/jdk:jdk",
"--javabase=@bazel_tools//tools/jdk:jdk",
"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("1.8"))
bash_completion.install "bazel-bin/scripts/bazel-complete.bash"
zsh_completion.install "scripts/zsh_completion/_bazel"
prefix.install_metafiles
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",
"--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8",
"--java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8",
"--host_javabase=@bazel_tools//tools/jdk:jdk",
"--javabase=@bazel_tools//tools/jdk:jdk",
"//: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