Skip to content

Commit

Permalink
fix: make versioned rules return both builtin and rules_python provid…
Browse files Browse the repository at this point in the history
…ers (bazelbuild#2116)

This makes the versioned rules return both the `@builtin` and
`@rules_python` provider
objects. This makes the versioned rules more compatible with the
non-versioned rules.

Fixes bazelbuild#2114
  • Loading branch information
rickeylev authored Aug 11, 2024
1 parent 3b183bf commit 825acde
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 9 additions & 19 deletions python/config_settings/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions tests/config_settings/transition/multi_version_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 825acde

Please sign in to comment.