mirror of https://github.com/bazelbuild/rules_cc
Improve errors in variable definitions by adding labels to the variables.
BEGIN_PUBLIC Improve errors in variable definitions by adding labels to the variables. END_PUBLIC PiperOrigin-RevId: 618984216 Change-Id: I5d6d11ba2b72f426b9f01bcbb528b0914c98c964
This commit is contained in:
parent
7c0a3bbee1
commit
61def7a42c
|
@ -50,6 +50,7 @@ VariableInfo = provider(
|
||||||
# @unsorted-dict-items
|
# @unsorted-dict-items
|
||||||
fields = {
|
fields = {
|
||||||
"name": "(str) The variable name",
|
"name": "(str) The variable name",
|
||||||
|
"label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
|
||||||
"actions": "(Optional[depset[ActionTypeInfo]]) The actions this variable is available for",
|
"actions": "(Optional[depset[ActionTypeInfo]]) The actions this variable is available for",
|
||||||
"type": "A type constructed using variables.types.*",
|
"type": "A type constructed using variables.types.*",
|
||||||
},
|
},
|
||||||
|
@ -58,7 +59,7 @@ VariableInfo = provider(
|
||||||
BuiltinVariablesInfo = provider(
|
BuiltinVariablesInfo = provider(
|
||||||
doc = "The builtin variables",
|
doc = "The builtin variables",
|
||||||
fields = {
|
fields = {
|
||||||
"variables": "(dict[str, struct(type=type, actions=Optional[depset[ActionTypeInfo]]) A mapping from variable name to variable metadata.",
|
"variables": "(dict[str, VariableInfo]) A mapping from variable name to variable metadata.",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ types = struct(
|
||||||
def _cc_variable_impl(ctx):
|
def _cc_variable_impl(ctx):
|
||||||
return [VariableInfo(
|
return [VariableInfo(
|
||||||
name = ctx.label.name,
|
name = ctx.label.name,
|
||||||
|
label = ctx.label,
|
||||||
type = json.decode(ctx.attr.type),
|
type = json.decode(ctx.attr.type),
|
||||||
actions = collect_action_types(ctx.attr.actions) if ctx.attr.actions else None,
|
actions = collect_action_types(ctx.attr.actions) if ctx.attr.actions else None,
|
||||||
)]
|
)]
|
||||||
|
@ -84,10 +85,7 @@ def cc_variable(name, type, **kwargs):
|
||||||
|
|
||||||
def _cc_builtin_variables_impl(ctx):
|
def _cc_builtin_variables_impl(ctx):
|
||||||
return [BuiltinVariablesInfo(variables = {
|
return [BuiltinVariablesInfo(variables = {
|
||||||
variable.name: struct(
|
variable.name: variable
|
||||||
actions = variable.actions,
|
|
||||||
type = variable.type,
|
|
||||||
)
|
|
||||||
for variable in collect_provider(ctx.attr.srcs, VariableInfo)
|
for variable in collect_provider(ctx.attr.srcs, VariableInfo)
|
||||||
})]
|
})]
|
||||||
|
|
||||||
|
@ -131,7 +129,7 @@ def get_type(*, name, variables, overrides, actions, args_label, nested_label, f
|
||||||
for action in actions:
|
for action in actions:
|
||||||
if action not in valid_actions:
|
if action not in valid_actions:
|
||||||
fail("The variable {var} is inaccessible from the action {action}. This is required because it is referenced in {nested_label}, which is included by {args_label}, which references that action".format(
|
fail("The variable {var} is inaccessible from the action {action}. This is required because it is referenced in {nested_label}, which is included by {args_label}, which references that action".format(
|
||||||
var = outer,
|
var = variables[outer].label,
|
||||||
nested_label = nested_label,
|
nested_label = nested_label,
|
||||||
args_label = args_label,
|
args_label = args_label,
|
||||||
action = action.label,
|
action = action.label,
|
||||||
|
|
|
@ -84,7 +84,7 @@ nested_str_list: List[string]""")
|
||||||
|
|
||||||
expect_type("struct", actions = [c_compile]).ok()
|
expect_type("struct", actions = [c_compile]).ok()
|
||||||
expect_type("struct", actions = [c_compile, cpp_compile]).err().equals(
|
expect_type("struct", actions = [c_compile, cpp_compile]).err().equals(
|
||||||
"The variable struct is inaccessible from the action %s. This is required because it is referenced in %s, which is included by %s, which references that action" % (cpp_compile.label, _NESTED_LABEL, _ARGS_LABEL),
|
"The variable %s is inaccessible from the action %s. This is required because it is referenced in %s, which is included by %s, which references that action" % (targets.struct.label, cpp_compile.label, _NESTED_LABEL, _ARGS_LABEL),
|
||||||
)
|
)
|
||||||
|
|
||||||
expect_type("struct.nested_str_list", actions = [c_compile]).ok()
|
expect_type("struct.nested_str_list", actions = [c_compile]).ok()
|
||||||
|
|
Loading…
Reference in New Issue