From 5d6bdad1735dc85ae361bbc497932e0b6aa97d8c Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Tue, 3 Dec 2019 09:15:27 -0500 Subject: [PATCH 1/2] Fix immutable frozen set bug in defs.bzl When adding tags to a native py_library rule that is created through a macro we were not properly considering the case where the tags came from a different file and therefore were frozen. This caused an error. Analog of https://github.com/bazelbuild/rules_cc/commit/cfe68f6bc79dea602f2f6a767797f94a5904997f Co-authored-by: Googler --- python/defs.bzl | 2 +- tests/load_from_macro/BUILD | 24 ++++++++++++++++++++++++ tests/load_from_macro/foo.py | 13 +++++++++++++ tests/load_from_macro/tags.bzl | 18 ++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/load_from_macro/BUILD create mode 100644 tests/load_from_macro/foo.py create mode 100644 tests/load_from_macro/tags.bzl diff --git a/python/defs.bzl b/python/defs.bzl index 1e36de3a72..890c221e72 100644 --- a/python/defs.bzl +++ b/python/defs.bzl @@ -36,7 +36,7 @@ _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] + attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG] else: attrs["tags"] = [_MIGRATION_TAG] return attrs diff --git a/tests/load_from_macro/BUILD b/tests/load_from_macro/BUILD new file mode 100644 index 0000000000..2102e4d08a --- /dev/null +++ b/tests/load_from_macro/BUILD @@ -0,0 +1,24 @@ +# 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. + +load("//python:defs.bzl", "py_library") +load(":tags.bzl", "TAGS") + +licenses(["notice"]) + +py_library( + name = "foo", + srcs = ["foo.py"], + tags = TAGS, +) diff --git a/tests/load_from_macro/foo.py b/tests/load_from_macro/foo.py new file mode 100644 index 0000000000..724cdcb69a --- /dev/null +++ b/tests/load_from_macro/foo.py @@ -0,0 +1,13 @@ +# 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. diff --git a/tests/load_from_macro/tags.bzl b/tests/load_from_macro/tags.bzl new file mode 100644 index 0000000000..18c10e0f3c --- /dev/null +++ b/tests/load_from_macro/tags.bzl @@ -0,0 +1,18 @@ +# 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. + +""" +Example tags defined in a separate file. +""" +TAGS = ["first_tag", "second_tag"] From fac4522b6d3888176e686b0ba1e47efb6851772f Mon Sep 17 00:00:00 2001 From: Jon Brandvein Date: Wed, 4 Dec 2019 22:48:55 -0500 Subject: [PATCH 2/2] Add //tests to bazelci patterns --- .bazelci/presubmit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 6422631d39..ea43970407 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -13,6 +13,7 @@ all_targets: &all_targets - "//experimental/..." - "//packaging/..." - "//python/..." + - "//tests/..." - "//tools/..." # As a regression test for #225, check that wheel targets still build when # their package path is qualified with the repo name.