Skip to content

Commit

Permalink
Allow Bazel's own build to use Java 11 language features
Browse files Browse the repository at this point in the history
Fixes #14592

PiperOrigin-RevId: 422562457
  • Loading branch information
cushon authored and copybara-github committed Jan 18, 2022
1 parent 98e80e1 commit 0c65082
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ build:bzlmod --experimental_enable_bzlmod
build:bzlmod --crosstool_top=@rules_cc.0.0.1.cc_configure.local_config_cc//:toolchain
build:bzlmod --xcode_version_config=@rules_cc.0.0.1.cc_configure.local_config_xcode//:host_xcodes

# Enable Java 11 language features (https://github.com/bazelbuild/bazel/issues/14592)
# Toolchain resolution configuration for Bazel >= 5
build --java_language_version=11
build --tool_java_language_version=11
# Legacy configuration for Bazel <= 4
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11

# User-specific .bazelrc
try-import user.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ java_library(
["javac/*.java"],
exclude = JAVAC_OPTIONS_SRCS + JAVAC_TEST_SRCS,
),
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
],
deps = [
":invalid_command_line_exception",
":javac_options",
Expand All @@ -60,7 +68,6 @@ java_library(
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/java/jdk/langtools:javac",
"//third_party/protobuf:protobuf_java",
],
)
Expand Down Expand Up @@ -212,6 +219,11 @@ bootstrap_java_binary(
java_test(
name = "BootClassPathCachingFileManagerTest",
srcs = ["javac/BootClassPathCachingFileManagerTest.java"],
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
],
deps = [
":javac",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@ package(default_visibility = ["//src/java_tools/buildjar:buildjar_package_group"
java_library(
name = "plugins",
srcs = ["BlazeJavaCompilerPlugin.java"],
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
deps = [
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:invalid_command_line_exception",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/statistics",
"//third_party:guava",
"//third_party/java/jdk/langtools:javac",
],
)

java_library(
name = "dependency",
srcs = glob(["dependency/*.java"]),
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.resources=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
deps = [
":plugins",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:JarOwner",
Expand All @@ -28,31 +40,39 @@ java_library(
"//third_party:auto_value",
"//third_party:guava",
"//third_party:tomcat_annotations_api",
"//third_party/java/jdk/langtools:javac",
],
)

java_library(
name = "errorprone",
srcs = glob(["errorprone/*.java"]),
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
deps = [
":plugins",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:invalid_command_line_exception",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/statistics",
"//third_party:error_prone",
"//third_party:guava",
"//third_party/java/jdk/langtools:javac",
],
)

java_library(
name = "processing",
srcs = glob(["processing/*.java"]),
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
deps = [
":plugins",
"//src/main/protobuf:java_compilation_java_proto",
"//third_party:guava",
"//third_party/java/jdk/langtools:javac",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package(default_visibility = ["//visibility:public"])
java_library(
name = "statistics",
srcs = ["BlazeJavacStatistics.java"],
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
deps = [
"//third_party:auto_value",
"//third_party:caffeine",
"//third_party:guava",
"//third_party/java/jdk/langtools:javac",
],
)

Expand Down
22 changes: 18 additions & 4 deletions src/test/java/com/google/devtools/build/android/desugar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ java_test(
srcs = [
"DesugarCoreLibraryFunctionalTest.java",
],
javacopts = ["-source 8 -target 8"],
jvm_flags = [
# TODO (b/72181101): -Xbootclasspath/p is removed in JDK 9.
"-XX:+IgnoreUnrecognizedVMOptions",
Expand Down Expand Up @@ -693,7 +694,10 @@ sh_test(
java_library(
name = "testdata",
srcs = glob(["testdata/*.java"]),
javacopts = ["-Xep:SelfAssignment:OFF"],
javacopts = [
"-Xep:SelfAssignment:OFF",
"-source 8 -target 8",
],
resources = ["testdata/testresource.txt"],
deps = [
":separate",
Expand All @@ -707,7 +711,10 @@ java_library(
"testdata/*.java",
"testdata/java8/**/*.java",
]),
javacopts = ["-Xep:SelfAssignment:OFF"],
javacopts = [
"-Xep:SelfAssignment:OFF",
"-source 8 -target 8",
],
resources = ["testdata/testresource.txt"],
deps = [
":separate",
Expand All @@ -721,6 +728,7 @@ java_library(
srcs = glob([
"testdata/core_library/**/*.java",
]),
javacopts = ["-source 8 -target 8"],
resources = ["testdata/testresource.txt"],
deps = [
"//third_party:error_prone",
Expand All @@ -741,7 +749,10 @@ java_library(
java_library(
name = "testdata_like_in_android_studio",
srcs = glob(["testdata/*.java"]),
javacopts = ["-Xep:SelfAssignment:OFF"],
javacopts = [
"-Xep:SelfAssignment:OFF",
"-source 8 -target 8",
],
resources = ["testdata/testresource.txt"],
deps = [
":libseparate.jar", # puts full Jar instead of header Jar on the classpath
Expand All @@ -755,7 +766,10 @@ java_library(
"testdata/*.java",
"testdata/java8/**/*.java",
]),
javacopts = ["-Xep:SelfAssignment:OFF"],
javacopts = [
"-Xep:SelfAssignment:OFF",
"-source 8 -target 8",
],
resources = ["testdata/testresource.txt"],
deps = [
":libseparate.jar", # puts full Jar instead of header Jar on the classpath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ java_library(
],
exclude = ["DependencyInfo.java"],
),
javacopts = [
"--add-exports=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED",
],
exports = [
# Separated out to avoid a dependency cycle with resources/, but it logically belongs here.
":dependency_info",
Expand Down
1 change: 1 addition & 0 deletions third_party/ijar/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ genrule(
java_library(
name = "local_and_anonymous_lib",
srcs = ["LocalAndAnonymous.java"],
javacopts = ["-source 8 -target 8"],
)

genrule(
Expand Down

0 comments on commit 0c65082

Please sign in to comment.