Skip to content

Commit

Permalink
Fix failure on reset attrs with multiple list entries (#66)
Browse files Browse the repository at this point in the history
Fixes #64
  • Loading branch information
fmeum authored Feb 15, 2024
1 parent 6668529 commit d1a5009
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
32 changes: 26 additions & 6 deletions examples/cc_asan_test_with_reset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@ load("@with_cfg.bzl", "original_settings")
cc_asan_test(
name = "asan_test",
srcs = ["asan_test.cpp"],
# These synthetic references to targets demonstrate that attributes that are
# reset still support complex values such as selects.
data = [
":untransitioned_target",
],
":untransitioned_target_1",
":untransitioned_target_2",
] + select({
"@platforms//os:windows": [
":untransitioned_target_3",
":untransitioned_target_4",
],
"//conditions:default": [
":untransitioned_target_5",
":untransitioned_target_6",
],
}),
env = {
# Effectively invert the exit code so that the test passes if and only
# if the expected ASAN error is detected.
"ASAN_OPTIONS": "exitcode=0:abort_on_error=0",
},
# Verify that an attr.label (rather than an attr.label_list) is handled correctly, this is
# otherwise a no-op.
win_def_file = ":asan_test.def",
deps = [
":lib",
],
Expand All @@ -32,10 +47,15 @@ cc_asan_test_reset(
exports = "//cc_asan_test_with_reset/third_party:large_dep",
)

untransitioned_target(
name = "untransitioned_target",
)

original_settings(
name = "cc_asan_test_original_settings",
)

# These synthetic targets verify that they are not affected by any
# transition.
[
untransitioned_target(
name = "untransitioned_target_" + str(i),
)
for i in range(1, 7)
]
Empty file.
2 changes: 1 addition & 1 deletion examples/cc_asan_test_with_reset/cc_asan_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ _builder.extend("linkopt", select({
"//conditions:default": ["-fsanitize=address"],
}))
_builder.resettable(Label(":cc_asan_test_original_settings"))
_builder.reset_on_attrs("data", "srcs")
_builder.reset_on_attrs("data", "srcs", "win_def_file")
cc_asan_test, cc_asan_test_reset = _builder.build()
11 changes: 5 additions & 6 deletions with_cfg/private/wrapper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _process_attrs_for_reset(*, attrs, attrs_to_reset, reset_target, basename):
def _replace_dep_attr(*, dep, label_map, reset_target, base_target_name, mutable_num_calls):
if is_list(dep):
# attr.label_list
result = [
return [
_replace_single_dep(
label_string = label_string,
label_map = label_map,
Expand All @@ -234,7 +234,7 @@ def _replace_dep_attr(*, dep, label_map, reset_target, base_target_name, mutable
]
elif is_dict(dep):
# attr.label_keyed_string_dict (only the keys represent deps)
result = {
return {
_replace_single_dep(
label_string = label_string,
label_map = label_map,
Expand All @@ -246,17 +246,14 @@ def _replace_dep_attr(*, dep, label_map, reset_target, base_target_name, mutable
}
else:
# attr.label
result = _replace_single_dep(
return _replace_single_dep(
label_string = dep,
label_map = label_map,
reset_target = reset_target,
base_target_name = base_target_name,
mutable_num_calls = mutable_num_calls,
)

mutable_num_calls[0] += 1
return result

def _replace_single_dep(
*,
label_string,
Expand All @@ -279,4 +276,6 @@ def _replace_single_dep(
)
target_label_string = ":" + target_name
label_map[label] = target_label_string
mutable_num_calls[0] += 1

return native.package_relative_label(target_label_string) if use_label else target_label_string

0 comments on commit d1a5009

Please sign in to comment.