Skip to content

Commit

Permalink
Update handling of JavaInfo.compilation_info.javac_opts
Browse files Browse the repository at this point in the history
In order to use the helper utility method from `@rules_java`, this also needed the following additional changes:

- Update rules_java version to 7.2.0 (the first version that has the utility)
- Update bazel version(s) (the new rules_java requires a bazel version >= 6.4.0). (in any case, now that bazel 6.4.0 has been released, 6.3.0 is unsupported)
- Registering the new java bootstrap toolchains (see bazelbuild/bazel#18262)

Happy to split these changes off into separate PRs if it would make review easier.
  • Loading branch information
hvadehra committed Nov 16, 2023
1 parent 3c922e0 commit 35075fc
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .bazelminversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0
6.4.0
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0
6.4.0
37 changes: 23 additions & 14 deletions external.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende
load(
"@rules_java//java:repositories.bzl",
"remote_jdk17_repos",
"remote_jdk20_repos",
"remote_jdk21_repos",
"rules_java_dependencies",
"rules_java_toolchains",
)
load("@rules_java//toolchains:remote_java_repository.bzl", "remote_java_repository")
load("@rules_jvm_external//:defs.bzl", "maven_install")
Expand All @@ -43,13 +44,21 @@ def _rule_dependencies():
remote_jdk19_repos()
remote_jdk20_repos()
remote_jdk21_repos()
native.register_toolchains(
"@local_jdk//:runtime_toolchain_definition",
"@local_jdk//:bootstrap_runtime_toolchain_definition",
)
native.register_toolchains("@local_jdk//:runtime_toolchain_definition")
for version in ("11", "17", "19", "20", "21"):
for platform in ("linux", "macos", "win"):
native.register_toolchains("@remotejdk{version}_{platform}_toolchain_config_repo//:toolchain".format(
repo = "@remotejdk{version}_{platform}_toolchain_config_repo".format(
version = version,
platform = platform,
))
)
native.register_toolchains(
repo + "//:toolchain",
repo + "//:bootstrap_runtime_toolchain",
)
native.register_toolchains("//buildenv/java:all")

protobuf_deps()
Expand Down Expand Up @@ -1929,38 +1938,38 @@ def remote_jdk19_repos():
version = "19.32.13-ca-jdk19.0.2",
)

def remote_jdk21_repos():
"""Imports OpenJDK 21 repositories."""
def remote_jdk20_repos():
"""Imports OpenJDK 20 repositories."""

maybe(
_remote_jdk_repository,
name = "remotejdk21_linux",
name = "remotejdk20_linux",
os = "linux",
cpu = "x86_64",
version = "21.28.85-ca-jdk21.0.0",
sha256 = "0c0eadfbdc47a7ca64aeab51b9c061f71b6e4d25d2d87674512e9b6387e9e3a6",
version = "20.28.85-ca-jdk20.0.0",
sha256 = "0386418db7f23ae677d05045d30224094fc13423593ce9cd087d455069893bac",
)

maybe(
_remote_jdk_repository,
name = "remotejdk21_macos",
name = "remotejdk20_macos",
os = "macos",
cpu = "x86_64",
version = "21.28.85-ca-jdk21.0.0",
version = "20.28.85-ca-jdk20.0.0",
)

maybe(
_remote_jdk_repository,
name = "remotejdk21_macos_aarch64",
name = "remotejdk20_macos_aarch64",
os = "macos",
cpu = "aarch64",
version = "21.28.85-ca-jdk21.0.0",
version = "20.28.85-ca-jdk20.0.0",
)

maybe(
_remote_jdk_repository,
name = "remotejdk21_win",
name = "remotejdk20_win",
os = "windows",
cpu = "x86_64",
version = "21.28.85-ca-jdk21.0.0",
version = "20.28.85-ca-jdk20.0.0",
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ java_binary(
bzl_library(
name = "aspect_bzl",
srcs = ["aspect.bzl"],
deps = ["@rules_java//java:utils"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_java//java:java_utils.bzl", _java_utils = "utils")

_mnemonic = "Javac"

Expand All @@ -34,6 +35,9 @@ def _extract_java(target, ctx):
compilation = info.compilation_info
annotations = info.annotation_processing

# compilation.javac_options may be a depset
javac_options = _java_utils.tokenize_javacopts(ctx, compilation.javac_options)

source_files = []
for src in ctx.rule.files.srcs:
source_files.append(src.path)
Expand Down Expand Up @@ -61,7 +65,7 @@ def _extract_java(target, ctx):
outputjar = output_jar,
classpath = classpath,
source_file = source_files,
javac_opt = compilation.javac_options,
javac_opt = javac_options,
processor = processors,
processorpath = processorpath,
bootclasspath = bootclasspath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,5 @@ java_library(
bzl_library(
name = "aspect_bzl",
srcs = ["aspect.bzl"],
deps = ["@rules_java//java:utils"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

load("//tools/build_rules/verifier_test:verifier_test.bzl", "extract")
load("@rules_java//java:java_utils.bzl", _java_utils = "utils")

def _extract_java_aspect(target, ctx):
if JavaInfo not in target or not hasattr(ctx.rule.attr, "srcs"):
Expand All @@ -24,6 +25,9 @@ def _extract_java_aspect(target, ctx):
compilation = info.compilation_info
annotations = info.annotation_processing

# compilation.javac_options may be a depset
javac_options = _java_utils.tokenize_javacopts(ctx, compilation.javac_options)

classpath = [j.path for j in compilation.compilation_classpath]
bootclasspath = [j.path for j in compilation.boot_classpath]

Expand All @@ -34,7 +38,7 @@ def _extract_java_aspect(target, ctx):
processors = annotations.processor_classnames

# Skip --release options; -source/-target/-bootclasspath are already set
args = _remove_flags(compilation.javac_options, {"--release": 1}) + [
args = _remove_flags(javac_options, {"--release": 1}) + [
"-cp",
":".join(classpath),
"-bootclasspath",
Expand Down
6 changes: 3 additions & 3 deletions setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def kythe_rule_repositories():
name = "rules_java",
urls = [
# Note: when updating rules_java, please check if the ModuleName check in tools/javacopts.bazelrc can be re-enabled.
"https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/6.5.1/rules_java-6.5.1.tar.gz",
"https://github.com/bazelbuild/rules_java/releases/download/6.5.1/rules_java-6.5.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/7.2.0/rules_java-7.2.0.tar.gz",
"https://github.com/bazelbuild/rules_java/releases/download/7.2.0/rules_java-7.2.0.tar.gz",
],
sha256 = "7b0d9ba216c821ee8697dedc0f9d0a705959ace462a3885fe9ba0347ba950111",
sha256 = "eb7db63ed826567b2ceb1ec53d6b729e01636f72c9f5dfb6d2dfe55ad69d1d2a",
)

maybe(
Expand Down
4 changes: 2 additions & 2 deletions version.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Minimum supported Bazel version. Should match .bazelminversion file.
MIN_VERSION = "6.3.0"
MIN_VERSION = "6.4.0"

# Maximum supported Bazel version. Should match .bazelversion file.
MAX_VERSION = "6.3.0"
MAX_VERSION = "6.4.0"

def _tuplicate(value, delim):
rv = ()
Expand Down

0 comments on commit 35075fc

Please sign in to comment.