diff options
author | Xùdōng Yáng <wyverald@gmail.com> | 2022-09-06 06:17:20 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-05 16:17:20 -0400 |
commit | 61d9c6283308410d91f769e489e53855d446d995 (patch) | |
tree | 83a2cf45a147ecf3ab318f048a2357973811237d | |
parent | 908bf1431d276245ba921e37862f74cec45ba9f4 (diff) | |
download | bazel-skylib-61d9c6283308410d91f769e489e53855d446d995.tar.gz |
Make settings error message more friendly (#394)
By stripping leading '@'s from labels in the main repo. So it talks about the flag '//foo:bar' instead of the flag '@//foo:bar'.
-rw-r--r-- | rules/common_settings.bzl | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/rules/common_settings.bzl b/rules/common_settings.bzl index d5b8408..eb057cc 100644 --- a/rules/common_settings.bzl +++ b/rules/common_settings.bzl @@ -69,13 +69,22 @@ string_list_setting = rule( doc = "A string list-typed build setting that cannot be set on the command line", ) +def _no_at_str(label): + """Strips any leading '@'s for labels in the main repo, so that the error string is more friendly.""" + s = str(label) + if s.startswith("@@//"): + return s[2:] + if s.startswith("@//"): + return s[1:] + return s + def _string_impl(ctx): allowed_values = ctx.attr.values value = ctx.build_setting_value if len(allowed_values) == 0 or value in ctx.attr.values: return BuildSettingInfo(value = value) else: - fail("Error setting " + str(ctx.label) + ": invalid value '" + value + "'. Allowed values are " + str(allowed_values)) + fail("Error setting " + _no_at_str(ctx.label) + ": invalid value '" + value + "'. Allowed values are " + str(allowed_values)) string_flag = rule( implementation = _string_impl, |