blob: d12e328f4a5b0ad2bd2221e1c48849b324549e5f [file] [log] [blame]
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01001package(default_visibility = ["//visibility:public"])
2
cushon5c16ab232017-12-19 16:18:49 -08003load(
4 "//tools/jdk:default_java_toolchain.bzl",
5 "default_java_toolchain",
cushon30c601d2018-08-08 09:09:08 -07006 "java_runtime_files",
lberki7eb9ea12018-09-07 04:01:48 -07007 "JDK8_JVM_OPTS",
cushon999354b2018-09-21 00:31:42 -07008 "bootclasspath",
cushon5c16ab232017-12-19 16:18:49 -08009)
lberki528a1ea2017-07-13 17:11:18 +020010
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
lberki528a1ea2017-07-13 17:11:18 +020017java_runtime_alias(name = "current_java_runtime")
18
lberki2a9e1252017-12-08 03:38:07 -080019java_host_runtime_alias(name = "current_host_java_runtime")
20
lberki528a1ea2017-07-13 17:11:18 +020021java_toolchain_alias(name = "current_java_toolchain")
22
cushon0173bdb2018-09-05 11:59:49 -070023# Used to set --host_javabase or --javabase to a local JDK without having to define
24# a custom java_runtime rule.
25# E.g.:
26# bazel build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
27# --define=ABSOLUTE_JAVABASE=<path to JDK> ...
28java_runtime(
29 name = "absolute_javabase",
30 java_home = "$(ABSOLUTE_JAVABASE)",
31)
32
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000033filegroup(
34 name = "BUILD-jdk",
Philipp Wollermann77234d62018-07-25 07:36:44 -070035 srcs = [":BUILD"],
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000036)
37
lberki2a9e1252017-12-08 03:38:07 -080038# This is necessary to get the *host* Java runtime. Depending on
39# //tools/jdk:current_java_runtime from an attribute with the host transition
40# does not work because the dependency is determined based on the configuration
41# *before* the transition.
42alias(
43 name = "java_runtime_alias",
dbabkin35df7152018-06-26 05:47:54 -070044 actual = "@bazel_tools//tools/jdk:current_java_runtime",
lberki2a9e1252017-12-08 03:38:07 -080045)
46
cushon30c601d2018-08-08 09:09:08 -070047java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010048 name = "jni_header",
cushon30c601d2018-08-08 09:09:08 -070049 srcs = ["include/jni.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010050)
51
cushon30c601d2018-08-08 09:09:08 -070052java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010053 name = "jni_md_header-darwin",
cushon30c601d2018-08-08 09:09:08 -070054 srcs = ["include/darwin/jni_md.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010055)
56
cushon30c601d2018-08-08 09:09:08 -070057java_runtime_files(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010058 name = "jni_md_header-linux",
cushon30c601d2018-08-08 09:09:08 -070059 srcs = ["include/linux/jni_md.h"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060)
61
cushon30c601d2018-08-08 09:09:08 -070062java_runtime_files(
pcloudy178e03e92017-06-27 10:32:46 +020063 name = "jni_md_header-windows",
cushon30c601d2018-08-08 09:09:08 -070064 srcs = ["include/win32/jni_md.h"],
pcloudy178e03e92017-06-27 10:32:46 +020065)
66
cushon30c601d2018-08-08 09:09:08 -070067java_runtime_files(
Doug Rabson709bc612015-08-25 14:12:00 +000068 name = "jni_md_header-freebsd",
cushon30c601d2018-08-08 09:09:08 -070069 srcs = ["include/freebsd/jni_md.h"],
Doug Rabson709bc612015-08-25 14:12:00 +000070)
71
Ulf Adams27085f42016-10-06 08:51:47 +000072alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010073 name = "java",
Ulf Adamsc8510b12017-02-14 10:27:11 +000074 actual = "@local_jdk//:java",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010075)
76
Ulf Adams27085f42016-10-06 08:51:47 +000077alias(
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +000078 name = "jar",
Ulf Adamsc8510b12017-02-14 10:27:11 +000079 actual = "@local_jdk//:jar",
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +000080)
81
Ulf Adams27085f42016-10-06 08:51:47 +000082alias(
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +000083 name = "javac",
Ulf Adamsc8510b12017-02-14 10:27:11 +000084 actual = "@local_jdk//:javac",
Damien Martin-Guillerez0bf90f72015-06-11 09:20:59 +000085)
86
Lukacs Berkib35e25d2016-02-10 16:44:54 +000087# On Windows, executables end in ".exe", but the label we reach it through
88# must be platform-independent. Thus, we create a little filegroup that
89# contains the appropriate platform-dependent file.
90filegroup(
91 name = "ijar",
xingao1f0f1f12017-11-01 13:03:40 -040092 srcs = select({
tomlu1a483d42017-11-30 15:08:40 -080093 "//src/conditions:remote": ["//third_party/ijar:ijar"],
xingao1f0f1f12017-11-01 13:03:40 -040094 "//conditions:default": glob(["ijar/*"]),
95 }),
Lukacs Berkib35e25d2016-02-10 16:44:54 +000096)
97
xingao202d5912017-06-01 19:23:29 +020098# On Windows, Java implementation of singlejar is used. We create a little
99# filegroup that contains the appropriate platform-dependent file.
100# Once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is,
101# the native singlejar is used on windows), this file group can be reused since
102# on Windows, executables end in ".exe", but the label we reach it through
103# must be platform-independent.
104filegroup(
105 name = "singlejar",
xingao1f0f1f12017-11-01 13:03:40 -0400106 srcs = select({
Loo Rong Jiec5573992018-11-06 05:50:45 -0800107 "//src/conditions:remote": ["//src/tools/singlejar:singlejar"],
xingao1f0f1f12017-11-01 13:03:40 -0400108 "//conditions:default": glob(["singlejar/*"]),
109 }),
xingao202d5912017-06-01 19:23:29 +0200110)
111
xingao8df71b52017-04-03 15:25:18 +0000112filegroup(
113 name = "genclass",
114 srcs = ["//tools/jdk:GenClass_deploy.jar"],
115)
116
117filegroup(
118 name = "turbine",
119 srcs = ["//tools/jdk:turbine_deploy.jar"],
120)
121
122filegroup(
Liam Miller-Cushonda77c4e2018-10-23 21:53:36 -0700123 name = "turbine_direct",
124 srcs = glob(["turbine_direct*"]),
125)
126
127filegroup(
xingao8df71b52017-04-03 15:25:18 +0000128 name = "javabuilder",
129 srcs = ["//tools/jdk:JavaBuilder_deploy.jar"],
130)
131
132filegroup(
133 name = "vanillajavabuilder",
134 srcs = ["//tools/jdk:VanillaJavaBuilder_deploy.jar"],
135)
136
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100137BOOTCLASS_JARS = [
138 "rt.jar",
139 "resources.jar",
140 "jsse.jar",
141 "jce.jar",
142 "charsets.jar",
143]
144
cushon29a96822017-12-20 16:19:56 -0800145# TODO(cushon): this isn't compatible with JDK 9
Ulf Adams27085f42016-10-06 08:51:47 +0000146alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100147 name = "bootclasspath",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000148 actual = "@local_jdk//:bootclasspath",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100149)
150
Ulf Adams27085f42016-10-06 08:51:47 +0000151alias(
Liam Miller-Cushon8153cb82017-02-17 03:42:18 +0000152 name = "extclasspath",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000153 actual = "@local_jdk//:extdir",
Liam Miller-Cushon22218602015-05-19 17:23:01 +0000154)
155
Irina Iancuc9a75d22017-02-21 13:45:20 +0000156# TODO(cushon): migrate to extclasspath and delete
157alias(
158 name = "extdir",
159 actual = "@local_jdk//:extdir",
160)
161
Liam Miller-Cushon22218602015-05-19 17:23:01 +0000162filegroup(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100163 name = "langtools",
Liam Miller-Cushon38949b82017-05-08 10:18:38 -0400164 srcs = ["//third_party/java/jdk/langtools:javac_jar"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100165)
166
167java_import(
168 name = "langtools-neverlink",
Liam Miller-Cushon1ed3c472015-06-19 00:35:26 +0000169 jars = [":langtools"],
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100170 neverlink = 1,
171)
172
Ulf Adams27085f42016-10-06 08:51:47 +0000173alias(
Philipp Wollermannc8db70c2015-08-21 13:35:10 +0000174 name = "jre",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000175 actual = "@local_jdk//:jre",
Philipp Wollermannc8db70c2015-08-21 13:35:10 +0000176)
177
Ulf Adams27085f42016-10-06 08:51:47 +0000178alias(
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100179 name = "jdk",
Ulf Adamsc8510b12017-02-14 10:27:11 +0000180 actual = "@local_jdk//:jdk",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100181)
182
lberkic4cd9862017-12-05 05:57:27 -0800183alias(
184 name = "host_jdk",
Tobias Werthbf18a9f2018-12-06 01:40:33 -0800185 actual = ":remote_jdk",
lberkic4cd9862017-12-05 05:57:27 -0800186)
187
cushon999354b2018-09-21 00:31:42 -0700188bootclasspath(
189 name = "platformclasspath",
190 src = "DumpPlatformClassPath.java",
191 host_javabase = "current_java_runtime",
cushon999354b2018-09-21 00:31:42 -0700192 target_javabase = "current_java_runtime",
193)
194
cushon5c16ab232017-12-19 16:18:49 -0800195default_java_toolchain(
cushonc1705f02018-08-07 10:31:41 -0700196 name = "toolchain_hostjdk8",
lberki7eb9ea12018-09-07 04:01:48 -0700197 jvm_opts = JDK8_JVM_OPTS,
cushonc1705f02018-08-07 10:31:41 -0700198 source_version = "8",
199 target_version = "8",
200)
201
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700202# Default to the Java 8 language level.
203# TODO(cushon): consider if/when we should increment this?
cushon999354b2018-09-21 00:31:42 -0700204default_java_toolchain(
cushon137504e2018-09-25 18:15:09 -0700205 name = "toolchain",
cushon999354b2018-09-21 00:31:42 -0700206 source_version = "8",
207 target_version = "8",
cushona1ef9992018-05-14 09:38:41 -0700208)
209
David Ostrovsky0bef68e2018-09-20 12:13:56 -0700210# The 'vanilla' toolchain is an unsupported alternative to the default.
211#
212# It does not provider any of the following features:
213# * Error Prone
214# * Strict Java Deps
215# * Header Compilation
216# * Reduced Classpath Optimization
217#
218# It uses the version of javac from the `--host_javabase` instead of the
219# embedded javac, which may not be source- or bug-compatible with the embedded
220# javac.
221#
222# However it does allow using a wider range of `--host_javabase`s, including
223# versions newer than the current embedded JDK.
224default_java_toolchain(
225 name = "toolchain_vanilla",
226 forcibly_disable_header_compilation = True,
227 javabuilder = [":vanillajavabuilder"],
228 jvm_opts = [],
229)
230
cushon5a1ed1f2018-09-26 13:41:54 -0700231RELEASES = (8, 9)
232
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700233[
234 default_java_toolchain(
235 name = "toolchain_java%d" % release,
Liam Miller-Cushon39873002018-08-28 18:47:25 -0700236 source_version = "%s" % release,
237 target_version = "%s" % release,
238 )
239 for release in RELEASES
240]
buchgr4c9149d2018-07-24 11:50:48 -0700241
Damien Martin-Guillerez5cbd5a42015-03-24 21:55:19 +0000242filegroup(
243 name = "srcs",
Michael Staib6817a6f2015-10-05 15:58:23 +0000244 srcs = [
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +0000245 "BUILD-jdk", # Tools are build from the workspace for tests.
cushon29a96822017-12-20 16:19:56 -0800246 "DumpPlatformClassPath.java",
cushon5c16ab232017-12-19 16:18:49 -0800247 "default_java_toolchain.bzl",
Michael Staib6817a6f2015-10-05 15:58:23 +0000248 "proguard_whitelister.py",
249 "proguard_whitelister_test.py",
250 "proguard_whitelister_test_input.cfg",
251 ],
Damien Martin-Guillerez5cbd5a42015-03-24 21:55:19 +0000252)
Damien Martin-Guillerezab13f682015-07-28 08:19:32 +0000253
254filegroup(
255 name = "package-srcs",
256 srcs = glob(["**"]),
257)
Michael Staib6817a6f2015-10-05 15:58:23 +0000258
259py_binary(
260 name = "proguard_whitelister",
261 srcs = [
262 "proguard_whitelister.py",
263 ],
264 deps = [
265 "//third_party/py/gflags",
266 ],
267)
268
269py_test(
270 name = "proguard_whitelister_test",
271 srcs = ["proguard_whitelister_test.py"],
272 data = ["proguard_whitelister_test_input.cfg"],
273 deps = [
274 ":proguard_whitelister",
275 ],
276)
Yue Gan4a753492016-12-20 04:54:55 +0000277
278# For java coverage
279alias(
280 name = "jacoco-blaze-agent",
281 actual = "//third_party/java/jacoco:blaze-agent",
282)
283
Damien Martin-Guillerez39e5a462016-12-20 10:58:17 +0000284java_import(
Yue Gan4a753492016-12-20 04:54:55 +0000285 name = "JacocoCoverage",
Damien Martin-Guillerez39e5a462016-12-20 10:58:17 +0000286 jars = [":JacocoCoverage_deploy.jar"],
Yue Gan4a753492016-12-20 04:54:55 +0000287)
Laszlo Csomordf16c772018-08-09 23:36:39 -0700288
289test_suite(
290 name = "windows_tests",
291 tags = [
292 "-no_windows",
293 "-slow",
294 ],
295 visibility = ["//visibility:private"],
296)
297
298test_suite(
299 name = "all_windows_tests",
300 tests = [":windows_tests"],
301 visibility = ["//tools:__pkg__"],
302)
Tobias Werth1b757622018-10-10 07:26:23 -0700303
304# Replacement for the embedded JDK as host javabase.
305alias(
306 name = "remote_jdk",
307 actual = select(
308 {
309 "//src/conditions:darwin": "@remotejdk_macos//:jdk",
310 "//src/conditions:darwin_x86_64": "@remotejdk_macos//:jdk",
311 "//src/conditions:windows": "@remotejdk_win//:jdk",
312 "//src/conditions:linux_aarch64": "@remotejdk_linux_aarch64//:jdk",
313 "//src/conditions:linux_x86_64": "@remotejdk_linux//:jdk",
314 },
twerthedce5802018-10-10 08:18:15 -0700315 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
316 " provide one using `--host_javabase.`",
Tobias Werth1b757622018-10-10 07:26:23 -0700317 ),
318 visibility = ["//visibility:public"],
319)
cushon825c0492018-10-10 13:57:11 -0700320
321# A JDK 10 for use as a --host_javabase.
322alias(
323 name = "remote_jdk10",
324 actual = select(
325 {
326 "//src/conditions:darwin": "@remotejdk10_macos//:jdk",
327 "//src/conditions:darwin_x86_64": "@remotejdk10_macos//:jdk",
328 "//src/conditions:windows": "@remotejdk10_win//:jdk",
329 "//src/conditions:linux_aarch64": "@remotejdk10_linux_aarch64//:jdk",
330 "//src/conditions:linux_x86_64": "@remotejdk10_linux//:jdk",
331 },
332 no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
333 " provide one using `--host_javabase.`",
334 ),
335 visibility = ["//visibility:public"],
336)