Skip to content
This repository was archived by the owner on Nov 29, 2022. It is now read-only.

Commit 3a967de

Browse files
author
Tom Renn
committed
Use java toolchains
The --javabase, and --java_toolchain options are removed in Bazel 5.0. bazelbuild/bazel#7849 Also removed javacopt as the default java options includes "-g", which generates all debugging information (source,lines,vars). See https://cs.opensource.google/bazel/bazel/+/refs/tags/5.0.0:tools/jdk/default_java_toolchain.bzl;l=49 Two jdk11 toolchains are registered (in addition to the runtime toolchain). *java8_definition and *java11_definition have different values for source and target version compatibility. These toolchains can be switched by using different values of --java_language_version. Bug: 220902606 Test: presubmit passes Change-Id: I3c59eb277279b40cc3371e3986c9a5980c370e3c
1 parent 1d5c8e1 commit 3a967de

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

bazel/bazel.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def _iml_module_jar_impl(
136136
deps = java_deps + kotlin_providers,
137137
javac_opts = java_common.default_javac_opts(java_toolchain = java_toolchain) + ctx.attr.javacopts,
138138
java_toolchain = java_toolchain,
139-
host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase),
140139
sourcepath = sourcepath,
141140
# TODO(b/216385876) After updating to Bazel 5.0, use enable_compile_jar_action = use_ijar,
142141
)
@@ -371,7 +370,6 @@ _iml_module_ = rule(
371370
"data": attr.label_list(allow_files = True),
372371
"test_data": attr.label_list(allow_files = True),
373372
"_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")),
374-
"_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_host_java_runtime")),
375373
"_zipper": attr.label(
376374
default = Label("@bazel_tools//tools/zip:zipper"),
377375
cfg = "host",

bazel/common.bazelrc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ build:datasize_aspect --output_groups=+data_size
4747

4848
build --incompatible_strict_action_env # Ensures actions don't pick up env changes
4949
build --sandbox_tmpfs_path=/tmp
50-
build --javacopt="-g:source,lines,vars" # Keep debug info
5150
# TODO (b/141269926): this generates a warning on windows when building for host,
5251
# but is required when building for android.
5352
build --copt=-fvisibility=hidden
@@ -58,11 +57,10 @@ build --define=grpc_no_ares=true
5857
# finds make in the ndk-build script (see b/72179674).
5958
build --test_env=SHELL
6059

61-
# Use prebuilt JDK when doing local bazel build/test
62-
build --host_javabase=//prebuilts/studio/jdk:jdk11_runtime
63-
build --javabase=//prebuilts/studio/jdk:jdk11_runtime
64-
build --host_java_toolchain=@bazel_tools//tools/jdk:legacy_toolchain
65-
build --java_toolchain=@bazel_tools//tools/jdk:legacy_toolchain
60+
# Bazel will find the matching java toolchain registered in WORKSPACE.
61+
build --java_language_version=8
62+
build --java_runtime_version=jdk11
63+
build --tool_java_runtime_version=jdk11
6664

6765
# Use prebuilt native toolchain
6866
build --crosstool_top=@native_toolchain//:toolchain

bazel/kotlin.bzl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,13 @@ def kotlin_test(
133133
)
134134

135135
# Creates actions to generate the sources jar
136-
def _sources(ctx, srcs, source_jars, jar, java_toolchain, host_javabase):
136+
def _sources(ctx, srcs, source_jars, jar, java_toolchain):
137137
java_common.pack_sources(
138138
ctx.actions,
139139
output_source_jar = jar,
140140
sources = srcs,
141141
source_jars = source_jars,
142142
java_toolchain = java_toolchain,
143-
host_javabase = host_javabase,
144143
)
145144

146145
# Creates actions to generate a resources_jar from the given resources.
@@ -297,7 +296,6 @@ def _kotlin_library_impl(ctx):
297296
jars += [resources_jar]
298297

299298
java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain)
300-
host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase)
301299

302300
# Java
303301
if java_srcs or source_jars:
@@ -310,8 +308,7 @@ def _kotlin_library_impl(ctx):
310308
deps = deps + kotlin_providers,
311309
javac_opts = java_common.default_javac_opts(java_toolchain = java_toolchain) + ctx.attr.javacopts,
312310
java_toolchain = java_toolchain,
313-
host_javabase = host_javabase,
314-
plugins = [plugin[JavaInfo] for plugin in ctx.attr.plugins],
311+
plugins = [plugin[JavaPluginInfo] for plugin in ctx.attr.plugins],
315312
# TODO(b/216385876) After updating to Bazel 5.0, use enable_compile_jar_action = use_ijar,
316313
)
317314

@@ -337,7 +334,7 @@ def _kotlin_library_impl(ctx):
337334
allow_duplicates = True,
338335
)
339336

340-
_sources(ctx, java_srcs + kotlin_srcs, source_jars, ctx.outputs.source_jar, java_toolchain, host_javabase)
337+
_sources(ctx, java_srcs + kotlin_srcs, source_jars, ctx.outputs.source_jar, java_toolchain)
341338

342339
java_info = JavaInfo(
343340
output_jar = ctx.outputs.jar,
@@ -382,11 +379,10 @@ _kotlin_library = rule(
382379
"kotlin_use_ir": attr.bool(),
383380
"compress_resources": attr.bool(),
384381
"plugins": attr.label_list(
385-
providers = [JavaInfo],
382+
providers = [JavaPluginInfo],
386383
),
387384
"stdlib": attr.label(),
388385
"_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")),
389-
"_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_host_java_runtime")),
390386
"_bootclasspath": attr.label(
391387
# Use JDK 8 because AGP still needs to support it (b/166472930).
392388
default = Label("//prebuilts/studio/jdk:bootclasspath"),

bazel/toplevel.WORKSPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ register_toolchains(
1111
"@native_toolchain//:cc-toolchain-x64_windows-clang-cl",
1212
"//tools/base/bazel/toolchains/darwin:python_toolchain",
1313
"//tools/base/bazel/toolchains/darwin:python_toolchain_10.13",
14+
"//prebuilts/studio/jdk:runtime_toolchain_definition",
15+
"//prebuilts/studio/jdk:jdk11_toolchain_java8_definition",
16+
"//prebuilts/studio/jdk:jdk11_toolchain_java11_definition",
1417
)
1518

1619
local_repository(

0 commit comments

Comments
 (0)