Skip to content

Commit

Permalink
Add stub @rules_python to third_party/
Browse files Browse the repository at this point in the history
This stub contains only one relevant file, @rules_python//python:defs.bzl,
which mimics the file at the same path in bazelbuild/rules_python. Having this
repo gives us a way to inject this defs.bzl file into our protobuf dependency,
which is loaded as a separate (local) external repo and therefore cannot access
the existing //tools/python:private/defs.bzl in Bazel's own workspace. It also
means we'll be compatible with the future upstream migration to fix protobuf
for bazelbuild#9006.

A separate PR will add this to the Bazel root WORKSPACE file (since
third_party/ must be updated in a separate commit).

Break-out of bazelbuild#9019. Work toward bazelbuild#9006.

RELNOTES: None
  • Loading branch information
brandjon committed Aug 1, 2019
1 parent 299e3f0 commit 5acf342
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions third_party/rules_python/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "srcs",
srcs = glob(["**"]) + ["//third_party/rules_python/python:srcs"],
visibility = ["//visibility:public"],
)
5 changes: 5 additions & 0 deletions third_party/rules_python/python/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
36 changes: 36 additions & 0 deletions third_party/rules_python/python/defs.bzl
Original file line number Diff line number Diff line change
@@ -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))
7 changes: 7 additions & 0 deletions third_party/rules_python/rules_python.WORKSPACE
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 5acf342

Please sign in to comment.