Extensions > API reference > rule_attributes

rule_attributes

Information about attributes of a rule an aspect is applied to.

attr

struct rule_attributes.attr

A struct to access the values of the attributes. The values are provided by the user (if not, a default value is used). The attributes of the struct and the types of their values correspond to the keys and values of the attrs dict provided to the rule function. See example of use.

executable

struct rule_attributes.executable

A struct containing executable files defined in label type attributes marked as executable=True. The struct fields correspond to the attribute names. Each value in the struct is either a File or None. If an optional attribute is not specified in the rule then the corresponding struct value is None. If a label type is not marked as executable=True, no corresponding struct field is generated. See example of use.

file

struct rule_attributes.file

A struct containing files defined in label type attributes marked as allow_single_file. The struct fields correspond to the attribute names. The struct value is always a File or None. If an optional attribute is not specified in the rule then the corresponding struct value is None. If a label type is not marked as allow_single_file, no corresponding struct field is generated. It is a shortcut for:
list(ctx.attr.<ATTR>.files)[0]
In other words, use file to access the (singular) default output of a dependency. See example of use.

files

struct rule_attributes.files

A struct containing files defined in label or label list type attributes. The struct fields correspond to the attribute names. The struct values are list of Files. It is a shortcut for:
[f for t in ctx.attr.<ATTR> for f in t.files]
In other words, use files to access the default outputs of a dependency. See example of use.

kind

string rule_attributes.kind

The kind of a rule, such as 'cc_library'