Skip to content

Commit

Permalink
Add support for configuring --system using `java_package_configurat…
Browse files Browse the repository at this point in the history
…ion`

Also use `cfg = "target"` for `java_toolchain.package_configuration` to ensure `java_package_configuration.system` is built in the target config, and do the exec transition later for `java_package_configuration.data` (which we do want in the exec config). The system needs to match the target Java language configuration, the data is an exec dependency used at built-time.

PiperOrigin-RevId: 684478368
Change-Id: Ia546c9bc84cc726c985b15e7785af390a02b0349
  • Loading branch information
cushon authored and copybara-github committed Oct 10, 2024
1 parent 0e876b1 commit d12959c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@ def compile(
["-Abazel.repository=" + ctx.label.workspace_name],
order = "preorder",
))
system_override = False
for package_config in java_toolchain._package_configuration:
if package_config.matches(ctx.label):
all_javac_opts.append(package_config.javac_opts)
if package_config.system:
if system_override:
fail("Multiple system package configurations found for %s" % ctx.label)
bootclasspath = package_config.system
system_override = True

all_javac_opts.append(depset(
["--add-exports=%s=ALL-UNNAMED" % x for x in add_exports],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Implementation for the java_package_configuration rule"""

load(":common/java/boot_class_path_info.bzl", "BootClassPathInfo")
load(":common/java/java_helper.bzl", "helper")

_java_common_internal = _builtins.internal.java_common_internal_do_not_use
Expand All @@ -27,6 +28,7 @@ JavaPackageConfigurationInfo = provider(
"javac_opts",
"matches",
"package_specs",
"system",
],
)

Expand All @@ -40,13 +42,15 @@ def _rule_impl(ctx):
javacopts = _java_common_internal.expand_java_opts(ctx, "javacopts", tokenize = True)
javacopts_depset = helper.detokenize_javacopts(javacopts)
package_specs = [package[PackageSpecificationInfo] for package in ctx.attr.packages]
system = ctx.attr.system[BootClassPathInfo] if ctx.attr.system else None
return [
DefaultInfo(),
JavaPackageConfigurationInfo(
data = depset(ctx.files.data),
javac_opts = javacopts_depset,
matches = lambda label: _matches(package_specs, label),
package_specs = package_specs,
system = system,
),
]

Expand Down Expand Up @@ -103,11 +107,18 @@ Java compiler flags.
""",
),
"data": attr.label_list(
cfg = "exec",
allow_files = True,
doc = """
The list of files needed by this configuration at runtime.
""",
),
"system": attr.label(
providers = [BootClassPathInfo],
doc = """
Corresponds to javac's --system flag.
""",
),
"output_licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ Label of the one-version allowlist for tests.
""",
),
"package_configuration": attr.label_list(
cfg = "exec",
cfg = "target",
providers = [JavaPackageConfigurationInfo],
doc = """
Configuration that should be applied to the specified package groups.
Expand Down

0 comments on commit d12959c

Please sign in to comment.