diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f11f7d2cc..a1ff57277a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,9 @@ A brief description of the categories of changes: * (rules) User dependencies come before runtime site-packages when using {obj}`--bootstrap_impl=script`. ([#2064](https://github.com/bazelbuild/rules_python/issues/2064)). +* (rules) Version-aware rules now return both `@_builtins` and `@rules_python` + providers instead of only one. + ([#2114](https://github.com/bazelbuild/rules_python/issues/2114)). * (pip) Fixed pypi parse_simpleapi_html function for feeds with package metadata containing ">" sign * (toolchains) Added missing executable permission to diff --git a/python/config_settings/transition.bzl b/python/config_settings/transition.bzl index da48a1fdb3..7ac41f881f 100644 --- a/python/config_settings/transition.bzl +++ b/python/config_settings/transition.bzl @@ -81,31 +81,12 @@ def _transition_py_impl(ctx): for k, v in ctx.attr.env.items(): env[k] = ctx.expand_location(v) - if PyInfo in target: - py_info = target[PyInfo] - elif BuiltinPyInfo in target: - py_info = target[BuiltinPyInfo] - else: - fail("target {} does not have rules_python PyInfo or builtin PyInfo".format(target)) - - if PyRuntimeInfo in target: - py_runtime_info = target[PyRuntimeInfo] - elif BuiltinPyRuntimeInfo in target: - py_runtime_info = target[BuiltinPyRuntimeInfo] - else: - fail( - "target {} does not have rules_python PyRuntimeInfo or builtin PyRuntimeInfo. ".format(target) + - "There is likely no toolchain being matched to your configuration, use --toolchain_resolution_debug parameter to get more information", - ) - providers = [ DefaultInfo( executable = executable, files = depset(default_outputs, transitive = [target[DefaultInfo].files]), runfiles = ctx.runfiles(default_outputs).merge(target[DefaultInfo].default_runfiles), ), - py_info, - py_runtime_info, # Ensure that the binary we're wrapping is included in code coverage. coverage_common.instrumented_files_info( ctx, @@ -118,6 +99,15 @@ def _transition_py_impl(ctx): # https://github.com/bazelbuild/bazel/commit/dbdfa07e92f99497be9c14265611ad2920161483 testing.TestEnvironment(env), ] + if PyInfo in target: + providers.append(target[PyInfo]) + if BuiltinPyInfo in target and PyInfo != BuiltinPyInfo: + providers.append(target[BuiltinPyInfo]) + + if PyRuntimeInfo in target: + providers.append(target[PyRuntimeInfo]) + if BuiltinPyRuntimeInfo in target and PyRuntimeInfo != BuiltinPyRuntimeInfo: + providers.append(target[BuiltinPyRuntimeInfo]) return providers _COMMON_ATTRS = { diff --git a/tests/config_settings/transition/multi_version_tests.bzl b/tests/config_settings/transition/multi_version_tests.bzl index e35590bbb6..6659da574c 100644 --- a/tests/config_settings/transition/multi_version_tests.bzl +++ b/tests/config_settings/transition/multi_version_tests.bzl @@ -16,7 +16,9 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:test_suite.bzl", "test_suite") load("@rules_testing//lib:util.bzl", "TestingAspectInfo", rt_util = "util") +load("//python:py_info.bzl", "PyInfo") load("//python/config_settings:transition.bzl", py_binary_transitioned = "py_binary", py_test_transitioned = "py_test") +load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility # NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel @@ -45,7 +47,8 @@ def _test_py_test_with_transition(name): def _test_py_test_with_transition_impl(env, target): # Nothing to assert; we just want to make sure it builds - _ = env, target # @unused + env.expect.that_target(target).has_provider(PyInfo) + env.expect.that_target(target).has_provider(BuiltinPyInfo) _tests.append(_test_py_test_with_transition) @@ -65,7 +68,8 @@ def _test_py_binary_with_transition(name): def _test_py_binary_with_transition_impl(env, target): # Nothing to assert; we just want to make sure it builds - _ = env, target # @unused + env.expect.that_target(target).has_provider(PyInfo) + env.expect.that_target(target).has_provider(BuiltinPyInfo) _tests.append(_test_py_binary_with_transition)