From 61d9c6283308410d91f769e489e53855d446d995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=B9d=C5=8Dng=20Y=C3=A1ng?= Date: Tue, 6 Sep 2022 06:17:20 +1000 Subject: [PATCH] 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'. --- rules/common_settings.bzl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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,