Skip to content

Commit 135c118

Browse files
committed
refactor: remove is_bazel_6_or_higher
1 parent 00a912f commit 135c118

12 files changed

Lines changed: 20 additions & 135 deletions

python/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,14 @@ bzl_library(
184184
srcs = ["py_runtime.bzl"],
185185
deps = [
186186
"//python/private:py_runtime_macro_bzl",
187-
"//python/private:util_bzl",
188187
],
189188
)
190189

191190
bzl_library(
192191
name = "py_runtime_pair_bzl",
193192
srcs = ["py_runtime_pair.bzl"],
194193
deps = [
195-
"//python/private:bazel_tools_bzl",
196194
"//python/private:py_runtime_pair_macro_bzl",
197-
"//python/private:util_bzl",
198195
],
199196
)
200197

python/private/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ bzl_library(
440440
deps = [
441441
":builders_bzl",
442442
":reexports_bzl",
443-
":util_bzl",
444443
],
445444
)
446445

@@ -505,7 +504,6 @@ bzl_library(
505504
bzl_library(
506505
name = "py_runtime_info_bzl",
507506
srcs = ["py_runtime_info.bzl"],
508-
deps = [":util_bzl"],
509507
)
510508

511509
bzl_library(

python/private/py_cc_link_params_info.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
"""Providers for Python rules."""
1515

1616
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
17-
load(":util.bzl", "define_bazel_6_provider")
1817

1918
def _PyCcLinkParamsInfo_init(cc_info):
2019
return {
2120
"cc_info": CcInfo(linking_context = cc_info.linking_context),
2221
}
2322

2423
# buildifier: disable=name-conventions
25-
PyCcLinkParamsInfo, _unused_raw_py_cc_link_params_provider_ctor = define_bazel_6_provider(
24+
PyCcLinkParamsInfo, _unused_raw_py_cc_link_params_provider_ctor = provider(
2625
doc = ("Python-wrapper to forward {obj}`CcInfo.linking_context`. This is to " +
2726
"allow Python targets to propagate C++ linking information, but " +
2827
"without the Python target appearing to be a valid C++ rule dependency"),

python/private/py_info.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
load(":builders.bzl", "builders")
1717
load(":reexports.bzl", "BuiltinPyInfo")
18-
load(":util.bzl", "define_bazel_6_provider")
1918

2019
def _VenvSymlinkKind_typedef():
2120
"""An enum of types of venv directories.
@@ -159,7 +158,7 @@ def _PyInfo_init(
159158
"venv_symlinks": venv_symlinks,
160159
}
161160

162-
PyInfo, _unused_raw_py_info_ctor = define_bazel_6_provider(
161+
PyInfo, _unused_raw_py_info_ctor = provider(
163162
doc = """Encapsulates information provided by the Python rules.
164163
165164
Instead of creating this object directly, use {obj}`PyInfoBuilder` and

python/private/py_runtime_info.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414
"""Providers for Python rules."""
1515

16-
load(":util.bzl", "define_bazel_6_provider")
17-
1816
DEFAULT_STUB_SHEBANG = "#!/usr/bin/env python3"
1917

2018
_PYTHON_VERSION_VALUES = ["PY2", "PY3"]
@@ -124,7 +122,7 @@ def _PyRuntimeInfo_init(
124122
"zip_main_template": zip_main_template,
125123
}
126124

127-
PyRuntimeInfo, _unused_raw_py_runtime_info_ctor = define_bazel_6_provider(
125+
PyRuntimeInfo, _unused_raw_py_runtime_info_ctor = provider(
128126
doc = """Contains information about a Python runtime, as returned by the `py_runtime`
129127
rule.
130128

python/private/util.bzl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,10 @@ def add_tag(attrs, tag):
7070
else:
7171
attrs["tags"] = [tag]
7272

73-
# Helper to make the provider definitions not crash under Bazel 5.4:
74-
# Bazel 5.4 doesn't support the `init` arg of `provider()`, so we have to
75-
# not pass that when using Bazel 5.4. But, not passing the `init` arg
76-
# changes the return value from a two-tuple to a single value, which then
77-
# breaks Bazel 6+ code.
78-
# This isn't actually used under Bazel 5.4, so just stub out the values
79-
# to get past the loading phase.
80-
def define_bazel_6_provider(doc, fields, **kwargs):
81-
"""Define a provider, or a stub for pre-Bazel 7."""
82-
if not IS_BAZEL_6_OR_HIGHER:
83-
return provider("Stub, not used", fields = []), None
84-
return provider(doc = doc, fields = fields, **kwargs)
85-
8673
IS_BAZEL_7_4_OR_HIGHER = hasattr(native, "legacy_globals")
8774

8875
IS_BAZEL_7_OR_HIGHER = hasattr(native, "starlark_doc_extract")
8976

90-
# Bazel 5.4 has a bug where every access of testing.ExecutionInfo is a
91-
# different object that isn't equal to any other. This is fixed in bazel 6+.
92-
IS_BAZEL_6_OR_HIGHER = testing.ExecutionInfo == testing.ExecutionInfo
93-
9477
_marker_rule_to_detect_bazel_6_4_or_higher = rule(implementation = lambda ctx: None)
9578

9679
# Bazel 6.4 and higher have a bug fix where rule names show up in the str()

python/py_runtime.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
"""Public entry point for py_runtime."""
1616

1717
load("//python/private:py_runtime_macro.bzl", _starlark_py_runtime = "py_runtime")
18-
load("//python/private:util.bzl", "IS_BAZEL_6_OR_HIGHER")
1918

2019
# buildifier: disable=native-python
21-
_py_runtime_impl = _starlark_py_runtime if IS_BAZEL_6_OR_HIGHER else native.py_runtime
20+
_py_runtime_impl = _starlark_py_runtime
2221

2322
def py_runtime(**attrs):
2423
"""Creates an executable Python program.

python/py_runtime_pair.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
"""Public entry point for py_runtime_pair."""
1616

17-
load("@bazel_tools//tools/python:toolchain.bzl", _bazel_tools_impl = "py_runtime_pair")
1817
load("//python/private:py_runtime_pair_macro.bzl", _starlark_impl = "py_runtime_pair")
19-
load("//python/private:util.bzl", "IS_BAZEL_6_OR_HIGHER")
2018

21-
_py_runtime_pair = _starlark_impl if IS_BAZEL_6_OR_HIGHER else _bazel_tools_impl
19+
_py_runtime_pair = _starlark_impl
2220

2321
# NOTE: This doc is copy/pasted from the builtin py_runtime_pair rule so our
2422
# doc generator gives useful API docs.

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ def _test_default_main_can_have_multiple_path_segments_impl(env, target):
179179
)
180180

181181
def _test_default_main_must_be_in_srcs(name, config):
182-
# Bazel 5 will crash with a Java stacktrace when the native Python
183-
# rules have an error.
184-
if not pt_util.is_bazel_6_or_higher():
185-
rt_util.skip_test(name = name)
186-
return
187182
rt_util.helper_target(
188183
config.rule,
189184
name = name + "_subject",
@@ -204,11 +199,6 @@ def _test_default_main_must_be_in_srcs_impl(env, target):
204199
)
205200

206201
def _test_default_main_cannot_be_ambiguous(name, config):
207-
# Bazel 5 will crash with a Java stacktrace when the native Python
208-
# rules have an error.
209-
if not pt_util.is_bazel_6_or_higher():
210-
rt_util.skip_test(name = name)
211-
return
212202
rt_util.helper_target(
213203
config.rule,
214204
name = name + "_subject",
@@ -251,11 +241,6 @@ def _test_explicit_main_impl(env, target):
251241
)
252242

253243
def _test_explicit_main_cannot_be_ambiguous(name, config):
254-
# Bazel 5 will crash with a Java stacktrace when the native Python
255-
# rules have an error.
256-
if not pt_util.is_bazel_6_or_higher():
257-
rt_util.skip_test(name = name)
258-
return
259244
rt_util.helper_target(
260245
config.rule,
261246
name = name + "_subject",
@@ -312,11 +297,6 @@ def _test_files_to_build_impl(env, target):
312297
env.expect.that_file(first_default_output).equals(executable)
313298

314299
def _test_name_cannot_end_in_py(name, config):
315-
# Bazel 5 will crash with a Java stacktrace when the native Python
316-
# rules have an error.
317-
if not pt_util.is_bazel_6_or_higher():
318-
rt_util.skip_test(name = name)
319-
return
320300
rt_util.helper_target(
321301
config.rule,
322302
name = name + "_subject.py",

tests/base_rules/py_test/py_test_tests.bzl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ _SKIP_WINDOWS = {
3939
_tests = []
4040

4141
def _test_mac_requires_darwin_for_execution(name, config):
42-
# Bazel 5.4 has a bug where every access of testing.ExecutionInfo is
43-
# a different object that isn't equal to any other, which prevents
44-
# rules_testing from detecting it properly and fails with an error.
45-
# This is fixed in Bazel 6+.
46-
if not pt_util.is_bazel_6_or_higher():
47-
rt_util.skip_test(name = name)
48-
return
49-
5042
rt_util.helper_target(
5143
config.rule,
5244
name = name + "_subject",
@@ -74,13 +66,6 @@ def _test_mac_requires_darwin_for_execution_impl(env, target):
7466
_tests.append(_test_mac_requires_darwin_for_execution)
7567

7668
def _test_non_mac_doesnt_require_darwin_for_execution(name, config):
77-
# Bazel 5.4 has a bug where every access of testing.ExecutionInfo is
78-
# a different object that isn't equal to any other, which prevents
79-
# rules_testing from detecting it properly and fails with an error.
80-
# This is fixed in Bazel 6+.
81-
if not pt_util.is_bazel_6_or_higher():
82-
rt_util.skip_test(name = name)
83-
return
8469
rt_util.helper_target(
8570
config.rule,
8671
name = name + "_subject",

0 commit comments

Comments
 (0)