Documentation

attr

Module for creating new attributes. They are only for use with rule or aspect.

bool

attr_definition attr.bool(default=False, mandatory=False)

Creates an attribute of type bool.

Parameters

Parameter Description
default

bool

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

int

attr_definition attr.int(default=0, mandatory=False, values=[])

Creates an attribute of type int.

Parameters

Parameter Description
default

int

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

values

sequence of ints

the list of allowed values for the attribute. An error is raised if any other value is given.

int_list

attr_definition attr.int_list(default=[], mandatory=False, non_empty=False, allow_empty=True)

Creates an attribute which is a list of ints.

Parameters

Parameter Description
default

sequence of ints

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty

label

attr_definition attr.label(default=None, executable=False, allow_files=None, allow_single_file=None, mandatory=False, providers=[], allow_rules=None, single_file=False, cfg=None, aspects=[])

Creates an attribute of type Target which is the target referred to by the label. It is the only way to specify a dependency to another target. If you need a dependency that the user cannot overwrite, make the attribute private.

Parameters

Parameter Description
default

Label

the default value of the attribute. Use the Label function to specify a default value ex:

attr.label(default = Label("//a:b"))

executable

bool

True if the labels have to be executable. This means the label must refer to an executable file, or to a rule that outputs an executable file. Access the labels with ctx.executable.<attribute_name>.

allow_files

whether File targets are allowed. Can be True, False (default), or a list of file extensions that are allowed (e.g. [".cc", ".cpp"]).

allow_single_file

This is similar to allow_files, with the restriction that the label must correspond to a single File. Access it through ctx.file.<attribute_name>.

mandatory

bool

True if the value must be explicitly specified

providers

sequence

mandatory providers list. It should be either a list of providers, or a list of lists of providers. Every dependency should provide ALL providers from at least ONE of these lists. A single list of providers will be automatically converted to a list containing one list of providers.

allow_rules

sequence of strings

which rule targets (name of the classes) are allowed. This is deprecated (kept only for compatiblity), use providers instead.

single_file

bool

Deprecated: Use allow_single_file instead. If True, the label must correspond to a single File. Access it through ctx.file.<attribute_name>.

cfg

configuration of the attribute. It can be either "data", "host", or "target". This parameter is required if executable is True.

aspects

sequence of Aspects

aspects that should be applied to the dependency or dependencies specified by this attribute

label_keyed_string_dict

attr_definition attr.label_keyed_string_dict(default={}, allow_files=None, allow_rules=None, providers=[], flags=[], mandatory=False, non_empty=False, allow_empty=True, cfg=None, aspects=[])

Creates an attribute which is a dict. Its keys are type Target and are specified by the label keys of the input dict. Its values are strings. See label for more information.

Parameters

Parameter Description
default

dict

the default value of the attribute. Use the Label function to specify default values ex:

attr.label_keyed_string_dict(default = { Label("//a:b"): "value", Label("//a:c"): "string" })

allow_files

whether File targets are allowed. Can be True, False (default), or a list of file extensions that are allowed (e.g. [".cc", ".cpp"]).

allow_rules

sequence of strings

which rule targets (name of the classes) are allowed. This is deprecated (kept only for compatiblity), use providers instead.

providers

sequence

mandatory providers list. It should be either a list of providers, or a list of lists of providers. Every dependency should provide ALL providers from at least ONE of these lists. A single list of providers will be automatically converted to a list containing one list of providers.

flags

sequence of strings

deprecated, will be removed

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty

cfg

configuration of the attribute. It can be either "data", "host", or "target". This parameter is required if executable is True.

aspects

sequence of Aspects

aspects that should be applied to the dependency or dependencies specified by this attribute

label_list

attr_definition attr.label_list(default=[], allow_files=None, allow_rules=None, providers=[], flags=[], mandatory=False, non_empty=False, allow_empty=True, cfg=None, aspects=[])

Creates an attribute which is a list of type Target which are specified by the labels in the list. See label for more information.

Parameters

Parameter Description
default

sequence of Labels

the default value of the attribute. Use the Label function to specify default values ex:

attr.label_list(default = [ Label("//a:b"), Label("//a:c") ])

allow_files

whether File targets are allowed. Can be True, False (default), or a list of file extensions that are allowed (e.g. [".cc", ".cpp"]).

allow_rules

sequence of strings

which rule targets (name of the classes) are allowed. This is deprecated (kept only for compatiblity), use providers instead.

providers

sequence

mandatory providers list. It should be either a list of providers, or a list of lists of providers. Every dependency should provide ALL providers from at least ONE of these lists. A single list of providers will be automatically converted to a list containing one list of providers.

flags

sequence of strings

deprecated, will be removed

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty

cfg

configuration of the attribute. It can be either "data", "host", or "target". This parameter is required if executable is True.

aspects

sequence of Aspects

aspects that should be applied to the dependency or dependencies specified by this attribute

license

attr_definition attr.license(default=None, mandatory=False)

Creates an attribute of type license.

Parameters

Parameter Description
default

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

output

attr_definition attr.output(default=None, mandatory=False)

Creates an attribute of type output. The user provides a file name (string) and the rule must create an action that generates the file.

Parameters

Parameter Description
default

Label

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

output_list

attr_definition attr.output_list(default=[], mandatory=False, non_empty=False, allow_empty=True)

Creates an attribute which is a list of outputs. See output for more information.

Parameters

Parameter Description
default

sequence of Labels

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty

string

attr_definition attr.string(default='', mandatory=False, values=[])

Creates an attribute of type string.

Parameters

Parameter Description
default

string

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

values

sequence of strings

the list of allowed values for the attribute. An error is raised if any other value is given.

string_dict

attr_definition attr.string_dict(default={}, mandatory=False, non_empty=False, allow_empty=True)

Creates an attribute of type dict, mapping from string to string.

Parameters

Parameter Description
default

dict

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty

string_list

attr_definition attr.string_list(default=[], mandatory=False, non_empty=False, allow_empty=True)

Creates an attribute which is a list of strings.

Parameters

Parameter Description
default

sequence of strings

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty

string_list_dict

attr_definition attr.string_list_dict(default={}, mandatory=False, non_empty=False, allow_empty=True)

Creates an attribute of type dict, mapping from string to list of string.

Parameters

Parameter Description
default

dict

the default value of the attribute.

mandatory

bool

True if the value must be explicitly specified

non_empty

bool

True if the attribute must not be empty. Deprecated: Use allow_empty instead.

allow_empty

bool

True if the attribute can be empty