Skip to content

Commit

Permalink
Fix immutable frozen set bug in defs.bzl
Browse files Browse the repository at this point in the history
When adding tags to a native cc_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.

RELNOTES:none
PiperOrigin-RevId: 283039855
Change-Id: Id4cb45675a08ca65196f4f7771abdd5bb0705b79
  • Loading branch information
oquenchil authored and copybara-github committed Nov 29, 2019
1 parent 03ae87b commit cfe68f6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _MIGRATION_TAG = "__CC_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
Expand Down
24 changes: 24 additions & 0 deletions tests/load_from_macro/BUILD
Original file line number Diff line number Diff line change
@@ -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("//cc:defs.bzl", "cc_library")
load(":tags.bzl", "TAGS")

licenses(["notice"])

cc_library(
name = "foo",
srcs = ["foo.cc"],
tags = TAGS,
)
13 changes: 13 additions & 0 deletions tests/load_from_macro/foo.cc
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 17 additions & 0 deletions tests/load_from_macro/tags.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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"]

0 comments on commit cfe68f6

Please sign in to comment.