Skip to content

Commit 2393c5a

Browse files
committed
use rules_python_internal to get globals; fix a couple missed spots
1 parent 060d87e commit 2393c5a

File tree

7 files changed

+36
-19
lines changed

7 files changed

+36
-19
lines changed

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ load("//:internal_deps.bzl", "rules_python_internal_deps")
2121

2222
rules_python_internal_deps()
2323

24-
load("//python:repositories_deps.bzl", "py_repositories_deps")
25-
26-
py_repositories_deps()
24+
##load("//python:repositories_deps.bzl", "py_repositories_deps")
25+
##
26+
##py_repositories_deps()
2727

2828
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
2929

python/private/common/py_runtime_rule.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _py_runtime_impl(ctx):
132132
runfiles = runfiles,
133133
),
134134
]
135-
if BuiltinPyRuntimeInfo != None:
135+
if BuiltinPyRuntimeInfo != None and BuiltinPyRuntimeInfo != PyRuntimeInfo:
136136
# Return the builtin provider for better compatibility.
137137
# 1. There is a legacy code path in py_binary that
138138
# checks for the provider when toolchains aren't used

python/private/internal_config_repo.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ _ENABLE_PYSTAR_DEFAULT = "1"
2424
_CONFIG_TEMPLATE = """\
2525
config = struct(
2626
enable_pystar = {enable_pystar},
27+
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
28+
BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}),
29+
BuiltinPyCcLinkParamsProvider = getattr(getattr(native, "legacy_globals", None), "PyCcLinkParamsProvider", {builtin_py_cc_link_params_provider}),
2730
)
2831
"""
2932

@@ -65,8 +68,20 @@ def _internal_config_repo_impl(rctx):
6568
else:
6669
enable_pystar = False
6770

71+
if native.bazel_version.startswith("8."):
72+
builtin_py_info_symbol = "None"
73+
builtin_py_runtime_info_symbol = "None"
74+
builtin_py_cc_link_params_provider = "None"
75+
else:
76+
builtin_py_info_symbol = "PyInfo"
77+
builtin_py_runtime_info_symbol = "PyRuntimeInfo"
78+
builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider"
79+
6880
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
6981
enable_pystar = enable_pystar,
82+
builtin_py_info_symbol = builtin_py_info_symbol,
83+
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
84+
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
7085
))
7186

7287
if enable_pystar:

python/private/py_info.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ This field is currently unused in Bazel and may go away in the future.
118118
)
119119

120120
# The "effective" PyInfo is what the canonical //python:py_info.bzl%PyInfo symbol refers to
121-
_EffectivePyInfo = PyInfo if config.enable_pystar or BuiltinPyInfo == None else BuiltinPyInfo
121+
_EffectivePyInfo = PyInfo if (config.enable_pystar or BuiltinPyInfo == None) else BuiltinPyInfo
122122

123123
def PyInfoBuilder():
124124
# buildifier: disable=uninitialized

python/private/reexports.bzl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ inaccessible. So instead we access the builtin here and export it under a
3030
different name. Then we can load it from elsewhere.
3131
"""
3232

33-
load("@bazel_features//:features.bzl", "bazel_features")
33+
load("@rules_python_internal//:rules_python_config.bzl", "config")
3434

35-
# Don't use underscore prefix, since that would make the symbol local to this
36-
# file only. Use a non-conventional name to emphasize that this is not a public
37-
# symbol.
35+
# NOTE: May be None (Bazel 8 autoloading rules_python)
3836
# buildifier: disable=name-conventions
39-
BuiltinPyInfo = getattr(bazel_features.globals, "PyInfo", None)
37+
BuiltinPyInfo = config.BuiltinPyInfo
4038

39+
# NOTE: May be None (Bazel 8 autoloading rules_python)
4140
# buildifier: disable=name-conventions
42-
BuiltinPyRuntimeInfo = getattr(bazel_features.globals, "PyRuntimeInfo", None)
41+
BuiltinPyRuntimeInfo = config.BuiltinPyRuntimeInfo

python/py_cc_link_params_info.bzl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Public entry point for PyCcLinkParamsInfo."""
22

3-
load("@bazel_features//:features.bzl", "bazel_features")
43
load("@rules_python_internal//:rules_python_config.bzl", "config")
54
load("//python/private/common:providers.bzl", _starlark_PyCcLinkParamsProvider = "PyCcLinkParamsProvider")
65

7-
_PyCcLinkParamsProvider = getattr(bazel_features.globals, "PyCcLinkParamsProvider", None) # buildifier: disable=name-conventions
8-
PyCcLinkParamsInfo = _starlark_PyCcLinkParamsProvider if config.enable_pystar or _PyCcLinkParamsProvider == None else PyCcLinkParamsProvider
6+
PyCcLinkParamsInfo = (
7+
_starlark_PyCcLinkParamsProvider if (
8+
config.enable_pystar or config.BuiltinPyCcLinkParamsProvider == None
9+
) else config.BuiltinPyCcLinkParamsProvider
10+
)
11+
print(native.legacy_globals)

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1919
load("@rules_testing//lib:truth.bzl", "matching")
2020
load("@rules_testing//lib:util.bzl", rt_util = "util")
2121
load("//python:py_executable_info.bzl", "PyExecutableInfo")
22+
load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo")
2223
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2324
load("//tests/base_rules:base_tests.bzl", "create_base_tests")
2425
load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util")
2526
load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject")
2627
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "WINDOWS_X86_64")
2728

28-
_BuiltinPyRuntimeInfo = PyRuntimeInfo
29-
3029
_tests = []
3130

3231
def _test_basic_windows(name, config):
@@ -359,9 +358,10 @@ def _test_py_runtime_info_provided_impl(env, target):
359358
# Make sure that the rules_python loaded symbol is provided.
360359
env.expect.that_target(target).has_provider(RulesPythonPyRuntimeInfo)
361360

362-
# For compatibility during the transition, the builtin PyRuntimeInfo should
363-
# also be provided.
364-
env.expect.that_target(target).has_provider(_BuiltinPyRuntimeInfo)
361+
if BuiltinPyRuntimeInfo != None:
362+
# For compatibility during the transition, the builtin PyRuntimeInfo should
363+
# also be provided.
364+
env.expect.that_target(target).has_provider(BuiltinPyRuntimeInfo)
365365

366366
_tests.append(_test_py_runtime_info_provided)
367367

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy