Skip to content

Commit 779623c

Browse files
authored
chore: make builtin build_python_zip flag optional for tests (bazel 10 compatibility) (#3507)
Starting in bazel 10, the build_python_zip flag is removed. This means using the flag in e.g. transitions no longer works, which breaks some of the tests that set the flag for testing. To fix, don't set the flags or add them to transitions when running under bazel 10. Fixes #3496
1 parent c6acbfc commit 779623c

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

python/private/internal_config_repo.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config = struct(
3535
enable_deprecation_warnings = {enable_deprecation_warnings},
3636
bazel_8_or_later = {bazel_8_or_later},
3737
bazel_9_or_later = {bazel_9_or_later},
38+
bazel_10_or_later = {bazel_10_or_later},
3839
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
3940
BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}),
4041
BuiltinPyCcLinkParamsProvider = getattr(getattr(native, "legacy_globals", None), "PyCcLinkParamsProvider", {builtin_py_cc_link_params_provider}),
@@ -124,6 +125,7 @@ def _internal_config_repo_impl(rctx):
124125
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
125126
bazel_8_or_later = str(bazel_major_version >= 8),
126127
bazel_9_or_later = str(bazel_major_version >= 9),
128+
bazel_10_or_later = str(bazel_major_version > 9),
127129
))
128130

129131
shim_content = _PY_INTERNAL_SHIM

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") # buildifier: di
2626
load("//tests/base_rules:base_tests.bzl", "create_base_tests")
2727
load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util")
2828
load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject")
29-
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP")
29+
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "maybe_builtin_build_python_zip")
3030
load("//tests/support/platforms:platforms.bzl", "platform_targets")
3131

3232
_tests = []
@@ -49,14 +49,13 @@ def _test_basic_windows(name, config):
4949
# platforms.
5050
# Pass value to both native and starlark versions of the flag until
5151
# the native one is removed.
52-
"//command_line_option:build_python_zip": "true",
5352
labels.BUILD_PYTHON_ZIP: True,
5453
"//command_line_option:cpu": "windows_x86_64",
5554
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
5655
"//command_line_option:extra_execution_platforms": [platform_targets.WINDOWS_X86_64],
5756
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
5857
"//command_line_option:platforms": [platform_targets.WINDOWS_X86_64],
59-
},
58+
} | maybe_builtin_build_python_zip("true"),
6059
attr_values = {},
6160
)
6261

@@ -95,14 +94,13 @@ def _test_basic_zip(name, config):
9594
# platforms.
9695
# Pass value to both native and starlark versions of the flag until
9796
# the native one is removed.
98-
"//command_line_option:build_python_zip": "true",
9997
labels.BUILD_PYTHON_ZIP: True,
10098
"//command_line_option:cpu": "linux_x86_64",
10199
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
102100
"//command_line_option:extra_execution_platforms": [platform_targets.LINUX_X86_64],
103101
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
104102
"//command_line_option:platforms": [platform_targets.LINUX_X86_64],
105-
},
103+
} | maybe_builtin_build_python_zip("true"),
106104
attr_values = {"target_compatible_with": target_compatible_with},
107105
)
108106

tests/config_settings/transition/multi_version_tests.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ load("//python:py_info.bzl", "PyInfo")
2222
load("//python:py_test.bzl", "py_test")
2323
load("//python/private:common_labels.bzl", "labels") # buildifier: disable=bzl-visibility
2424
load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility
25-
load("//tests/support:support.bzl", "CC_TOOLCHAIN")
25+
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "maybe_builtin_build_python_zip")
2626
load("//tests/support/platforms:platforms.bzl", "platform_targets")
2727

2828
# NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel
@@ -92,11 +92,10 @@ def _setup_py_binary_windows(name, *, impl, build_python_zip):
9292
target = name + "_subject",
9393
impl = impl,
9494
config_settings = {
95-
"//command_line_option:build_python_zip": str(build_python_zip),
9695
labels.BUILD_PYTHON_ZIP: build_python_zip,
9796
"//command_line_option:extra_toolchains": CC_TOOLCHAIN,
9897
"//command_line_option:platforms": str(platform_targets.WINDOWS_X86_64),
99-
},
98+
} | maybe_builtin_build_python_zip(str(build_python_zip)),
10099
)
101100

102101
def _test_py_binary_windows_build_python_zip_false(name):

tests/support/py_reconfig.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def _perform_transition_impl(input_settings, attr, base_impl):
3131
settings.update(base_impl(input_settings, attr))
3232

3333
settings[labels.VISIBLE_FOR_TESTING] = True
34-
settings["//command_line_option:build_python_zip"] = str(attr.build_python_zip)
34+
35+
if _BUILTIN_BUILD_PYTHON_ZIP:
36+
settings["//command_line_option:build_python_zip"] = str(attr.build_python_zip)
3537
settings[labels.BUILD_PYTHON_ZIP] = attr.build_python_zip
3638
if attr.bootstrap_impl:
3739
settings[labels.BOOTSTRAP_IMPL] = attr.bootstrap_impl
@@ -49,6 +51,10 @@ def _perform_transition_impl(input_settings, attr, base_impl):
4951
settings[str(key)] = value
5052
return settings
5153

54+
_BUILTIN_BUILD_PYTHON_ZIP = [] if config.bazel_10_or_later else [
55+
"//command_line_option:build_python_zip",
56+
]
57+
5258
_RECONFIG_INPUTS = [
5359
"//command_line_option:extra_toolchains",
5460
CUSTOM_RUNTIME,
@@ -59,10 +65,9 @@ _RECONFIG_INPUTS = [
5965
labels.VENVS_USE_DECLARE_SYMLINK,
6066
]
6167
_RECONFIG_OUTPUTS = _RECONFIG_INPUTS + [
62-
"//command_line_option:build_python_zip",
6368
labels.BUILD_PYTHON_ZIP,
6469
labels.VISIBLE_FOR_TESTING,
65-
]
70+
] + _BUILTIN_BUILD_PYTHON_ZIP
6671
_RECONFIG_INHERITED_OUTPUTS = [v for v in _RECONFIG_OUTPUTS if v in _RECONFIG_INPUTS]
6772

6873
_RECONFIG_ATTRS = {

tests/support/support.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# rules_testing or as config_setting values, which don't support Label in some
2020
# places.
2121

22+
load("@rules_python_internal//:rules_python_config.bzl", "config")
2223
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
2324

2425
PY_TOOLCHAINS = str(Label("//tests/support/py_toolchains:all"))
@@ -43,3 +44,10 @@ NOT_WINDOWS = select({
4344
"@platforms//os:windows": ["@platforms//:incompatible"],
4445
"//conditions:default": [],
4546
})
47+
48+
def maybe_builtin_build_python_zip(value):
49+
settings = {}
50+
if not config.bazel_10_or_later:
51+
settings["//command_line_option:build_python_zip"] = value
52+
53+
return settings

0 commit comments

Comments
 (0)