Skip to content

Commit 0116723

Browse files
cushonrules_java Copybara
authored andcommitted
Add support for configuring --system using java_package_configuration
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: Iaa2020525b204cf9eabc0cd1830cb3bdc40da683
1 parent e6009ef commit 0116723

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

java/common/rules/java_package_configuration.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ load("//java/common/rules/impl:java_helper.bzl", "helper")
2121

2222
_java_common_internal = java_common.internal_DO_NOT_USE()
2323

24+
BootClassPathInfo = java_common.BootClassPathInfo
25+
2426
JavaPackageConfigurationInfo = provider(
2527
"A provider for Java per-package configuration",
2628
fields = [
2729
"data",
2830
"javac_opts",
2931
"matches",
3032
"package_specs",
33+
"system",
3134
],
3235
)
3336

@@ -41,13 +44,15 @@ def _rule_impl(ctx):
4144
javacopts = _java_common_internal.expand_java_opts(ctx, "javacopts", tokenize = True)
4245
javacopts_depset = helper.detokenize_javacopts(javacopts)
4346
package_specs = [package[PackageSpecificationInfo] for package in ctx.attr.packages]
47+
system = ctx.attr.system[BootClassPathInfo] if ctx.attr.system else None
4448
return [
4549
DefaultInfo(),
4650
JavaPackageConfigurationInfo(
4751
data = depset(ctx.files.data),
4852
javac_opts = javacopts_depset,
4953
matches = lambda label: _matches(package_specs, label),
5054
package_specs = package_specs,
55+
system = system,
5156
),
5257
]
5358

@@ -104,11 +109,18 @@ Java compiler flags.
104109
""",
105110
),
106111
"data": attr.label_list(
112+
cfg = "exec",
107113
allow_files = True,
108114
doc = """
109115
The list of files needed by this configuration at runtime.
110116
""",
111117
),
118+
"system": attr.label(
119+
providers = [BootClassPathInfo],
120+
doc = """
121+
Corresponds to javac's --system flag.
122+
""",
123+
),
112124
# buildifier: disable=attr-licenses
113125
"output_licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
114126
},

java/common/rules/java_toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ Label of the one-version allowlist for tests.
522522
""",
523523
),
524524
"package_configuration": attr.label_list(
525-
cfg = "exec",
525+
cfg = "target",
526526
providers = [JavaPackageConfigurationInfo],
527527
doc = """
528528
Configuration that should be applied to the specified package groups.

java/docs/rules.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ java_library(<a href="#java_library-name">name</a>, <a href="#java_library-deps"
247247
## java_package_configuration
248248

249249
<pre>
250-
java_package_configuration(<a href="#java_package_configuration-name">name</a>, <a href="#java_package_configuration-data">data</a>, <a href="#java_package_configuration-javacopts">javacopts</a>, <a href="#java_package_configuration-output_licenses">output_licenses</a>, <a href="#java_package_configuration-packages">packages</a>)
250+
java_package_configuration(<a href="#java_package_configuration-name">name</a>, <a href="#java_package_configuration-data">data</a>, <a href="#java_package_configuration-javacopts">javacopts</a>, <a href="#java_package_configuration-output_licenses">output_licenses</a>, <a href="#java_package_configuration-packages">packages</a>, <a href="#java_package_configuration-system">system</a>)
251251
</pre>
252252

253253
<p>
@@ -295,6 +295,7 @@ java_toolchain(
295295
| <a id="java_package_configuration-javacopts"></a>javacopts | Java compiler flags. | List of strings | optional | `[]` |
296296
| <a id="java_package_configuration-output_licenses"></a>output_licenses | - | List of strings | optional | `[]` |
297297
| <a id="java_package_configuration-packages"></a>packages | The set of <code><a href="${link package_group}">package_group</a></code>s the configuration should be applied to. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
298+
| <a id="java_package_configuration-system"></a>system | Corresponds to javac's --system flag. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
298299

299300

300301
<a id="java_plugin"></a>

0 commit comments

Comments
 (0)