blob: 9e15088ebf1a1bbc1fa35c303a75a3b91f7ebcff [file] [log] [blame]
cushon5c16ab232017-12-19 16:18:49 -08001load(
2 "//tools/jdk:default_java_toolchain.bzl",
3 "default_java_toolchain",
iirina22d375b2019-01-21 04:44:29 -08004 "default_remote_java_toolchain",
cushon30c601d2018-08-08 09:09:08 -07005 "java_runtime_files",
lberki7eb9ea12018-09-07 04:01:48 -07006 "JDK8_JVM_OPTS",
iirina22d375b2019-01-21 04:44:29 -08007 "JDK8_JVM_OPTS_REMOTE_JAVAC",
cushon999354b2018-09-21 00:31:42 -07008 "bootclasspath",
cushon5c16ab232017-12-19 16:18:49 -08009)
lberki528a1ea2017-07-13 17:11:18 +020010
cushon0faef912019-01-09 08:44:03 -080011package(default_visibility = ["//visibility:public"])
12
John Caterd90a0052018-01-12 07:29:13 -080013# Used to distinguish toolchains used for Java development, ie the JavaToolchainProvider.
14toolchain_type(name = "toolchain_type")
15
16# Used to distinguish toolchains used for Java execution, ie the JavaRuntimeInfo.
17toolchain_type(name = "runtime_toolchain_type")
18
cushon0faef912019-01-09 08:44:03 -080019toolchain(
20 name = "dummy_java_toolchain",
21 toolchain = ":dummy_toolchain",
22 toolchain_type = ":toolchain_type",
23)
24
25cc_binary(name = "dummy_binary")
26
27java_toolchain(
28 name = "dummy_toolchain",
29 genclass = [":dummy_binary"],
30 ijar = [":dummy_binary"],
31 javabuilder = [":dummy_binary"],
32 javac = [":dummy_binary"],
33 singlejar = [":dummy_binary"],
34)
35
36toolchain(
37 name = "dummy_java_runtime_toolchain",
38 toolchain = ":dummy_java_runtime",
39 toolchain_type = ":runtime_toolchain_type",
40)
41
42java_runtime(name = "dummy_java_runtime")
43
lberki528a1ea2017-07-13 17:11:18 +020044java_runtime_alias(name = "current_java_runtime")
45
lberki2a9e1252017-12-08 03:38:07 -080046java_host_runtime_alias(name = "current_host_java_runtime")
47
lberki528a1ea2017-07-13 17:11:18 +020048java_toolchain_alias(name = "current_java_toolchain")
49
cushon0173bdb2018-09-05 11:59:49 -070050# Used to set --host_javabase or --javabase to a local JDK without having to define
51# a custom java_runtime rule.
52# E.g.:
53# bazel build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
54# --define=ABSOLUTE_JAVABASE=<path to JDK> ...
55java_runtime(
56 name = "absolute_javabase",
57 java_home = "$(ABSOLUTE_JAVABASE)",
58)
59
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000060filegroup(
61 name = "BUILD-jdk",
Philipp Wollermann77234d62018-07-25 07:36:44 -070062 srcs = [":BUILD"],
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000063)
64
lberki2a9e1252017-12-08 03:38:07 -080065# This is necessary to get the *host* Java runtime. Depending on
66# //tools/jdk:current_java_runtime from an attribute with the host transition
67# does not work because the dependency is determined based on the configuration
68# *before* the transition.
69alias(
70 name = "java_runtime_alias",
dbabkin35df7152018-06-26 05:47:54 -070071 actual = "@bazel_tools//tools/jdk:current_java_runtime",
lberki2a9e1252017-12-08 03:38:07 -080072)
73
cushon30c601d2018-08-08 09:09:08 -070074java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010075 name = "jni_header",
cushon30c601d2018-08-08 09:09:08 -070076 srcs = ["include/jni.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010077)
78
cushon30c601d2018-08-08 09:09:08 -070079java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010080 name = "jni_md_header-darwin",
cushon30c601d2018-08-08 09:09:08 -070081 srcs = ["include/darwin/jni_md.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010082)
83
cushon30c601d2018-08-08 09:09:08 -070084java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010085 name = "jni_md_header-linux",
cushon30c601d2018-08-08 09:09:08 -070086 srcs = ["include/linux/jni_md.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010087)
88
cushon30c601d2018-08-08 09:09:08 -070089java_runtime_files(
pcloudy178e03e92017-06-27 10:32:46 +020090 name = "jni_md_header-windows",
cushon30c601d2018-08-08 09:09:08 -070091 srcs = ["include/win32/jni_md.h"],
pcloudy178e03e92017-06-27 10:32:46 +020092)
93
cushon30c601d2018-08-08 09:09:08 -070094java_runtime_files(
Doug Rabson709bc612015-08-25 14:12:00 +000095 name = "jni_md_header-freebsd",
cushon30c601d2018-08-08 09:09:08 -070096 srcs = ["include/freebsd/jni_md.h"],
Doug Rabson709bc612015-08-25 14:12:00 +000097)
98
Ulf Adams27085f42016-10-06 08:51:47 +000099alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100100 name = "java",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000101 actual = "@local_jdk//:java",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100102)
103
Ulf Adams27085f42016-10-06 08:51:47 +0000104alias(
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000105 name = "jar",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000106 actual = "@local_jdk//:jar",
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000107)
108
Ulf Adams27085f42016-10-06 08:51:47 +0000109alias(
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000110 name = "javac",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000111 actual = "@local_jdk//:javac",
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000112)
113
Lukacs Berkib35e25d2016-02-10 16:44:54 +0000114# On Windows, executables end in ".exe", but the label we reach it through
115# must be platform-independent. Thus, we create a little filegroup that
116# contains the appropriate platform-dependent file.
117filegroup(
118 name = "ijar",
xingao1f0f1f12017-11-01 13:03:40 -0400119 srcs = select({
tomlu1a483d42017-11-30 15:08:40 -0800120 "//src/conditions:remote": ["//third_party/ijar:ijar"],
xingao1f0f1f12017-11-01 13:03:40 -0400121 "//conditions:default": glob(["ijar/*"]),
122 }),
Lukacs Berkib35e25d2016-02-10 16:44:54 +0000123)
124
xingao202d5912017-06-01 19:23:29 +0200125# On Windows, Java implementation of singlejar is used. We create a little
126# filegroup that contains the appropriate platform-dependent file.
127# Once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is,
128# the native singlejar is used on windows), this file group can be reused since
129# on Windows, executables end in ".exe", but the label we reach it through
130# must be platform-independent.
131filegroup(
132 name = "singlejar",
xingao1f0f1f12017-11-01 13:03:40 -0400133 srcs = select({
Loo Rong Jiec5573992018-11-06 05:50:45 -0800134 "//src/conditions:remote": ["//src/tools/singlejar:singlejar"],
xingao1f0f1f12017-11-01 13:03:40 -0400135 "//conditions:default": glob(["singlejar/*"]),
136 }),
xingao202d5912017-06-01 19:23:29 +0200137)
138
iirina22d375b2019-01-21 04:44:29 -0800139exports_files(["BUILD.pkg"])
140
xingao8df71b52017-04-03 15:25:18 +0000141filegroup(
142 name = "genclass",
143 srcs = ["//tools/jdk:GenClass_deploy.jar"],
144)
145
146filegroup(
iirina22d375b2019-01-21 04:44:29 -0800147 name = "remote-genclass",
148 srcs = ["@remote_java_tools//:GenClass"],
149)
150
151filegroup(
xingao8df71b52017-04-03 15:25:18 +0000152 name = "turbine",
153 srcs = ["//tools/jdk:turbine_deploy.jar"],
154)
155
156filegroup(
iirina22d375b2019-01-21 04:44:29 -0800157 name = "remote-turbine",
158 srcs = ["@remote_java_tools//:Turbine"],
159)
160
161filegroup(
Liam Miller-Cushonda77c4e2018-10-23 21:53:36 -0700162 name = "turbine_direct",
163 srcs = glob(["turbine_direct*"]),
164)
165
166filegroup(
iirina22d375b2019-01-21 04:44:29 -0800167 name = "remote-turbine_direct",
168 srcs = ["@remote_java_tools//:TurbineDirect"],
169)
170
171filegroup(
xingao8df71b52017-04-03 15:25:18 +0000172 name = "javabuilder",
173 srcs = ["//tools/jdk:JavaBuilder_deploy.jar"],
174)
175
176filegroup(
iirina22d375b2019-01-21 04:44:29 -0800177 name = "remote-javabuilder",
178 srcs = ["@remote_java_tools//:JavaBuilder"],
179)
180
181filegroup(
xingao8df71b52017-04-03 15:25:18 +0000182 name = "vanillajavabuilder",
183 srcs = ["//tools/jdk:VanillaJavaBuilder_deploy.jar"],
184)
185
iirina22d375b2019-01-21 04:44:29 -0800186filegroup(
187 name = "remote-vanillajavabuilder",
188 srcs = ["@remote_java_tools//:VanillaJavaBuilder"],
189)
190
191filegroup(
192 name = "remote-javac_jar",
193 srcs = ["@remote_java_tools//:javac_jar"],
194)
195
196filegroup(
197 name = "remote-jdk_compiler_jar",
198 srcs = ["@remote_java_tools//:jdk_compiler_jar"],
199)
200
201filegroup(
202 name = "remote-java_compiler_jar",
203 srcs = ["@remote_java_tools//:java_compiler_jar"],
204)
205
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100206BOOTCLASS_JARS = [
207 "rt.jar",
208 "resources.jar",
209 "jsse.jar",
210 "jce.jar",
211 "charsets.jar",
212]
213
cushon29a96822017-12-20 16:19:56 -0800214# TODO(cushon): this isn't compatible with JDK 9
Ulf Adams27085f42016-10-06 08:51:47 +0000215alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100216 name = "bootclasspath",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000217 actual = "@local_jdk//:bootclasspath",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100218)
219
Ulf Adams27085f42016-10-06 08:51:47 +0000220alias(
Liam Miller-Cushon8153cb82017-02-17 03:42:18 +0000221 name = "extclasspath",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000222 actual = "@local_jdk//:extdir",
Liam Miller-Cushon22218602015-05-19 17:23:01 +0000223)
224
Irina Iancuc9a75d22017-02-21 13:45:20 +0000225# TODO(cushon): migrate to extclasspath and delete
226alias(
227 name = "extdir",
228 actual = "@local_jdk//:extdir",
229)
230
Liam Miller-Cushon22218602015-05-19 17:23:01 +0000231filegroup(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100232 name = "langtools",
Liam Miller-Cushon38949b82017-05-08 10:18:38 -0400233 srcs = ["//third_party/java/jdk/langtools:javac_jar"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100234)
235
236java_import(
237 name = "langtools-neverlink",
Liam Miller-Cushon1ed3c472015-06-19 00:35:26 +0000238 jars = [":langtools"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100239 neverlink = 1,
240)
241
Ulf Adams27085f42016-10-06 08:51:47 +0000242alias(
Philipp Wollermannc8db70c2015-08-21 13:35:10 +0000243 name = "jre",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000244 actual = "@local_jdk//:jre",
Philipp Wollermannc8db70c2015-08-21 13:35:10 +0000245)
246
Ulf Adams27085f42016-10-06 08:51:47 +0000247alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100248 name = "jdk",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000249 actual = "@local_jdk//:jdk",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100250)
251
lberkic4cd9862017-12-05 05:57:27 -0800252alias(
253 name = "host_jdk",
Tobias Werthbf18a9f2018-12-06 01:40:33 -0800254 actual = ":remote_jdk",
lberkic4cd9862017-12-05 05:57:27 -0800255)
256
cushon999354b2018-09-21 00:31:42 -0700257bootclasspath(
258 name = "platformclasspath",
259 src = "DumpPlatformClassPath.java",
260 host_javabase = "current_java_runtime",
cushon999354b2018-09-21 00:31:42 -0700261 target_javabase = "current_java_runtime",
262)
263
cushon5c16ab232017-12-19 16:18:49 -0800264default_java_toolchain(
cushonc1705f02018-08-07 10:31:41 -0700265 name = "toolchain_hostjdk8",
lberki7eb9ea12018-09-07 04:01:48 -0700266 jvm_opts = JDK8_JVM_OPTS,
cushonc1705f02018-08-07 10:31:41 -0700267 source_version = "8",
268 target_version = "8",
269)
270
iirina22d375b2019-01-21 04:44:29 -0800271default_remote_java_toolchain(
272 name = "remote_toolchain_hostjdk8",
273 jvm_opts = JDK8_JVM_OPTS_REMOTE_JAVAC,
274 source_version = "8",
275 target_version = "8",
276)
277
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700278# Default to the Java 8 language level.
279# TODO(cushon): consider if/when we should increment this?
cushon999354b2018-09-21 00:31:42 -0700280default_java_toolchain(
cushon137504e2018-09-25 18:15:09 -0700281 name = "toolchain",
cushon999354b2018-09-21 00:31:42 -0700282 source_version = "8",
283 target_version = "8",
cushona1ef9992018-05-14 09:38:41 -0700284)
285
iirina22d375b2019-01-21 04:44:29 -0800286default_remote_java_toolchain(
287 name = "remote_toolchain",
288 source_version = "8",
289 target_version = "8",
290)
291
David Ostrovsky0bef68e2018-09-20 12:13:56 -0700292# The 'vanilla' toolchain is an unsupported alternative to the default.
293#
294# It does not provider any of the following features:
295# * Error Prone
296# * Strict Java Deps
297# * Header Compilation
298# * Reduced Classpath Optimization
299#
300# It uses the version of javac from the `--host_javabase` instead of the
301# embedded javac, which may not be source- or bug-compatible with the embedded
302# javac.
303#
304# However it does allow using a wider range of `--host_javabase`s, including
305# versions newer than the current embedded JDK.
306default_java_toolchain(
307 name = "toolchain_vanilla",
308 forcibly_disable_header_compilation = True,
309 javabuilder = [":vanillajavabuilder"],
310 jvm_opts = [],
311)
312
iirina22d375b2019-01-21 04:44:29 -0800313default_remote_java_toolchain(
314 name = "remote_toolchain_vanilla",
315 forcibly_disable_header_compilation = True,
316 javabuilder = ["@bazel_tools//tools/jdk:remote-vanillajavabuilder"],
317 jvm_opts = [],
318)
319
cushon5a1ed1f2018-09-26 13:41:54 -0700320RELEASES = (8, 9)
321
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700322[
323 default_java_toolchain(
324 name = "toolchain_java%d" % release,
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700325 source_version = "%s" % release,
326 target_version = "%s" % release,
327 )
328 for release in RELEASES
329]
buchgr4c9149d2018-07-24 11:50:48 -0700330
Damien Martin-Guillerez5cbd5a42015-03-24 21:55:19 +0000331filegroup(
332 name = "srcs",
Michael Staib6817a6f2015-10-05 15:58:23 +0000333 srcs = [
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +0000334 "BUILD-jdk", # Tools are build from the workspace for tests.
cushon29a96822017-12-20 16:19:56 -0800335 "DumpPlatformClassPath.java",
cushon5c16ab232017-12-19 16:18:49 -0800336 "default_java_toolchain.bzl",
Michael Staib6817a6f2015-10-05 15:58:23 +0000337 "proguard_whitelister.py",
338 "proguard_whitelister_test.py",
339 "proguard_whitelister_test_input.cfg",
cushon4e67bd72019-02-04 10:00:23 -0800340 "toolchain_utils.bzl",
Michael Staib6817a6f2015-10-05 15:58:23 +0000341 ],
Damien Martin-Guillerez5cbd5a42015-03-24 21:55:19 +0000342)
Damien Martin-Guillerezab13f682015-07-28 08:19:32 +0000343
344filegroup(
345 name = "package-srcs",
346 srcs = glob(["**"]),
347)
Michael Staib6817a6f2015-10-05 15:58:23 +0000348
349py_binary(
350 name = "proguard_whitelister",
351 srcs = [
352 "proguard_whitelister.py",
353 ],
354 deps = [
355 "//third_party/py/gflags",
356 ],
357)
358
359py_test(
360 name = "proguard_whitelister_test",
361 srcs = ["proguard_whitelister_test.py"],
362 data = ["proguard_whitelister_test_input.cfg"],
363 deps = [
364 ":proguard_whitelister",
365 ],
366)
Yue Gan4a753492016-12-20 04:54:55 +0000367
368# For java coverage
369alias(
370 name = "jacoco-blaze-agent",
371 actual = "//third_party/java/jacoco:blaze-agent",
372)
373
Damien Martin-Guillerez39e5a462016-12-20 10:58:17 +0000374java_import(
Yue Gan4a753492016-12-20 04:54:55 +0000375 name = "JacocoCoverage",
Damien Martin-Guillerez39e5a462016-12-20 10:58:17 +0000376 jars = [":JacocoCoverage_deploy.jar"],
Yue Gan4a753492016-12-20 04:54:55 +0000377)
Laszlo Csomordf16c772018-08-09 23:36:39 -0700378
iirina5bd55432019-01-16 06:36:56 -0800379java_import(
380 name = "JarJar",
381 jars = [":jarjar_command_deploy.jar"],
382)
383
Laszlo Csomordf16c772018-08-09 23:36:39 -0700384test_suite(
385 name = "windows_tests",
386 tags = [
387 "-no_windows",
388 "-slow",
389 ],
390 visibility = ["//visibility:private"],
391)
392
393test_suite(
394 name = "all_windows_tests",
395 tests = [":windows_tests"],
396 visibility = ["//tools:__pkg__"],
397)
Tobias Werth1b757622018-10-10 07:26:23 -0700398
399# Replacement for the embedded JDK as host javabase.
400alias(
401 name = "remote_jdk",
402 actual = select(
403 {
404 "//src/conditions:darwin": "@remotejdk_macos//:jdk",
405 "//src/conditions:darwin_x86_64": "@remotejdk_macos//:jdk",
406 "//src/conditions:windows": "@remotejdk_win//:jdk",
407 "//src/conditions:linux_aarch64": "@remotejdk_linux_aarch64//:jdk",
408 "//src/conditions:linux_x86_64": "@remotejdk_linux//:jdk",
409 },
twerthedce5802018-10-10 08:18:15 -0700410 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
411 " provide one using `--host_javabase.`",
Tobias Werth1b757622018-10-10 07:26:23 -0700412 ),
413 visibility = ["//visibility:public"],
414)
cushon825c0492018-10-10 13:57:11 -0700415
416# A JDK 10 for use as a --host_javabase.
417alias(
418 name = "remote_jdk10",
419 actual = select(
420 {
421 "//src/conditions:darwin": "@remotejdk10_macos//:jdk",
422 "//src/conditions:darwin_x86_64": "@remotejdk10_macos//:jdk",
423 "//src/conditions:windows": "@remotejdk10_win//:jdk",
424 "//src/conditions:linux_aarch64": "@remotejdk10_linux_aarch64//:jdk",
425 "//src/conditions:linux_x86_64": "@remotejdk10_linux//:jdk",
426 },
427 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
428 " provide one using `--host_javabase.`",
429 ),
430 visibility = ["//visibility:public"],
431)
cushon125f2c52019-01-24 09:10:59 -0800432
433# A JDK 11 for use as a --host_javabase.
434alias(
435 name = "remote_jdk11",
436 actual = select(
437 {
438 "//src/conditions:darwin": "@remotejdk11_macos//:jdk",
439 "//src/conditions:darwin_x86_64": "@remotejdk11_macos//:jdk",
440 "//src/conditions:windows": "@remotejdk11_win//:jdk",
441 "//src/conditions:linux_x86_64": "@remotejdk11_linux//:jdk",
442 },
443 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
444 " provide one using `--host_javabase.`",
445 ),
446 visibility = ["//visibility:public"],
447)