pico-sdk/bazel/util/label_flag_matches.bzl
armandomontanez 6262b49c74
Some checks are pending
Bazel presubmit checks / bazel-build-check (macos-latest) (push) Waiting to run
Bazel presubmit checks / bazel-build-check (ubuntu-latest) (push) Waiting to run
Bazel presubmit checks / other-bazel-checks (push) Waiting to run
Check Configs / check-configs (push) Waiting to run
CMake / build (push) Waiting to run
Build on macOS / build (push) Waiting to run
Build on Windows / build (push) Waiting to run
[bazel] Run buildifier on Bazel build files (#2825)
This is an automated change with the following commands:

$ find . -name "BUILD.bazel" -o -name "*.bzl" \
  -exec buildifier -lint=fix {} \;

* Add missing `load()` statements for things provided by @rules_cc. This
  is required for Bazel >9.
* Sort attributes on build targets.
* Add missing trailing commas where applicable.
2026-03-02 10:24:17 +00:00

36 lines
1 KiB
Python

"""A wrapper that enables a `config_setting` matcher for label_flag flags."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
def _match_label_flag_impl(ctx):
matches = str(ctx.attr.expected_value.label) == str(ctx.attr.flag.label)
return [
config_common.FeatureFlagInfo(value = str(matches)),
BuildSettingInfo(value = matches),
]
_match_label_flag = rule(
implementation = _match_label_flag_impl,
attrs = {
"expected_value": attr.label(
mandatory = True,
doc = "The expected flag value",
),
"flag": attr.label(
mandatory = True,
doc = "The flag to extract a value from",
),
},
)
def label_flag_matches(*, name, flag, value):
_match_label_flag(
name = name + "._impl",
expected_value = native.package_relative_label(value),
flag = flag,
)
native.config_setting(
name = name,
flag_values = {":{}".format(name + "._impl"): "True"},
)