|
| 1 | +# Copyright 2019 The Bazel Authors. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""This is a Bazel-internal file; do not load() it! |
| 16 | +
|
| 17 | +The incompatible change `--incompatible_load_python_rules_from_bzl` (#9006) |
| 18 | +makes it so the four native Python rules cannot be used unless a magic tag is |
| 19 | +present. It is intended that only `@rules_python` (bazelbuild/rules_python) |
| 20 | +uses this tag, and all other uses access the native rules via the wrapper |
| 21 | +macros defined in `@rules_python`. |
| 22 | +
|
| 23 | +However, `@bazel_tools` is not allowed to depend on any other repos. Therefore, |
| 24 | +we replicate the behavior of `@rules_python`'s wrapper macros in this file, for |
| 25 | +use by Bazel only. |
| 26 | +
|
| 27 | +This gets a bit tricky with the third_party/ directory. Some of its |
| 28 | +subdirectories are full-blown workspaces that cannot directly reference this |
| 29 | +file's label. For these cases we currently copy this file into those trees |
| 30 | +under the name `python_defs.bzl`. |
| 31 | +
|
| 32 | +TODO(#9029): Currently all uses of Python in Bazel's source tree use this file, |
| 33 | +but in principle only `@bazel_tools` needs to. The rest should use the real |
| 34 | +`@rules_python`, or for third_party/ packages that get mirrored into |
| 35 | +`@bazel_tools`, a dummy version of the repo that contains only this file under |
| 36 | +label `@rules_python//python:defs.bzl`. |
| 37 | +""" |
| 38 | + |
| 39 | +_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" |
| 40 | + |
| 41 | +def _add_tags(attrs): |
| 42 | + if "tags" in attrs and attrs["tags"] != None: |
| 43 | + attrs["tags"] += [_MIGRATION_TAG] |
| 44 | + else: |
| 45 | + attrs["tags"] = [_MIGRATION_TAG] |
| 46 | + return attrs |
| 47 | + |
| 48 | +def py_library(**attrs): |
| 49 | + native.py_library(**_add_tags(attrs)) |
| 50 | + |
| 51 | +def py_binary(**attrs): |
| 52 | + native.py_binary(**_add_tags(attrs)) |
| 53 | + |
| 54 | +def py_test(**attrs): |
| 55 | + native.py_test(**_add_tags(attrs)) |
| 56 | + |
| 57 | +def py_runtime(**attrs): |
| 58 | + native.py_runtime(**_add_tags(attrs)) |
0 commit comments