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'.
This commit is contained in:
Xùdōng Yáng 2022-09-06 06:17:20 +10:00 committed by GitHub
parent 908bf1431d
commit 61d9c62833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -69,13 +69,22 @@ string_list_setting = rule(
doc = "A string list-typed build setting that cannot be set on the command line", 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): def _string_impl(ctx):
allowed_values = ctx.attr.values allowed_values = ctx.attr.values
value = ctx.build_setting_value value = ctx.build_setting_value
if len(allowed_values) == 0 or value in ctx.attr.values: if len(allowed_values) == 0 or value in ctx.attr.values:
return BuildSettingInfo(value = value) return BuildSettingInfo(value = value)
else: 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( string_flag = rule(
implementation = _string_impl, implementation = _string_impl,