Skip to content

Commit 36e8c81

Browse files
authored
cleanup(pystar): inline @bazel_tools and @platforms references (#1531)
The location of the `@bazel_tools` and `@platforms` repositories were originally part of the semantics.bzl config because performing rewrites on the code as part of the Bazel code export process was too difficult. With the direction being reversed (imported instead of exported), and the scope of the codebase being reduced (just rules_python instead of the entire Bazel codebase), it's easier to perform copybara rewrites. In particular, the `"//` strings are problematic to rewrite because they look like intra-repo references instead of parts of a larger expression.
1 parent 4e26bcd commit 36e8c81

File tree

8 files changed

+17
-29
lines changed

8 files changed

+17
-29
lines changed

python/private/common/attributes.bzl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ load(":py_internal.bzl", "py_internal")
1919
load(
2020
":semantics.bzl",
2121
"DEPS_ATTR_ALLOW_RULES",
22-
"PLATFORMS_LOCATION",
2322
"SRCS_ATTR_ALLOW_FILES",
24-
"TOOLS_REPO",
2523
)
2624

2725
# TODO: Load CcInfo from rules_cc
@@ -72,7 +70,7 @@ def copy_common_test_kwargs(kwargs):
7270
CC_TOOLCHAIN = {
7371
# NOTE: The `cc_helper.find_cpp_toolchain()` function expects the attribute
7472
# name to be this name.
75-
"_cc_toolchain": attr.label(default = "@" + TOOLS_REPO + "//tools/cpp:current_cc_toolchain"),
73+
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
7674
}
7775

7876
# The common "data" attribute definition.
@@ -188,11 +186,11 @@ environment when the test is executed by bazel test.
188186
# TODO(b/176993122): Remove when Bazel automatically knows to run on darwin.
189187
"_apple_constraints": attr.label_list(
190188
default = [
191-
PLATFORMS_LOCATION + "/os:ios",
192-
PLATFORMS_LOCATION + "/os:macos",
193-
PLATFORMS_LOCATION + "/os:tvos",
194-
PLATFORMS_LOCATION + "/os:visionos",
195-
PLATFORMS_LOCATION + "/os:watchos",
189+
"@platforms//os:ios",
190+
"@platforms//os:macos",
191+
"@platforms//os:tvos",
192+
"@platforms//os:visionos",
193+
"@platforms//os:watchos",
196194
],
197195
),
198196
},

python/private/common/common.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ load(
2020
":semantics.bzl",
2121
"NATIVE_RULES_MIGRATION_FIX_CMD",
2222
"NATIVE_RULES_MIGRATION_HELP_URL",
23-
"TOOLS_REPO",
2423
)
2524

2625
_testing = testing
@@ -29,7 +28,7 @@ _coverage_common = coverage_common
2928
_py_builtins = py_internal
3029
PackageSpecificationInfo = getattr(py_internal, "PackageSpecificationInfo", None)
3130

32-
TOOLCHAIN_TYPE = "@" + TOOLS_REPO + "//tools/python:toolchain_type"
31+
TOOLCHAIN_TYPE = "@bazel_tools//tools/python:toolchain_type"
3332

3433
# Extensions without the dot
3534
_PYTHON_SOURCE_EXTENSIONS = ["py"]

python/private/common/providers.bzl

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

1616
load("@rules_python_internal//:rules_python_config.bzl", "config")
17-
load(":semantics.bzl", "TOOLS_REPO")
1817

1918
# TODO: load CcInfo from rules_cc
2019
_CcInfo = CcInfo
2120

2221
DEFAULT_STUB_SHEBANG = "#!/usr/bin/env python3"
2322

24-
DEFAULT_BOOTSTRAP_TEMPLATE = "@" + TOOLS_REPO + "//tools/python:python_bootstrap_template.txt"
23+
DEFAULT_BOOTSTRAP_TEMPLATE = "@bazel_tools//tools/python:python_bootstrap_template.txt"
2524
_PYTHON_VERSION_VALUES = ["PY2", "PY3"]
2625

2726
# Helper to make the provider definitions not crash under Bazel 5.4:

python/private/common/py_binary_rule_bazel.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ load(
2020
"create_executable_rule",
2121
"py_executable_bazel_impl",
2222
)
23-
load(":semantics.bzl", "TOOLS_REPO")
2423

2524
_PY_TEST_ATTRS = {
2625
"_collect_cc_coverage": attr.label(
27-
default = "@" + TOOLS_REPO + "//tools/test:collect_cc_coverage",
26+
default = "@bazel_tools//tools/test:collect_cc_coverage",
2827
executable = True,
2928
cfg = "exec",
3029
),

python/private/common/py_executable.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ load(
4949
"ALLOWED_MAIN_EXTENSIONS",
5050
"BUILD_DATA_SYMLINK_PATH",
5151
"IS_BAZEL",
52-
"PLATFORMS_LOCATION",
5352
"PY_RUNTIME_ATTR_NAME",
54-
"TOOLS_REPO",
5553
)
5654

5755
# TODO: Load cc_common from rules_cc
@@ -61,7 +59,7 @@ _py_builtins = py_internal
6159

6260
# Bazel 5.4 doesn't have config_common.toolchain_type
6361
_CC_TOOLCHAINS = [config_common.toolchain_type(
64-
"@" + TOOLS_REPO + "//tools/cpp:toolchain_type",
62+
"@bazel_tools//tools/cpp:toolchain_type",
6563
mandatory = False,
6664
)] if hasattr(config_common, "toolchain_type") else []
6765

@@ -97,7 +95,7 @@ filename in `srcs`, `main` must be specified.
9795
),
9896
"_windows_constraints": attr.label_list(
9997
default = [
100-
PLATFORMS_LOCATION + "/os:windows",
98+
"@platforms//os:windows",
10199
],
102100
),
103101
},

python/private/common/py_executable_bazel.bzl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ load(
3232
"py_executable_base_impl",
3333
)
3434
load(":py_internal.bzl", "py_internal")
35-
load(":semantics.bzl", "TOOLS_REPO")
3635

3736
_py_builtins = py_internal
3837
_EXTERNAL_PATH_PREFIX = "external"
@@ -56,11 +55,11 @@ the `srcs` of Python targets as required.
5655
),
5756
"_bootstrap_template": attr.label(
5857
allow_single_file = True,
59-
default = "@" + TOOLS_REPO + "//tools/python:python_bootstrap_template.txt",
58+
default = "@bazel_tools//tools/python:python_bootstrap_template.txt",
6059
),
6160
"_launcher": attr.label(
6261
cfg = "target",
63-
default = "@" + TOOLS_REPO + "//tools/launcher:launcher",
62+
default = "@bazel_tools//tools/launcher:launcher",
6463
executable = True,
6564
),
6665
"_py_interpreter": attr.label(
@@ -76,17 +75,17 @@ the `srcs` of Python targets as required.
7675
# GraphlessQueryTest.testLabelsOperator relies on it to test for
7776
# query behavior of implicit dependencies.
7877
"_py_toolchain_type": attr.label(
79-
default = "@" + TOOLS_REPO + "//tools/python:toolchain_type",
78+
default = "@bazel_tools//tools/python:toolchain_type",
8079
),
8180
"_windows_launcher_maker": attr.label(
82-
default = "@" + TOOLS_REPO + "//tools/launcher:launcher_maker",
81+
default = "@bazel_tools//tools/launcher:launcher_maker",
8382
cfg = "exec",
8483
executable = True,
8584
),
8685
"_zipper": attr.label(
8786
cfg = "exec",
8887
executable = True,
89-
default = "@" + TOOLS_REPO + "//tools/zip:zipper",
88+
default = "@bazel_tools//tools/zip:zipper",
9089
),
9190
},
9291
)

python/private/common/py_test_rule_bazel.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ load(
2121
"create_executable_rule",
2222
"py_executable_bazel_impl",
2323
)
24-
load(":semantics.bzl", "TOOLS_REPO")
2524

2625
_BAZEL_PY_TEST_ATTRS = {
2726
# This *might* be a magic attribute to help C++ coverage work. There's no
2827
# docs about this; see TestActionBuilder.java
2928
"_collect_cc_coverage": attr.label(
30-
default = "@" + TOOLS_REPO + "//tools/test:collect_cc_coverage",
29+
default = "@bazel_tools//tools/test:collect_cc_coverage",
3130
executable = True,
3231
cfg = "exec",
3332
),

python/private/common/semantics.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
IMPORTS_ATTR_SUPPORTED = True
1717

18-
TOOLS_REPO = "bazel_tools"
19-
PLATFORMS_LOCATION = "@platforms/"
20-
2118
SRCS_ATTR_ALLOW_FILES = [".py", ".py3"]
2219

2320
DEPS_ATTR_ALLOW_RULES = None

0 commit comments

Comments
 (0)