Skip to content

Commit

Permalink
Use canonical labels for analysistest config_settings
Browse files Browse the repository at this point in the history
With bzlmod enabled, errors like the following would occur:
Error in analysis_test_transition: invalid transition output '@[unknown repo '' requested from @bazel_skylib~1.3.0]//:clippy_flags': no repo visible as @ from repository '@bazel_skylib~1.3.0'

To resolve this, use str(Label("...")) to get the canonical label to use
as the key in config_settings.

Related issues: bazelbuild#2181, bazelbuild/bazel#19286
  • Loading branch information
nickgooding committed Oct 10, 2023
1 parent 3e124fb commit c803b4f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/toolchain/toolchain_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _toolchain_adds_rustc_flags_impl(ctx):
toolchain_adds_rustc_flags_test = analysistest.make(
_toolchain_adds_rustc_flags_impl,
config_settings = {
"@//:extra_rustc_flags": [CONFIG_FLAG],
str(Label("//:extra_rustc_flags")): [CONFIG_FLAG],
},
)

Expand Down
4 changes: 2 additions & 2 deletions test/unit/channel_transitions/channel_transiitons_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ nightly_transition_test = analysistest.make(
_nightly_transition_test_impl,
doc = "Test that targets can be forced to use a nightly toolchain",
config_settings = {
"@//rust/toolchain/channel:channel": "nightly",
str(Label("//rust/toolchain/channel:channel")): "nightly",
},
)

Expand All @@ -42,7 +42,7 @@ stable_transition_test = analysistest.make(
_stable_transition_test_impl,
doc = "Test that targets can be forced to use a stable toolchain",
config_settings = {
"@//rust/toolchain/channel:channel": "stable",
str(Label("//rust/toolchain/channel:channel")): "stable",
},
)

Expand Down
7 changes: 6 additions & 1 deletion test/unit/clippy/clippy_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ def make_clippy_aspect_unittest(impl, **kwargs):
binary_clippy_aspect_action_has_warnings_flag_test = make_clippy_aspect_unittest(_binary_clippy_aspect_action_has_warnings_flag_test_impl)
library_clippy_aspect_action_has_warnings_flag_test = make_clippy_aspect_unittest(_library_clippy_aspect_action_has_warnings_flag_test_impl)
test_clippy_aspect_action_has_warnings_flag_test = make_clippy_aspect_unittest(_test_clippy_aspect_action_has_warnings_flag_test_impl)
clippy_aspect_with_explicit_flags_test = make_clippy_aspect_unittest(_clippy_aspect_with_explicit_flags_test_impl, config_settings = {"@//:clippy_flags": _CLIPPY_EXPLICIT_FLAGS})
clippy_aspect_with_explicit_flags_test = make_clippy_aspect_unittest(
_clippy_aspect_with_explicit_flags_test_impl,
config_settings = {
str(Label("//:clippy_flags")): _CLIPPY_EXPLICIT_FLAGS
},
)

def clippy_test_suite(name):
"""Entry-point macro called from the BUILD file.
Expand Down
6 changes: 3 additions & 3 deletions test/unit/extra_rustc_flags/extra_rustc_flags_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extra_rustc_flags_present_test = analysistest.make(
),
},
config_settings = {
"@//:extra_rustc_flags": [EXTRA_FLAG],
str(Label("//:extra_rustc_flags")): [EXTRA_FLAG],
},
)

Expand All @@ -67,8 +67,8 @@ extra_rustc_flag_present_test = analysistest.make(
),
},
config_settings = {
"@//:extra_rustc_flag": [EXTRA_FLAG],
"@//:extra_rustc_flags": [],
str(Label("//:extra_rustc_flag")): [EXTRA_FLAG],
str(Label("//:extra_rustc_flags")): [],
},
)

Expand Down
8 changes: 4 additions & 4 deletions test/unit/per_crate_rustc_flag/per_crate_rustc_flag_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ per_crate_rustc_flag_not_present_test = analysistest.make(_per_crate_rustc_flag_
per_crate_rustc_flag_not_present_non_matching_test = analysistest.make(
_per_crate_rustc_flag_not_present_test,
config_settings = {
"@//:experimental_per_crate_rustc_flag": [NON_MATCHING_FLAG],
str(Label("//:experimental_per_crate_rustc_flag")): [NON_MATCHING_FLAG],
},
)

Expand All @@ -72,7 +72,7 @@ per_crate_rustc_flag_present_label_test = analysistest.make(
),
},
config_settings = {
"@//:experimental_per_crate_rustc_flag": [MATCHING_LABEL_FLAG],
str(Label("//:experimental_per_crate_rustc_flag")): [MATCHING_LABEL_FLAG],
},
)

Expand All @@ -85,15 +85,15 @@ per_crate_rustc_flag_present_execution_path_test = analysistest.make(
),
},
config_settings = {
"@//:experimental_per_crate_rustc_flag": [MATCHING_EXECUTION_PATH_FLAG],
str(Label("//:experimental_per_crate_rustc_flag")): [MATCHING_EXECUTION_PATH_FLAG],
},
)

per_crate_rustc_flag_invalid_pattern_test = analysistest.make(
_per_crate_rustc_flag_invalid_pattern_test,
expect_failure = True,
config_settings = {
"@//:experimental_per_crate_rustc_flag": [INVALID_FLAG],
str(Label("//:experimental_per_crate_rustc_flag")): [INVALID_FLAG],
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NOT_WINDOWS = select({
})

ENABLE_PIPELINING = {
"@//rust/settings:pipelined_compilation": True,
str(Label("//rust/settings:pipelined_compilation")): True,
}

def _second_lib_test_impl(ctx):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ def _proc_macro_does_not_leak_lib_deps_test():
target_compatible_with = NOT_WINDOWS,
)

proc_macro_does_not_leak_lib_deps_test = analysistest.make(_proc_macro_does_not_leak_lib_deps_impl, config_settings = {"@//rust/settings:pipelined_compilation": True})
proc_macro_does_not_leak_lib_deps_test = analysistest.make(
_proc_macro_does_not_leak_lib_deps_impl,
config_settings = {
str(Label("//rust/settings:pipelined_compilation")): True,
},
)

def proc_macro_does_not_leak_deps_test_suite(name):
"""Entry-point macro called from the BUILD file.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/rustdoc/rustdoc_unit_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ rustdoc_for_lib_with_cc_lib_test = analysistest.make(_rustdoc_for_lib_with_cc_li
rustdoc_with_args_test = analysistest.make(_rustdoc_with_args_test_impl)
rustdoc_zip_output_test = analysistest.make(_rustdoc_zip_output_test_impl)
rustdoc_with_json_error_format_test = analysistest.make(_rustdoc_with_json_error_format_test_impl, config_settings = {
"@//:error_format": "json",
str(Label("//:error_format")): "json",
})

def _target_maker(rule_fn, name, rustdoc_deps = [], **kwargs):
Expand Down

0 comments on commit c803b4f

Please sign in to comment.