Make part of @bazel_tools compatible with --incompatible_disallow_struct_provider_syntax
Fix xcode_version_flag.bzl without incompatible change.
Fix java_rules_skylark with a potentially incompatible change. This file is marked to only be used for bootstrapping bazel (and thus should not be depended on), so hopefully, indeed, no users are depending on it.
Progress toward #7347.
RELNOTES: None.
PiperOrigin-RevId: 244400176
diff --git a/tools/build_rules/java_rules_skylark.bzl b/tools/build_rules/java_rules_skylark.bzl
index f99449f..f837fe4 100644
--- a/tools/build_rules/java_rules_skylark.bzl
+++ b/tools/build_rules/java_rules_skylark.bzl
@@ -19,14 +19,20 @@
ready.
"""
-def java_library_impl(ctx):
+_JarsInfo = provider(fields = ["compile_time_jars", "runtime_jars"])
+
+def _java_library_impl(ctx):
javac_options = ctx.fragments.java.default_javac_flags
class_jar = ctx.outputs.class_jar
compile_time_jars = depset(order = "topological")
runtime_jars = depset(order = "topological")
for dep in ctx.attr.deps:
- compile_time_jars += dep.compile_time_jars
- runtime_jars += dep.runtime_jars
+ compile_time_jars = depset(
+ transitive = [compile_time_jars, dep[_JarsInfo].compile_time_jars],
+ )
+ runtime_jars = depset(
+ transitive = [runtime_jars, dep[_JarsInfo].runtime_jars],
+ )
jars = ctx.files.jars
neverlink_jars = ctx.files.neverlink_jars
@@ -83,17 +89,22 @@
runfiles = ctx.runfiles(collect_data = True)
- return struct(
- compile_time_jars = compile_time_jars + [class_jar],
- runtime_jars = runtime_jars + [class_jar],
- providers = [DefaultInfo(
+ compile_time_jars = depset(transitive = [compile_time_jars], direct = [class_jar])
+ runtime_jars = depset(transitive = [runtime_jars], direct = [class_jar])
+
+ return [
+ DefaultInfo(
files = depset([class_jar]),
runfiles = runfiles,
- )],
- )
+ ),
+ _JarsInfo(
+ compile_time_jars = compile_time_jars,
+ runtime_jars = runtime_jars,
+ ),
+ ]
-def java_binary_impl(ctx):
- library_result = java_library_impl(ctx)
+def _java_binary_impl(ctx):
+ library_result = _java_library_impl(ctx)
deploy_jar = ctx.outputs.deploy_jar
manifest = ctx.outputs.manifest
@@ -109,14 +120,14 @@
# Cleaning build output directory
cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n"
- for jar in library_result.runtime_jars:
+ for jar in library_result[1].runtime_jars:
cmd += "unzip -qn " + jar.path + " -d " + build_output + "\n"
cmd += (jar_path + " cmf " + manifest.path + " " +
deploy_jar.path + " -C " + build_output + " .\n" +
"touch " + build_output + "\n")
ctx.actions.run_shell(
- inputs = list(library_result.runtime_jars) + [manifest] + ctx.files._jdk,
+ inputs = list(library_result[1].runtime_jars) + [manifest] + ctx.files._jdk,
outputs = [deploy_jar],
mnemonic = "Deployjar",
command = cmd,
@@ -169,22 +180,28 @@
)
runfiles = ctx.runfiles(files = [deploy_jar, executable] + ctx.files._jdk, collect_data = True)
- files_to_build = depset([deploy_jar, manifest, executable])
- files_to_build += library_result.providers[0].files
+ files_to_build = depset(
+ transitive = [library_result[0].files],
+ direct = [deploy_jar, manifest, executable],
+ )
return [DefaultInfo(files = files_to_build, runfiles = runfiles)]
-def java_import_impl(ctx):
+def _java_import_impl(ctx):
# TODO(bazel-team): Why do we need to filter here? The attribute
# already says only jars are allowed.
jars = depset(ctx.files.jars)
neverlink_jars = depset(ctx.files.neverlink_jars)
runfiles = ctx.runfiles(collect_data = True)
- return struct(
- compile_time_jars = jars + neverlink_jars,
- runtime_jars = jars,
- providers = [DefaultInfo(files = jars, runfiles = runfiles)],
- )
+ compile_time_jars = depset(transitive = [jars, neverlink_jars])
+
+ return [
+ DefaultInfo(files = jars, runfiles = runfiles),
+ _JarsInfo(
+ compile_time_jars = compile_time_jars,
+ runtime_jars = jars,
+ ),
+ ]
java_library_attrs = {
"_jdk": attr.label(
@@ -199,12 +216,12 @@
"srcjars": attr.label_list(allow_files = [".jar", ".srcjar"]),
"deps": attr.label_list(
allow_files = False,
- providers = ["compile_time_jars", "runtime_jars"],
+ providers = [_JarsInfo],
),
}
java_library = rule(
- java_library_impl,
+ _java_library_impl,
attrs = java_library_attrs,
outputs = {
"class_jar": "lib%{name}.jar",
@@ -214,7 +231,7 @@
# A copy to avoid conflict with native rule.
bootstrap_java_library = rule(
- java_library_impl,
+ _java_library_impl,
attrs = java_library_attrs,
outputs = {
"class_jar": "lib%{name}.jar",
@@ -238,7 +255,7 @@
}
java_binary = rule(
- java_binary_impl,
+ _java_binary_impl,
executable = True,
attrs = java_binary_attrs,
outputs = java_binary_outputs,
@@ -247,7 +264,7 @@
# A copy to avoid conflict with native rule
bootstrap_java_binary = rule(
- java_binary_impl,
+ _java_binary_impl,
executable = True,
attrs = java_binary_attrs,
outputs = java_binary_outputs,
@@ -255,7 +272,7 @@
)
java_test = rule(
- java_binary_impl,
+ _java_binary_impl,
executable = True,
attrs = dict(list(java_binary_attrs_common.items()) + [
("main_class", attr.string(default = "org.junit.runner.JUnitCore")),
@@ -269,7 +286,7 @@
)
java_import = rule(
- java_import_impl,
+ _java_import_impl,
attrs = {
"jars": attr.label_list(allow_files = [".jar"]),
"srcjar": attr.label(allow_files = [".jar", ".srcjar"]),
diff --git a/tools/osx/xcode_version_flag.bzl b/tools/osx/xcode_version_flag.bzl
index 4b1e2aa..5f750e9 100644
--- a/tools/osx/xcode_version_flag.bzl
+++ b/tools/osx/xcode_version_flag.bzl
@@ -40,59 +40,49 @@
def _xcode_version_flag_impl(ctx):
"""A rule that allows select() to differentiate between Xcode versions."""
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
- return struct(providers = [
- config_common.FeatureFlagInfo(value = _strip_version(
- xcode_config.xcode_version(),
- )),
- ])
+ return config_common.FeatureFlagInfo(value = _strip_version(
+ xcode_config.xcode_version(),
+ ))
def _ios_sdk_version_flag_impl(ctx):
"""A rule that allows select() to select based on the iOS SDK version."""
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
- return struct(providers = [
- config_common.FeatureFlagInfo(value = _strip_version(
- xcode_config.sdk_version_for_platform(
- apple_common.platform.ios_device,
- ),
- )),
- ])
+ return config_common.FeatureFlagInfo(value = _strip_version(
+ xcode_config.sdk_version_for_platform(
+ apple_common.platform.ios_device,
+ ),
+ ))
def _tvos_sdk_version_flag_impl(ctx):
"""A rule that allows select() to select based on the tvOS SDK version."""
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
- return struct(providers = [
- config_common.FeatureFlagInfo(value = _strip_version(
- xcode_config.sdk_version_for_platform(
- apple_common.platform.tvos_device,
- ),
- )),
- ])
+ return config_common.FeatureFlagInfo(value = _strip_version(
+ xcode_config.sdk_version_for_platform(
+ apple_common.platform.tvos_device,
+ ),
+ ))
def _watchos_sdk_version_flag_impl(ctx):
"""A rule that allows select() to select based on the watchOS SDK version."""
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
- return struct(providers = [
- config_common.FeatureFlagInfo(value = _strip_version(
- xcode_config.sdk_version_for_platform(
- apple_common.platform.watchos_device,
- ),
- )),
- ])
+ return config_common.FeatureFlagInfo(value = _strip_version(
+ xcode_config.sdk_version_for_platform(
+ apple_common.platform.watchos_device,
+ ),
+ ))
def _macos_sdk_version_flag_impl(ctx):
"""A rule that allows select() to select based on the macOS SDK version."""
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
- return struct(providers = [
- config_common.FeatureFlagInfo(value = _strip_version(
- xcode_config.sdk_version_for_platform(
- apple_common.platform.macos,
- ),
- )),
- ])
+ return config_common.FeatureFlagInfo(value = _strip_version(
+ xcode_config.sdk_version_for_platform(
+ apple_common.platform.macos,
+ ),
+ ))
xcode_version_flag = rule(
implementation = _xcode_version_flag_impl,