blob: 651374b6b37cc9ea3a23d13d936349d838919a2e [file] [log] [blame]
cushon5c16ab232017-12-19 16:18:49 -08001load(
2 "//tools/jdk:default_java_toolchain.bzl",
3 "default_java_toolchain",
cushon30c601d2018-08-08 09:09:08 -07004 "java_runtime_files",
lberki7eb9ea12018-09-07 04:01:48 -07005 "JDK8_JVM_OPTS",
cushon999354b2018-09-21 00:31:42 -07006 "bootclasspath",
cushon5c16ab232017-12-19 16:18:49 -08007)
lberki528a1ea2017-07-13 17:11:18 +02008
cushon0faef912019-01-09 08:44:03 -08009package(default_visibility = ["//visibility:public"])
10
John Caterd90a0052018-01-12 07:29:13 -080011# Used to distinguish toolchains used for Java development, ie the JavaToolchainProvider.
12toolchain_type(name = "toolchain_type")
13
14# Used to distinguish toolchains used for Java execution, ie the JavaRuntimeInfo.
15toolchain_type(name = "runtime_toolchain_type")
16
cushon0faef912019-01-09 08:44:03 -080017toolchain(
18 name = "dummy_java_toolchain",
19 toolchain = ":dummy_toolchain",
20 toolchain_type = ":toolchain_type",
21)
22
23cc_binary(name = "dummy_binary")
24
25java_toolchain(
26 name = "dummy_toolchain",
27 genclass = [":dummy_binary"],
28 ijar = [":dummy_binary"],
29 javabuilder = [":dummy_binary"],
30 javac = [":dummy_binary"],
31 singlejar = [":dummy_binary"],
32)
33
34toolchain(
35 name = "dummy_java_runtime_toolchain",
36 toolchain = ":dummy_java_runtime",
37 toolchain_type = ":runtime_toolchain_type",
38)
39
40java_runtime(name = "dummy_java_runtime")
41
lberki528a1ea2017-07-13 17:11:18 +020042java_runtime_alias(name = "current_java_runtime")
43
lberki2a9e1252017-12-08 03:38:07 -080044java_host_runtime_alias(name = "current_host_java_runtime")
45
lberki528a1ea2017-07-13 17:11:18 +020046java_toolchain_alias(name = "current_java_toolchain")
47
cushon0173bdb2018-09-05 11:59:49 -070048# Used to set --host_javabase or --javabase to a local JDK without having to define
49# a custom java_runtime rule.
50# E.g.:
51# bazel build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
52# --define=ABSOLUTE_JAVABASE=<path to JDK> ...
53java_runtime(
54 name = "absolute_javabase",
55 java_home = "$(ABSOLUTE_JAVABASE)",
56)
57
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000058filegroup(
59 name = "BUILD-jdk",
Philipp Wollermann77234d62018-07-25 07:36:44 -070060 srcs = [":BUILD"],
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000061)
62
lberki2a9e1252017-12-08 03:38:07 -080063# This is necessary to get the *host* Java runtime. Depending on
64# //tools/jdk:current_java_runtime from an attribute with the host transition
65# does not work because the dependency is determined based on the configuration
66# *before* the transition.
67alias(
68 name = "java_runtime_alias",
dbabkin35df7152018-06-26 05:47:54 -070069 actual = "@bazel_tools//tools/jdk:current_java_runtime",
lberki2a9e1252017-12-08 03:38:07 -080070)
71
cushon30c601d2018-08-08 09:09:08 -070072java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010073 name = "jni_header",
cushon30c601d2018-08-08 09:09:08 -070074 srcs = ["include/jni.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010075)
76
cushon30c601d2018-08-08 09:09:08 -070077java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010078 name = "jni_md_header-darwin",
cushon30c601d2018-08-08 09:09:08 -070079 srcs = ["include/darwin/jni_md.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010080)
81
cushon30c601d2018-08-08 09:09:08 -070082java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010083 name = "jni_md_header-linux",
cushon30c601d2018-08-08 09:09:08 -070084 srcs = ["include/linux/jni_md.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010085)
86
cushon30c601d2018-08-08 09:09:08 -070087java_runtime_files(
pcloudy178e03e92017-06-27 10:32:46 +020088 name = "jni_md_header-windows",
cushon30c601d2018-08-08 09:09:08 -070089 srcs = ["include/win32/jni_md.h"],
pcloudy178e03e92017-06-27 10:32:46 +020090)
91
cushon30c601d2018-08-08 09:09:08 -070092java_runtime_files(
Doug Rabson709bc612015-08-25 14:12:00 +000093 name = "jni_md_header-freebsd",
cushon30c601d2018-08-08 09:09:08 -070094 srcs = ["include/freebsd/jni_md.h"],
Doug Rabson709bc612015-08-25 14:12:00 +000095)
96
Ulf Adams27085f42016-10-06 08:51:47 +000097alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010098 name = "java",
Ulf Adamsc8510b12017-02-14 10:27:11 +000099 actual = "@local_jdk//:java",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100100)
101
Ulf Adams27085f42016-10-06 08:51:47 +0000102alias(
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000103 name = "jar",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000104 actual = "@local_jdk//:jar",
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000105)
106
Ulf Adams27085f42016-10-06 08:51:47 +0000107alias(
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000108 name = "javac",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000109 actual = "@local_jdk//:javac",
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +0000110)
111
Lukacs Berkib35e25d2016-02-10 16:44:54 +0000112# On Windows, executables end in ".exe", but the label we reach it through
113# must be platform-independent. Thus, we create a little filegroup that
114# contains the appropriate platform-dependent file.
115filegroup(
116 name = "ijar",
xingao1f0f1f12017-11-01 13:03:40 -0400117 srcs = select({
tomlu1a483d42017-11-30 15:08:40 -0800118 "//src/conditions:remote": ["//third_party/ijar:ijar"],
xingao1f0f1f12017-11-01 13:03:40 -0400119 "//conditions:default": glob(["ijar/*"]),
120 }),
Lukacs Berkib35e25d2016-02-10 16:44:54 +0000121)
122
xingao202d5912017-06-01 19:23:29 +0200123# On Windows, Java implementation of singlejar is used. We create a little
124# filegroup that contains the appropriate platform-dependent file.
125# Once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is,
126# the native singlejar is used on windows), this file group can be reused since
127# on Windows, executables end in ".exe", but the label we reach it through
128# must be platform-independent.
129filegroup(
130 name = "singlejar",
xingao1f0f1f12017-11-01 13:03:40 -0400131 srcs = select({
Loo Rong Jiec5573992018-11-06 05:50:45 -0800132 "//src/conditions:remote": ["//src/tools/singlejar:singlejar"],
xingao1f0f1f12017-11-01 13:03:40 -0400133 "//conditions:default": glob(["singlejar/*"]),
134 }),
xingao202d5912017-06-01 19:23:29 +0200135)
136
xingao8df71b52017-04-03 15:25:18 +0000137filegroup(
138 name = "genclass",
139 srcs = ["//tools/jdk:GenClass_deploy.jar"],
140)
141
142filegroup(
143 name = "turbine",
144 srcs = ["//tools/jdk:turbine_deploy.jar"],
145)
146
147filegroup(
Liam Miller-Cushonda77c4e2018-10-23 21:53:36 -0700148 name = "turbine_direct",
149 srcs = glob(["turbine_direct*"]),
150)
151
152filegroup(
xingao8df71b52017-04-03 15:25:18 +0000153 name = "javabuilder",
154 srcs = ["//tools/jdk:JavaBuilder_deploy.jar"],
155)
156
157filegroup(
158 name = "vanillajavabuilder",
159 srcs = ["//tools/jdk:VanillaJavaBuilder_deploy.jar"],
160)
161
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100162BOOTCLASS_JARS = [
163 "rt.jar",
164 "resources.jar",
165 "jsse.jar",
166 "jce.jar",
167 "charsets.jar",
168]
169
cushon29a96822017-12-20 16:19:56 -0800170# TODO(cushon): this isn't compatible with JDK 9
Ulf Adams27085f42016-10-06 08:51:47 +0000171alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100172 name = "bootclasspath",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000173 actual = "@local_jdk//:bootclasspath",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100174)
175
Ulf Adams27085f42016-10-06 08:51:47 +0000176alias(
Liam Miller-Cushon8153cb82017-02-17 03:42:18 +0000177 name = "extclasspath",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000178 actual = "@local_jdk//:extdir",
Liam Miller-Cushon22218602015-05-19 17:23:01 +0000179)
180
Irina Iancuc9a75d22017-02-21 13:45:20 +0000181# TODO(cushon): migrate to extclasspath and delete
182alias(
183 name = "extdir",
184 actual = "@local_jdk//:extdir",
185)
186
Liam Miller-Cushon22218602015-05-19 17:23:01 +0000187filegroup(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100188 name = "langtools",
Liam Miller-Cushon38949b82017-05-08 10:18:38 -0400189 srcs = ["//third_party/java/jdk/langtools:javac_jar"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100190)
191
192java_import(
193 name = "langtools-neverlink",
Liam Miller-Cushon1ed3c472015-06-19 00:35:26 +0000194 jars = [":langtools"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100195 neverlink = 1,
196)
197
Ulf Adams27085f42016-10-06 08:51:47 +0000198alias(
Philipp Wollermannc8db70c2015-08-21 13:35:10 +0000199 name = "jre",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000200 actual = "@local_jdk//:jre",
Philipp Wollermannc8db70c2015-08-21 13:35:10 +0000201)
202
Ulf Adams27085f42016-10-06 08:51:47 +0000203alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100204 name = "jdk",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000205 actual = "@local_jdk//:jdk",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100206)
207
lberkic4cd9862017-12-05 05:57:27 -0800208alias(
209 name = "host_jdk",
Tobias Werthbf18a9f2018-12-06 01:40:33 -0800210 actual = ":remote_jdk",
lberkic4cd9862017-12-05 05:57:27 -0800211)
212
cushon999354b2018-09-21 00:31:42 -0700213bootclasspath(
214 name = "platformclasspath",
215 src = "DumpPlatformClassPath.java",
216 host_javabase = "current_java_runtime",
cushon999354b2018-09-21 00:31:42 -0700217 target_javabase = "current_java_runtime",
218)
219
cushon5c16ab232017-12-19 16:18:49 -0800220default_java_toolchain(
cushonc1705f02018-08-07 10:31:41 -0700221 name = "toolchain_hostjdk8",
lberki7eb9ea12018-09-07 04:01:48 -0700222 jvm_opts = JDK8_JVM_OPTS,
cushonc1705f02018-08-07 10:31:41 -0700223 source_version = "8",
224 target_version = "8",
225)
226
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700227# Default to the Java 8 language level.
228# TODO(cushon): consider if/when we should increment this?
cushon999354b2018-09-21 00:31:42 -0700229default_java_toolchain(
cushon137504e2018-09-25 18:15:09 -0700230 name = "toolchain",
cushon999354b2018-09-21 00:31:42 -0700231 source_version = "8",
232 target_version = "8",
cushona1ef9992018-05-14 09:38:41 -0700233)
234
David Ostrovsky0bef68e2018-09-20 12:13:56 -0700235# The 'vanilla' toolchain is an unsupported alternative to the default.
236#
237# It does not provider any of the following features:
238# * Error Prone
239# * Strict Java Deps
240# * Header Compilation
241# * Reduced Classpath Optimization
242#
243# It uses the version of javac from the `--host_javabase` instead of the
244# embedded javac, which may not be source- or bug-compatible with the embedded
245# javac.
246#
247# However it does allow using a wider range of `--host_javabase`s, including
248# versions newer than the current embedded JDK.
249default_java_toolchain(
250 name = "toolchain_vanilla",
251 forcibly_disable_header_compilation = True,
252 javabuilder = [":vanillajavabuilder"],
253 jvm_opts = [],
254)
255
cushon5a1ed1f2018-09-26 13:41:54 -0700256RELEASES = (8, 9)
257
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700258[
259 default_java_toolchain(
260 name = "toolchain_java%d" % release,
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700261 source_version = "%s" % release,
262 target_version = "%s" % release,
263 )
264 for release in RELEASES
265]
buchgr4c9149d2018-07-24 11:50:48 -0700266
Damien Martin-Guillerez5cbd5a42015-03-24 21:55:19 +0000267filegroup(
268 name = "srcs",
Michael Staib6817a6f2015-10-05 15:58:23 +0000269 srcs = [
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +0000270 "BUILD-jdk", # Tools are build from the workspace for tests.
cushon29a96822017-12-20 16:19:56 -0800271 "DumpPlatformClassPath.java",
cushon5c16ab232017-12-19 16:18:49 -0800272 "default_java_toolchain.bzl",
Michael Staib6817a6f2015-10-05 15:58:23 +0000273 "proguard_whitelister.py",
274 "proguard_whitelister_test.py",
275 "proguard_whitelister_test_input.cfg",
276 ],
Damien Martin-Guillerez5cbd5a42015-03-24 21:55:19 +0000277)
Damien Martin-Guillerezab13f682015-07-28 08:19:32 +0000278
279filegroup(
280 name = "package-srcs",
281 srcs = glob(["**"]),
282)
Michael Staib6817a6f2015-10-05 15:58:23 +0000283
284py_binary(
285 name = "proguard_whitelister",
286 srcs = [
287 "proguard_whitelister.py",
288 ],
289 deps = [
290 "//third_party/py/gflags",
291 ],
292)
293
294py_test(
295 name = "proguard_whitelister_test",
296 srcs = ["proguard_whitelister_test.py"],
297 data = ["proguard_whitelister_test_input.cfg"],
298 deps = [
299 ":proguard_whitelister",
300 ],
301)
Yue Gan4a753492016-12-20 04:54:55 +0000302
303# For java coverage
304alias(
305 name = "jacoco-blaze-agent",
306 actual = "//third_party/java/jacoco:blaze-agent",
307)
308
Damien Martin-Guillerez39e5a462016-12-20 10:58:17 +0000309java_import(
Yue Gan4a753492016-12-20 04:54:55 +0000310 name = "JacocoCoverage",
Damien Martin-Guillerez39e5a462016-12-20 10:58:17 +0000311 jars = [":JacocoCoverage_deploy.jar"],
Yue Gan4a753492016-12-20 04:54:55 +0000312)
Laszlo Csomordf16c772018-08-09 23:36:39 -0700313
iirina5bd55432019-01-16 06:36:56 -0800314java_import(
315 name = "JarJar",
316 jars = [":jarjar_command_deploy.jar"],
317)
318
Laszlo Csomordf16c772018-08-09 23:36:39 -0700319test_suite(
320 name = "windows_tests",
321 tags = [
322 "-no_windows",
323 "-slow",
324 ],
325 visibility = ["//visibility:private"],
326)
327
328test_suite(
329 name = "all_windows_tests",
330 tests = [":windows_tests"],
331 visibility = ["//tools:__pkg__"],
332)
Tobias Werth1b757622018-10-10 07:26:23 -0700333
334# Replacement for the embedded JDK as host javabase.
335alias(
336 name = "remote_jdk",
337 actual = select(
338 {
339 "//src/conditions:darwin": "@remotejdk_macos//:jdk",
340 "//src/conditions:darwin_x86_64": "@remotejdk_macos//:jdk",
341 "//src/conditions:windows": "@remotejdk_win//:jdk",
342 "//src/conditions:linux_aarch64": "@remotejdk_linux_aarch64//:jdk",
343 "//src/conditions:linux_x86_64": "@remotejdk_linux//:jdk",
344 },
twerthedce5802018-10-10 08:18:15 -0700345 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
346 " provide one using `--host_javabase.`",
Tobias Werth1b757622018-10-10 07:26:23 -0700347 ),
348 visibility = ["//visibility:public"],
349)
cushon825c0492018-10-10 13:57:11 -0700350
351# A JDK 10 for use as a --host_javabase.
352alias(
353 name = "remote_jdk10",
354 actual = select(
355 {
356 "//src/conditions:darwin": "@remotejdk10_macos//:jdk",
357 "//src/conditions:darwin_x86_64": "@remotejdk10_macos//:jdk",
358 "//src/conditions:windows": "@remotejdk10_win//:jdk",
359 "//src/conditions:linux_aarch64": "@remotejdk10_linux_aarch64//:jdk",
360 "//src/conditions:linux_x86_64": "@remotejdk10_linux//:jdk",
361 },
362 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
363 " provide one using `--host_javabase.`",
364 ),
365 visibility = ["//visibility:public"],
366)