From d1a50095f216f8d8be3e55833ed0a8ee9e8cfb68 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 15 Feb 2024 20:58:37 +0100 Subject: [PATCH] Fix failure on reset attrs with multiple list entries (#66) Fixes #64 --- examples/cc_asan_test_with_reset/BUILD.bazel | 32 +++++++++++++++---- .../cc_asan_test_with_reset/asan_test.def | 0 .../cc_asan_test_with_reset/cc_asan_test.bzl | 2 +- with_cfg/private/wrapper.bzl | 11 +++---- 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 examples/cc_asan_test_with_reset/asan_test.def diff --git a/examples/cc_asan_test_with_reset/BUILD.bazel b/examples/cc_asan_test_with_reset/BUILD.bazel index ec46cb9..551755d 100644 --- a/examples/cc_asan_test_with_reset/BUILD.bazel +++ b/examples/cc_asan_test_with_reset/BUILD.bazel @@ -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", ], @@ -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) +] diff --git a/examples/cc_asan_test_with_reset/asan_test.def b/examples/cc_asan_test_with_reset/asan_test.def new file mode 100644 index 0000000..e69de29 diff --git a/examples/cc_asan_test_with_reset/cc_asan_test.bzl b/examples/cc_asan_test_with_reset/cc_asan_test.bzl index cb89bf6..a68e1f0 100644 --- a/examples/cc_asan_test_with_reset/cc_asan_test.bzl +++ b/examples/cc_asan_test_with_reset/cc_asan_test.bzl @@ -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() diff --git a/with_cfg/private/wrapper.bzl b/with_cfg/private/wrapper.bzl index f8040c5..f6bfd9c 100644 --- a/with_cfg/private/wrapper.bzl +++ b/with_cfg/private/wrapper.bzl @@ -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, @@ -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, @@ -246,7 +246,7 @@ 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, @@ -254,9 +254,6 @@ def _replace_dep_attr(*, dep, label_map, reset_target, base_target_name, mutable mutable_num_calls = mutable_num_calls, ) - mutable_num_calls[0] += 1 - return result - def _replace_single_dep( *, label_string, @@ -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