|
| 1 | +commit c02b7724a5dcf85bb9c87bc06c1cd0504c0507f9 |
| 2 | +Author: David Sanderson < [email protected]> |
| 3 | +Date: Wed Jun 11 17:35:01 2025 -0400 |
| 4 | + |
| 5 | + use DefaultInfo in rules_java |
| 6 | + |
| 7 | + We here address the following obstacles in rules_java to using |
| 8 | + Bazel's --incompatible_disable_target_default_provider_fields flag: |
| 9 | + |
| 10 | + ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/toolchains/BUILD:359:27: in java_toolchain rule @@rules_java+//toolchains:toolchain_jdk_21: |
| 11 | + Traceback (most recent call last): |
| 12 | + File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/java_toolchain.bzl", line 100, column 45, in _java_toolchain_impl |
| 13 | + jacocorunner = ctx.attr.jacocorunner.files_to_run if ctx.attr.jacocorunner else None, |
| 14 | + Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details. |
| 15 | + ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/toolchains/BUILD:359:27: Analysis of target '@@rules_java+//toolchains:toolchain_jdk_21' failed |
| 16 | + ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed |
| 17 | + |
| 18 | + ERROR: /Users/dws/src/bazel-dws/third_party/BUILD:578:20: in java_import rule //third_party:netty_tcnative_checked_in: |
| 19 | + Traceback (most recent call last): |
| 20 | + File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/bazel/rules/bazel_java_import.bzl", line 25, column 34, in _proxy |
| 21 | + return bazel_java_import_rule( |
| 22 | + File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/impl/bazel_java_import_impl.bzl", line 132, column 35, in bazel_java_import_rule |
| 23 | + collected_jars = _collect_jars(ctx, jars) |
| 24 | + File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/impl/bazel_java_import_impl.bzl", line 38, column 24, in _collect_jars |
| 25 | + for jar in info.files.to_list(): |
| 26 | + Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details. |
| 27 | + ERROR: /Users/dws/src/bazel-dws/third_party/BUILD:578:20: Analysis of target '//third_party:netty_tcnative_checked_in' failed |
| 28 | + ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed |
| 29 | + |
| 30 | +diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl |
| 31 | +index 4465670..ce338cb 100644 |
| 32 | +--- a/java/common/rules/impl/bazel_java_import_impl.bzl |
| 33 | ++++ b/java/common/rules/impl/bazel_java_import_impl.bzl |
| 34 | +@@ -35,7 +35,7 @@ def _collect_jars(ctx, jars): |
| 35 | + for info in jars: |
| 36 | + if JavaInfo in info: |
| 37 | + fail("'jars' attribute cannot contain labels of Java targets") |
| 38 | +- for jar in info.files.to_list(): |
| 39 | ++ for jar in info[DefaultInfo].files.to_list(): |
| 40 | + jar_path = jar.dirname + jar.basename |
| 41 | + if jars_dict.get(jar_path) != None: |
| 42 | + fail("in jars attribute of java_import rule //" + ctx.label.package + ":" + ctx.attr.name + ": " + jar.basename + " is a duplicate") |
| 43 | +@@ -179,7 +179,7 @@ def bazel_java_import_rule( |
| 44 | + # TODO(kotlaja): Revise if collected_runtimes can be added into construct_defaultinfo directly. |
| 45 | + collected_runtimes = [] |
| 46 | + for runtime_dep in ctx.attr.runtime_deps: |
| 47 | +- collected_runtimes.extend(runtime_dep.files.to_list()) |
| 48 | ++ collected_runtimes.extend(runtime_dep[DefaultInfo].files.to_list()) |
| 49 | + |
| 50 | + target["DefaultInfo"] = construct_defaultinfo( |
| 51 | + ctx, |
| 52 | +diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl |
| 53 | +index 2e4fc67..fe32fc3 100644 |
| 54 | +--- a/java/common/rules/java_toolchain.bzl |
| 55 | ++++ b/java/common/rules/java_toolchain.bzl |
| 56 | +@@ -96,13 +96,13 @@ def _java_toolchain_impl(ctx): |
| 57 | + oneversion_allowlist = ctx.file.oneversion_allowlist if ctx.file.oneversion_allowlist else ctx.file.oneversion_whitelist |
| 58 | + java_toolchain_info = _new_javatoolchaininfo( |
| 59 | + bootclasspath = bootclasspath_info.bootclasspath, |
| 60 | +- ijar = ctx.attr.ijar.files_to_run if ctx.attr.ijar else None, |
| 61 | +- jacocorunner = ctx.attr.jacocorunner.files_to_run if ctx.attr.jacocorunner else None, |
| 62 | ++ ijar = ctx.attr.ijar[DefaultInfo].files_to_run if ctx.attr.ijar else None, |
| 63 | ++ jacocorunner = ctx.attr.jacocorunner[DefaultInfo].files_to_run if ctx.attr.jacocorunner else None, |
| 64 | + java_runtime = java_runtime, |
| 65 | + jvm_opt = depset(get_internal_java_common().expand_java_opts(ctx, "jvm_opts", tokenize = False, exec_paths = True)), |
| 66 | + label = ctx.label, |
| 67 | +- proguard_allowlister = ctx.attr.proguard_allowlister.files_to_run if ctx.attr.proguard_allowlister else None, |
| 68 | +- single_jar = ctx.attr.singlejar.files_to_run, |
| 69 | ++ proguard_allowlister = ctx.attr.proguard_allowlister[DefaultInfo].files_to_run if ctx.attr.proguard_allowlister else None, |
| 70 | ++ single_jar = ctx.attr.singlejar[DefaultInfo].files_to_run, |
| 71 | + source_version = ctx.attr.source_version, |
| 72 | + target_version = ctx.attr.target_version, |
| 73 | + tools = depset(ctx.files.tools), |
| 74 | +@@ -131,7 +131,7 @@ def _java_toolchain_impl(ctx): |
| 75 | + _javac_supports_worker_multiplex_sandboxing = ctx.attr.javac_supports_worker_multiplex_sandboxing, |
| 76 | + _jspecify_info = _get_jspecify_info(ctx), |
| 77 | + _local_java_optimization_config = ctx.files._local_java_optimization_configuration, |
| 78 | +- _one_version_tool = ctx.attr.oneversion.files_to_run if ctx.attr.oneversion else None, |
| 79 | ++ _one_version_tool = ctx.attr.oneversion[DefaultInfo].files_to_run if ctx.attr.oneversion else None, |
| 80 | + _one_version_allowlist = oneversion_allowlist, |
| 81 | + _one_version_allowlist_for_tests = ctx.file.oneversion_allowlist_for_tests, |
| 82 | + _package_configuration = [dep[JavaPackageConfigurationInfo] for dep in ctx.attr.package_configuration], |
| 83 | +@@ -171,7 +171,7 @@ def _get_javac_opts(ctx): |
| 84 | + def _get_android_lint_tool(ctx): |
| 85 | + if not ctx.attr.android_lint_runner: |
| 86 | + return None |
| 87 | +- files_to_run = ctx.attr.android_lint_runner.files_to_run |
| 88 | ++ files_to_run = ctx.attr.android_lint_runner[DefaultInfo].files_to_run |
| 89 | + if not files_to_run or not files_to_run.executable: |
| 90 | + fail(ctx.attr.android_lint_runner.label, "does not refer to a valid executable target") |
| 91 | + return struct( |
| 92 | +@@ -186,7 +186,7 @@ def _get_tool_from_ctx(ctx, tool_attr, data_attr, opts_attr): |
| 93 | + dep = getattr(ctx.attr, tool_attr) |
| 94 | + if not dep: |
| 95 | + return None |
| 96 | +- files_to_run = dep.files_to_run |
| 97 | ++ files_to_run = dep[DefaultInfo].files_to_run |
| 98 | + if not files_to_run or not files_to_run.executable: |
| 99 | + fail(dep.label, "does not refer to a valid executable target") |
| 100 | + data = getattr(ctx.attr, data_attr) |
| 101 | +@@ -200,7 +200,7 @@ def _get_tool_from_executable(ctx, attr_name, data = [], jvm_opts = []): |
| 102 | + dep = getattr(ctx.attr, attr_name) |
| 103 | + if not dep: |
| 104 | + return None |
| 105 | +- files_to_run = dep.files_to_run |
| 106 | ++ files_to_run = dep[DefaultInfo].files_to_run |
| 107 | + if not files_to_run or not files_to_run.executable: |
| 108 | + fail(dep.label, "does not refer to a valid executable target") |
| 109 | + return struct(tool = files_to_run, data = depset(data), jvm_opts = depset(jvm_opts)) |
0 commit comments