Remove toolchain resolution logic from find_java_toolchain helper and put it exclusively in the implementation of the toolchain alias rules. This is similar to the removal of the toolchain resolution logic from the native rules in https://github.com/bazelbuild/bazel/commit/24bbdb518d70143eb8575f9e9cb61545e935d8cf. The indirection through the aliases is necessary to force a host configuration transition for the host runtime alias. PiperOrigin-RevId: 235721677
diff --git a/tools/jdk/java_toolchain_alias.bzl b/tools/jdk/java_toolchain_alias.bzl index 630fa4f..e581c63 100644 --- a/tools/jdk/java_toolchain_alias.bzl +++ b/tools/jdk/java_toolchain_alias.bzl
@@ -26,7 +26,10 @@ def _java_runtime_alias(ctx): """An experimental implementation of java_runtime_alias using toolchain resolution.""" - toolchain = find_java_runtime_toolchain(ctx, target = ctx.attr._java_runtime) + if java_common.is_java_toolchain_resolution_enabled_do_not_use(ctx = ctx): + toolchain = ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"] + else: + toolchain = ctx.attr._java_runtime[java_common.JavaRuntimeInfo] return [ toolchain, platform_common.TemplateVariableInfo({ @@ -75,7 +78,10 @@ def _java_toolchain_alias(ctx): """An experimental implementation of java_toolchain_alias using toolchain resolution.""" - toolchain = find_java_toolchain(ctx, target = ctx.attr._java_toolchain) + if java_common.is_java_toolchain_resolution_enabled_do_not_use(ctx = ctx): + toolchain = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"] + else: + toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo] return struct( providers = [toolchain], # Use the legacy provider syntax for compatibility with the native rules.
diff --git a/tools/jdk/toolchain_utils.bzl b/tools/jdk/toolchain_utils.bzl index adcc266..fd7482a 100644 --- a/tools/jdk/toolchain_utils.bzl +++ b/tools/jdk/toolchain_utils.bzl
@@ -34,8 +34,7 @@ A JavaToolchainInfo. """ - if java_common.is_java_toolchain_resolution_enabled_do_not_use(ctx = ctx): - return ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"] + _ignore = [ctx] return target[java_common.JavaToolchainInfo] @@ -54,7 +53,6 @@ A JavaRuntimeInfo. """ - if java_common.is_java_toolchain_resolution_enabled_do_not_use(ctx = ctx): - return ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"] + _ignore = [ctx] return target[java_common.JavaRuntimeInfo]