diff --git a/WORKSPACE b/WORKSPACE index 6f5bda1666e882..cd07a4b45cff84 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -79,6 +79,16 @@ new_local_repository( path = "./third_party/protobuf/3.6.1/", ) +# This is a mock version of bazelbuild/rules_python that contains only +# @rules_python//python:defs.bzl. It is used by protobuf. +# TODO(#9029): We could potentially replace this with the real @rules_python. +new_local_repository( + name = "rules_python", + path = "./third_party/rules_python", + build_file = "//third_party/rules_python:BUILD", + workspace_file = "//third_party/rules_python:rules_python.WORKSPACE", +) + local_repository( name = "googleapis", path = "./third_party/googleapis/", diff --git a/third_party/BUILD b/third_party/BUILD index eec39b37a564c7..159006d7410b25 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -35,6 +35,7 @@ filegroup( "//third_party/py/gflags:srcs", "//third_party/py/mock:srcs", "//third_party/py/six:srcs", + "//third_party/rules_python:srcs", "//third_party/zlib:srcs", "//third_party/nanopb:srcs", "//third_party/def_parser:srcs", 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/README.md b/third_party/protobuf/README.md index a678ab5b02426f..6f47936b15a8fd 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 `third_party/protobuf//BUILD` and `third_party/protobuf//protobuf.bzl`, + 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( diff --git a/third_party/rules_python/BUILD b/third_party/rules_python/BUILD new file mode 100644 index 00000000000000..e0282ba39e03c4 --- /dev/null +++ b/third_party/rules_python/BUILD @@ -0,0 +1,5 @@ +filegroup( + name = "srcs", + srcs = glob(["**"]) + ["//third_party/rules_python/python:srcs"], + visibility = ["//visibility:public"], +) diff --git a/third_party/rules_python/python/BUILD b/third_party/rules_python/python/BUILD new file mode 100644 index 00000000000000..70ff958ed43110 --- /dev/null +++ b/third_party/rules_python/python/BUILD @@ -0,0 +1,5 @@ +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) diff --git a/third_party/rules_python/python/defs.bzl b/third_party/rules_python/python/defs.bzl new file mode 100644 index 00000000000000..4468fea858739e --- /dev/null +++ b/third_party/rules_python/python/defs.bzl @@ -0,0 +1,36 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This file is selectively copied from //tools/python:private/defs.bzl.""" + +_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" + +def _add_tags(attrs): + if "tags" in attrs and attrs["tags"] != None: + attrs["tags"] += [_MIGRATION_TAG] + else: + attrs["tags"] = [_MIGRATION_TAG] + return attrs + +def py_library(**attrs): + native.py_library(**_add_tags(attrs)) + +def py_binary(**attrs): + native.py_binary(**_add_tags(attrs)) + +def py_test(**attrs): + native.py_test(**_add_tags(attrs)) + +def py_runtime(**attrs): + native.py_runtime(**_add_tags(attrs)) diff --git a/third_party/rules_python/rules_python.WORKSPACE b/third_party/rules_python/rules_python.WORKSPACE new file mode 100644 index 00000000000000..96961d95e29118 --- /dev/null +++ b/third_party/rules_python/rules_python.WORKSPACE @@ -0,0 +1,7 @@ +# A stub version of bazelbuild/rules_python that contains only the defs.bzl +# file, which is needed to access native Python rules under +# --incompatible_load_python_rules_from_bzl (#9006). +# +# TODO(#9029): Maybe replace this with the real thing. + +workspace(name = "rules_python")