From 299c56b1bd1a850929a1ec349c142436aa8a3cbc Mon Sep 17 00:00:00 2001 From: Jon Brandvein Date: Thu, 1 Aug 2019 13:17:37 -0400 Subject: [PATCH] Add load() statements for Python rules in third_party/ This replaces all direct uses of the native Python rules underneath the third_party/ directory with load()s of the internal wrapper macros. These macros are needed for compatibility with `--incompatible_load_python_rules_from_bzl`. Some of the uses are replaced by the file under the tools/ dir, which is already used elsewhere in Bazel. A few uses have to use a new @rules_python repo (see also #9029). Work toward #9006. RELNOTES: None --- third_party/def_parser/BUILD | 4 ++++ third_party/protobuf/3.6.1/BUILD | 2 ++ third_party/protobuf/3.6.1/protobuf.bzl | 7 +++++-- third_party/protobuf/3.6.1/six.BUILD | 3 +++ third_party/protobuf/README.md | 5 +++++ third_party/py/abseil/BUILD | 4 ++++ third_party/py/concurrent/BUILD | 4 ++++ third_party/py/gflags/BUILD | 4 ++++ third_party/py/mock/BUILD | 4 ++++ third_party/py/six/BUILD | 5 +++++ 10 files changed, 40 insertions(+), 2 deletions(-) diff --git a/third_party/def_parser/BUILD b/third_party/def_parser/BUILD index 0f281e4da38411..aaa994e328a0b9 100644 --- a/third_party/def_parser/BUILD +++ b/third_party/def_parser/BUILD @@ -1,3 +1,7 @@ +# Needed for #9006. Consider replacing label with @rules_python as per #9029 if +# merging from upstream becomes an issue. +load("//tools/python:private/defs.bzl", "py_test") + licenses(["notice"]) # 3-clause BSD package( diff --git a/third_party/protobuf/3.6.1/BUILD b/third_party/protobuf/3.6.1/BUILD index a24d0c9699024f..38fb985902feaa 100644 --- a/third_party/protobuf/3.6.1/BUILD +++ b/third_party/protobuf/3.6.1/BUILD @@ -21,6 +21,8 @@ config_setting( load(":protobuf.bzl", "py_proto_library") load(":compiler_config_setting.bzl", "create_compiler_config_setting") +# Needed for #9006. Hopefully a future upstream version will include this line. +load("@rules_python//python:defs.bzl", "py_library") filegroup( name = "srcs", diff --git a/third_party/protobuf/3.6.1/protobuf.bzl b/third_party/protobuf/3.6.1/protobuf.bzl index 50f162deeba6a6..24e333a1df75cb 100644 --- a/third_party/protobuf/3.6.1/protobuf.bzl +++ b/third_party/protobuf/3.6.1/protobuf.bzl @@ -1,3 +1,6 @@ +# Needed for #9006. Hopefully a future upstream version will include this line. +load("@rules_python//python:defs.bzl", "py_library", "py_test") + def _GetPath(ctx, path): if ctx.label.workspace_root: return ctx.label.workspace_root + "/" + path @@ -383,7 +386,7 @@ def py_proto_library( if default_runtime and not default_runtime in py_libs + deps: py_libs = py_libs + [default_runtime] - native.py_library( + py_library( name = name, srcs = outs + py_extra_srcs, deps = py_libs + deps, @@ -406,7 +409,7 @@ def internal_protobuf_py_tests( """ for m in modules: s = "python/google/protobuf/internal/%s.py" % m - native.py_test( + py_test( name = "py_%s" % m, srcs = [s], main = s, diff --git a/third_party/protobuf/3.6.1/six.BUILD b/third_party/protobuf/3.6.1/six.BUILD index fb0b3604cdf443..49003ce1fb365e 100644 --- a/third_party/protobuf/3.6.1/six.BUILD +++ b/third_party/protobuf/3.6.1/six.BUILD @@ -1,3 +1,6 @@ +# Needed for #9006. Hopefully a future upstream version will include this line. +load("@rules_python//python:defs.bzl", "py_library") + genrule( name = "copy_six", srcs = ["six-1.10.0/six.py"], diff --git a/third_party/protobuf/README.md b/third_party/protobuf/README.md index a678ab5b02426f..a29397290f6249 100644 --- a/third_party/protobuf/README.md +++ b/third_party/protobuf/README.md @@ -43,6 +43,11 @@ You will create and merge the following Pull Requests. copy the `licenses` declaration and the `srcs` filegroup to the corresponding file under `third_party/protobuf/`. +1. Modify the new protobuf to be compatible with #9006 (until upstream protobuf migrates): + In the `BUILD`, `protobuf.bzl`, and `six.BUILD` files under `third_party/protobuf/`, + copy the line that loads from `@rules_python` along with its explanatory comment, from the + corresponding files in the old proto directory. (See also #9019.) + 1. In `third_party/protobuf//BUILD`, in the `srcs` filegroup rule, update the version number referring to the newly added `srcs` rules. diff --git a/third_party/py/abseil/BUILD b/third_party/py/abseil/BUILD index 5bf0a22e4cdd19..48e7c94ed788a5 100644 --- a/third_party/py/abseil/BUILD +++ b/third_party/py/abseil/BUILD @@ -1,3 +1,7 @@ +# Needed for #9006. Consider replacing label with @rules_python as per #9029 if +# merging from upstream becomes an issue. +load("//tools/python:private/defs.bzl", "py_library") + licenses(["notice"]) filegroup( diff --git a/third_party/py/concurrent/BUILD b/third_party/py/concurrent/BUILD index ccc3faa03d3594..ec8614c357a9ff 100644 --- a/third_party/py/concurrent/BUILD +++ b/third_party/py/concurrent/BUILD @@ -1,3 +1,7 @@ +# Needed for #9006. Consider replacing label with @rules_python as per #9029 if +# merging from upstream becomes an issue. +load("//tools/python:private/defs.bzl", "py_library") + licenses(["notice"]) filegroup( diff --git a/third_party/py/gflags/BUILD b/third_party/py/gflags/BUILD index 35f06748e7286d..9dcc2cff27c083 100644 --- a/third_party/py/gflags/BUILD +++ b/third_party/py/gflags/BUILD @@ -1,3 +1,7 @@ +# Needed for #9006. Consider replacing label with @rules_python as per #9029 if +# merging from upstream becomes an issue. +load("//tools/python:private/defs.bzl", "py_library") + licenses(["notice"]) filegroup( diff --git a/third_party/py/mock/BUILD b/third_party/py/mock/BUILD index 2d4961de9e696d..3c80a0245fca01 100644 --- a/third_party/py/mock/BUILD +++ b/third_party/py/mock/BUILD @@ -1,3 +1,7 @@ +# Needed for #9006. Consider replacing label with @rules_python as per #9029 if +# merging from upstream becomes an issue. +load("//tools/python:private/defs.bzl", "py_library") + licenses(["notice"]) filegroup( diff --git a/third_party/py/six/BUILD b/third_party/py/six/BUILD index fa060cb6aed82c..38833ec2e07cea 100644 --- a/third_party/py/six/BUILD +++ b/third_party/py/six/BUILD @@ -1,3 +1,8 @@ +# Needed for #9006. We can't easily replace this label with a @rules_python +# label (#9029) because this file is used in both @io_bazel and @bazel_tools, +# the latter of which can't reference other repos. +load("//tools/python:private/defs.bzl", "py_library") + licenses(["notice"]) filegroup(