Skip to content

Commit db063a8

Browse files
brandjoncopybara-github
authored andcommitted
Add internal macros and partially migrate Bazel for upcoming change
This adds `@bazel_tools//tools/python:private/defs.bzl`, which defines macro wrappers around the four native Python rules (`py_library`, `py_binary`, `py_test`, `py_runtime`). These wrappers simulate the behavior of `@rules_python//python:defs.bzl`, so that they are compatible with the upcoming `--incompatible_load_python_rules_from_bzl` flag. This change also updates many direct uses of the native Python rules to use the wrappers instead. However, changes to the third_party/ directory have to be in a separate commit. The new macros should only be used by Bazel itself. All external users should use @rules_python instead. I'm omitting updating src/test/py/bazel/testdata/runfiles_test/*/BUILD.mock files because they appear to be tests that shouldn't complain until the flag is flipped, and I'm not sure that adding a load won't break them. Also not updating the examples/ dir for similar reasons. Work toward #9006. RELNOTES: None PiperOrigin-RevId: 260858287
1 parent a9cdc3d commit db063a8

19 files changed

Lines changed: 75 additions & 5 deletions

File tree

BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Bazel - Google's Build System
22

3+
load("//tools/python:private/defs.bzl", "py_binary")
4+
35
package(default_visibility = ["//scripts/release:__pkg__"])
46

57
exports_files(["LICENSE"])

scripts/docs/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tools/python:private/defs.bzl", "py_library", "py_binary")
2+
13
filegroup(
24
name = "srcs",
35
srcs = glob(["**"]),

src/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Packaging
22

3+
load("//tools/python:private/defs.bzl", "py_library", "py_binary")
34
load(":embedded_tools.bzl", "srcsfile")
45
load(":rule_size_test.bzl", "rule_size_test")
56

src/test/java/com/google/devtools/build/lib/packages/util/BazelMockPythonSupport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void setup(MockToolsConfig config) throws IOException {
3434
addTool(config, "tools/python/srcs_version.bzl");
3535
addTool(config, "tools/python/toolchain.bzl");
3636
addTool(config, "tools/python/utils.bzl");
37+
addTool(config, "tools/python/private/defs.bzl");
3738

3839
config.create(
3940
TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/python/BUILD",

src/test/py/bazel/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package(default_visibility = ["//visibility:private"])
22

33
load("@rules_cc//cc:defs.bzl", "cc_binary")
4+
load("//tools/python:private/defs.bzl", "py_library", "py_test")
45

56
filegroup(
67
name = "srcs",

src/test/starlark/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load(
33
"rule_test",
44
"file_test",
55
)
6+
load("//tools/python:private/defs.bzl", "py_test")
67

78
package(default_visibility = ["//src:__subpackages__"])
89

tools/android/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tools/python:private/defs.bzl", "py_library", "py_binary", "py_test")
2+
13
package(default_visibility = ["//tools:__pkg__"])
24

35
py_binary(

tools/android/BUILD.tools

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tools/python:private/defs.bzl", "py_library", "py_binary")
2+
13
package(default_visibility = ["//visibility:public"])
24

35
alias(

tools/aquery_differ/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("//tools/python:private/defs.bzl", "py_library", "py_binary", "py_test")
16+
1517
package(default_visibility = ["//visibility:public"])
1618

1719
licenses(["notice"]) # Apache 2.0

tools/build_defs/hash/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//tools/python:private/defs.bzl", "py_binary")
2+
13
licenses(["notice"]) # Apache 2.0
24

35
filegroup(

0 commit comments

Comments
 (0)