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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
# Packaging
md5_cmd = "set -e -o pipefail && cat $(SRCS) | sort | %s | awk '{ print $$1; }' > $@"
# TODO(bazel-team): find a better way to handle dylib extensions.
filegroup(
name = "libunix",
srcs = select({
":darwin": ["//src/main/native:libunix.dylib"],
":darwin_x86_64": ["//src/main/native:libunix.dylib"],
":windows": ["//src/main/native:windows_jni.dll"],
":windows_msvc": ["//src/main/native:windows_jni.dll"],
"//conditions:default": ["//src/main/native:libunix.so"],
}),
visibility = [
"//src/test/java:__pkg__",
"//src/tools/generate_workspace:__pkg__",
"//src/tools/remote_worker:__subpackages__",
],
)
[genrule(
name = "install_base_key-file" + suffix,
srcs = [
"//src/main/java/com/google/devtools/build/lib:bazel/BazelServer_deploy.jar",
"//src/main/cpp:client",
":libunix",
"//src/main/tools:build-runfiles",
"//src/main/tools:process-wrapper",
"//src/main/tools:linux-sandbox",
"//src/main/tools:build_interface_so",
"//tools/osx:xcode-locator",
] + embedded_tools,
outs = ["install_base_key" + suffix],
cmd = select({
":darwin": md5_cmd % "/sbin/md5",
":darwin_x86_64": md5_cmd % "/sbin/md5",
":freebsd": md5_cmd % "/sbin/md5",
"//conditions:default": md5_cmd % "md5sum",
}),
) for suffix, embedded_tools in {
"": [":embedded_tools"],
"_notools": [],
}.items()]
# Try to grab the java version from the java_toolchain.
# Unfortunately, we don't have access to the javac options
# so we cannot get it from the command-line options.
genquery(
name = "java_toolchain_content",
expression = "kind(java_toolchain, deps(//tools/defaults:java_toolchain))",
opts = ["--output=xml"],
scope = ["//tools/defaults:java_toolchain"],
)
genrule(
name = "java-version",
srcs = [":java_toolchain_content"],
outs = ["java.version"],
cmd = """
VERSION_LINE=$$(cat $< | grep target_version);
JAVA_VERSION=$$(echo $${VERSION_LINE} | sed 's/.*value=\\"\\([^\\"]\\)\\".*/\\1/');
if [ -z "$${JAVA_VERSION}" ]; then
echo "1.8" >$@ # Java 8 is the default
elif [[ "$${JAVA_VERSION}" =~ ^[0-9]+$$ ]]; then
echo "1.$${JAVA_VERSION}" >$@ # Add 1. before 7 or 8
else
echo "$${JAVA_VERSION}" >$@
fi
""",
)
# Create dummy tools so we can do select to prevent building iOS target on
# Linux.
OSX_DUMMY_TARGETS = [
"src/tools/xcode/actoolwrapper/actoolwrapper",
"src/tools/xcode/ibtoolwrapper/ibtoolwrapper",
"src/tools/xcode/libtool/libtool",
"src/tools/xcode/libtool/make_hashed_objlist.py",
"src/tools/xcode/momcwrapper/momcwrapper",
"src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper",
"src/tools/xcode/environment/environment_plist",
"src/tools/xcode/xcrunwrapper/xcrunwrapper",
"src/objc_tools/bundlemerge/bundlemerge_deploy.jar",
"src/objc_tools/plmerge/plmerge_deploy.jar",
"src/objc_tools/xcodegen/xcodegen_deploy.jar",
"src/tools/xcode/realpath/realpath",
"src/tools/xcode/stdredirect/StdRedirect.dylib",
]
[
genrule(
name = "dummy_darwin_tool_" + name.replace("/", "_"),
srcs = [],
outs = ["dummy_darwin_tools/" + name],
cmd = "touch $@",
)
for name in OSX_DUMMY_TARGETS
]
filegroup(
name = "darwin_tools",
srcs = [
"//src/tools/xcode/actoolwrapper:actoolwrapper",
"//src/tools/xcode/ibtoolwrapper:ibtoolwrapper",
"//src/tools/xcode/libtool:libtool_srcs",
"//src/tools/xcode/momcwrapper:momcwrapper",
"//src/tools/xcode/swiftstdlibtoolwrapper:swiftstdlibtoolwrapper",
"//src/tools/xcode/environment:environment_plist",
"//src/tools/xcode/xcrunwrapper:xcrunwrapper",
"//src/objc_tools/bundlemerge:bundlemerge_deploy.jar",
"//src/objc_tools/plmerge:plmerge_deploy.jar",
"//src/objc_tools/xcodegen:xcodegen_deploy.jar",
"//src/tools/xcode/realpath:realpath",
"//tools/osx:xcode_locator.m",
] + select({
":iphonesdk": ["//src/tools/xcode/stdredirect:StdRedirect.dylib"],
"//conditions:default": [":dummy_darwin_tool_src_tools_xcode_stdredirect_StdRedirect.dylib"],
}),
)
filegroup(
name = "dummy_darwin_tools",
srcs = [
"dummy_darwin_tool_" + name.replace("/", "_")
for name in OSX_DUMMY_TARGETS
],
)
genrule(
name = "embedded_tools",
srcs = [
":create_embedded_tools.sh",
"//tools:embedded_tools_srcs",
"//third_party:gpl-srcs",
"//third_party/java/jarjar:srcs",
"//third_party/java/jdk/langtools:test-srcs",
"//third_party/py/concurrent:srcs",
"//third_party/py/gflags:srcs",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper:srcs",
"//src/tools/android/java/com/google/devtools/build/android:embedded_tools",
"//src/tools/android/java/com/google/devtools/build/android/ideinfo:embedded_tools",
"//src/tools/android/java/com/google/devtools/build/android/idlclass:embedded_tools",
"//src/tools/android/java/com/google/devtools/build/android/incrementaldeployment:srcs",
"//src/tools/android/java/com/google/devtools/build/android/ziputils:embedded_tools",
"//src/main/protobuf:srcs",
"//src/java_tools/buildjar:JavaBuilderDeploy",
"//src/java_tools/singlejar:SingleJar_deploy.jar",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass:GenClass_deploy.jar",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner:Runner_deploy.jar",
"//src/java_tools/junitrunner/java/com/google/testing/coverage:embedded_tools",
"//third_party/ijar",
"//third_party/java/apkbuilder:embedded_tools",
"//third_party/java/jacoco:srcs",
] + select({
":darwin": [
":darwin_tools",
"//third_party/ijar:zipper",
],
":darwin_x86_64": [
":darwin_tools",
"//third_party/ijar:zipper",
],
"//conditions:default": [
":dummy_darwin_tools",
"//third_party/ijar:zipper",
],
}) + select({
"//tools/jdk:jdk7": [],
"//conditions:default": [
"//src/java_tools/buildjar/java/com/google/devtools/build/java/turbine:turbine_deploy.jar",
],
}),
outs = ["embedded_tools.zip"],
cmd = "$(location :create_embedded_tools.sh) $@ $(SRCS)",
)
[genrule(
name = "package-zip" + suffix,
srcs = ([":embedded_tools.zip"] if embed else []) + [
# The script assumes that the embedded tools zip (if exists) is the
# first item here, the deploy jar the second and install base key is the
# third
"//src/main/java/com/google/devtools/build/lib:bazel/BazelServer_deploy.jar",
"install_base_key" + suffix,
"//src/main/cpp:client",
":libunix",
"//src/main/tools:build-runfiles",
"//src/main/tools:process-wrapper",
"//src/main/tools:jdk-support",
"//src/main/tools:linux-sandbox",
"//src/main/tools:build_interface_so",
"//tools/osx:xcode-locator",
":java-version",
],
outs = ["package" + suffix + ".zip"],
cmd = "$(location :package-bazel.sh) $@ " + ("" if embed else "''") + " $(SRCS)",
tools = ["package-bazel.sh"],
) for suffix, embed in [
("", True),
("_notools", False),
]]
[genrule(
name = "bazel-bin" + suffix,
srcs = [
"//src/main/cpp:client",
"package-zip" + suffix,
],
outs = ["bazel" + suffix],
# In msys, a file path without .exe suffix(say foo), refers to a file with .exe
# suffix(say foo.exe), if foo.exe exists and foo doesn't. So, on windows, we
# need to remove bazel.exe first, so that cat to bazel won't fail.
cmd = "rm -f $@; cat $(location //src/main/cpp:client) $(location :package-zip" + suffix + ") > $@ && zip -qA $@",
executable = 1,
output_to_bindir = 1,
visibility = [
"//scripts:__pkg__", # For bash completion generation
"//scripts/packages:__pkg__", # For installer generation
"//src/java:__subpackages__", # For command line reference generation
"//src/test:__subpackages__", # For integration tests
],
) for suffix in [
"",
"_notools",
]]
# Build an executable named `bazel.exe`.
# Works on all platforms but only makes sense on Windows.
# Workaround for non-configurability of genrule's `outs` attribute.
[genrule(
name = "bazel-bin" + suffix + ".exe",
srcs = [":bazel-bin" + suffix],
outs = ["bazel" + suffix + ".exe"],
cmd = "cp $(location :bazel-bin" + suffix + ") $@",
executable = 1,
output_to_bindir = 1,
visibility = [
"//scripts:__pkg__", # For bash completion generation
"//scripts/packages:__pkg__", # For installer generation
"//src/test:__subpackages__", # For integration tests
],
) for suffix in [
"",
"_notools",
]]
config_setting(
name = "darwin",
values = {"cpu": "darwin"},
visibility = ["//visibility:public"],
)
config_setting(
name = "darwin_x86_64",
values = {"cpu": "darwin_x86_64"},
visibility = ["//visibility:public"],
)
config_setting(
name = "iphonesdk",
values = {"define": "IPHONE_SDK=1"},
visibility = ["//visibility:public"],
)
config_setting(
name = "freebsd",
values = {"cpu": "freebsd"},
visibility = ["//visibility:public"],
)
config_setting(
name = "windows",
values = {"cpu": "x64_windows"},
visibility = ["//visibility:public"],
)
config_setting(
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
visibility = ["//visibility:public"],
)
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//src/java_tools/buildjar:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/coverage:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/junit4:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/model:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing:srcs",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/util:srcs",
"//src/java_tools/singlejar:srcs",
"//src/main/cpp:srcs",
"//src/main/java/com/google/devtools/build/docgen:srcs",
"//src/main/java/com/google/devtools/build/lib:srcs",
"//src/main/java/com/google/devtools/build/lib/causes:srcs",
"//src/main/java/com/google/devtools/build/skyframe:srcs",
"//src/main/java/com/google/devtools/common/options:srcs",
"//src/main/java/com/google/devtools/skylark:srcs",
"//src/main/native:srcs",
"//src/main/protobuf:srcs",
"//src/main/tools:srcs",
"//src/objc_tools/bundlemerge:srcs",
"//src/objc_tools/plmerge:srcs",
"//src/objc_tools/xcodegen:srcs",
"//src/test/cpp:srcs",
"//src/test/java/com/google/devtools/build/android:srcs",
"//src/test/java/com/google/devtools/build/docgen:srcs",
"//src/test/java/com/google/devtools/build/lib:srcs",
"//src/test/java/com/google/devtools/build/skyframe:srcs",
"//src/test/java/com/google/devtools/common/options:srcs",
"//src/test/shell:srcs",
"//src/tools/android/java/com/google/devtools/build/android:srcs",
"//src/tools/generate_workspace:srcs",
"//src/tools/xcode/actoolwrapper:srcs",
"//src/tools/xcode/environment:srcs",
"//src/tools/xcode/ibtoolwrapper:srcs",
"//src/tools/xcode/libtool:srcs",
"//src/tools/xcode/momcwrapper:srcs",
"//src/tools/xcode/realpath:srcs",
"//src/tools/singlejar:srcs",
"//src/tools/xcode/stdredirect:srcs",
"//src/tools/xcode/swiftstdlibtoolwrapper:srcs",
"//src/tools/xcode/xcrunwrapper:srcs",
"//src/tools/xcode-common:srcs",
"//src/tools/remote_worker:srcs",
"//tools/osx:srcs",
],
visibility = ["//:__pkg__"],
)
genrule(
name = "derived_java_srcs",
srcs = [
"//src/main/protobuf:dist_jars",
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:dist_jars",
],
outs = ["derived_java_srcs.zip"],
cmd = "$(location :combine_derived_java_srcs.sh) $@ $(SRCS)",
tools = ["combine_derived_java_srcs.sh"],
visibility = ["//:__pkg__"],
)
|