|
| 1 | +# Copyright 2023 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 | + |
1 | 15 | """Functionality shared by multiple pieces of code."""
|
2 | 16 |
|
3 | 17 | load("@bazel_skylib//lib:types.bzl", "types")
|
@@ -46,15 +60,26 @@ def add_migration_tag(attrs):
|
46 | 60 | Returns:
|
47 | 61 | The same `attrs` object, but modified.
|
48 | 62 | """
|
| 63 | + add_tag(attrs, _MIGRATION_TAG) |
| 64 | + return attrs |
| 65 | + |
| 66 | +def add_tag(attrs, tag): |
| 67 | + """Adds `tag` to `attrs["tags"]`. |
| 68 | +
|
| 69 | + Args: |
| 70 | + attrs: dict of keyword args. It is modified in place. |
| 71 | + tag: str, the tag to add. |
| 72 | + """ |
49 | 73 | if "tags" in attrs and attrs["tags"] != None:
|
50 | 74 | tags = attrs["tags"]
|
51 | 75 |
|
52 | 76 | # Preserve the input type: this allows a test verifying the underlying
|
53 | 77 | # rule can accept the tuple for the tags argument.
|
54 | 78 | if types.is_tuple(tags):
|
55 |
| - attrs["tags"] = tags + (_MIGRATION_TAG,) |
| 79 | + attrs["tags"] = tags + (tag,) |
56 | 80 | else:
|
57 |
| - attrs["tags"] = tags + [_MIGRATION_TAG] |
| 81 | + # List concatenation is necessary because the original value |
| 82 | + # may be a frozen list. |
| 83 | + attrs["tags"] = tags + [tag] |
58 | 84 | else:
|
59 |
| - attrs["tags"] = [_MIGRATION_TAG] |
60 |
| - return attrs |
| 85 | + attrs["tags"] = [tag] |
0 commit comments