rule()
和 aspect()
的 attrs
字典参数的值。会员
bool
Attribute attr.bool(default=False, doc=None, mandatory=False)为布尔属性创建架构。相应的
ctx.attr
属性的类型为 bool
。
参数
参数 | 说明 |
---|---|
default
|
default = False 在实例化规则时,如果未为此特性指定任何值,则可以使用默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
int
Attribute attr.int(default=0, doc=None, mandatory=False, values=[])为整数属性创建架构。值必须在 32 位有符号范围内。相应的
ctx.attr
属性的类型为 int
。
参数
参数 | 说明 |
---|---|
default
|
default = 0 在实例化规则时,如果未为此特性指定值,则可以使用默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
values
|
sequence of ints ;
default = []属性允许使用的值列表。如果提供了任何其他值,则会引发错误。 |
整数列表
Attribute attr.int_list(mandatory=False, allow_empty=True, *, default=[], doc=None)为整数列表创建架构。每个元素都必须处于有符号的 32 位范围内。
参数
参数 | 说明 |
---|---|
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
default
|
sequence of ints ;
default = []如果在实例化规则时未提供此属性的任何值,则为默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
标签
Attribute attr.label(default=None, doc=None, executable=False, allow_files=None, allow_single_file=None, mandatory=False, providers=[], allow_rules=None, cfg=None, aspects=[])
为标签属性创建架构。这是一个依赖项属性。
此属性包含唯一的 Label
值。如果提供了字符串来代替 Label
,它将使用标签构造函数进行转换。标签路径的相对部分(包括可能重命名的)将针对实例化的目标的软件包进行解析。
在分析时(在规则的实现函数内),从 ctx.attr
检索属性值时,标签会被替换为相应的 Target
。这样一来,您就可以访问当前目标依赖项的提供方。
除了普通的源文件之外,这种属性通常也用于指代工具,例如编译器。与源代码文件一样,这些工具也被视为依赖项。为了避免用户每次在 BUILD 文件中使用规则时都必须指定该工具的标签,您可以将规范工具的标签硬编码为该属性的 default
值。如果您还想阻止用户覆盖此默认设置,则可以为该属性设置私密性,为其指定一个以下划线开头的名称。如需了解详情,请参阅规则页面。
参数
参数 | 说明 |
---|---|
default
|
Label; or string; or LateBoundDefault; or NativeComputedDefault; or function; or None ;
default = None在实例化规则时,如果未为此特性指定任何值,请使用默认值。请使用字符串或 Label 函数指定默认值,例如 attr.label(default = "//a:b") 。
|
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
executable
|
default = False 如果依赖项必须可执行,则为 true。也就是说,标签必须引用可执行文件,或者引用输出可执行文件的规则。使用 ctx.executable.<attribute_name> 访问标签。 |
allow_files
|
bool; or sequence of strings; or None ;
default = None是否允许 File 目标。可以是 True 、False (默认)或可以使用的文件扩展名列表(例如 [".cc", ".cpp"] )。
|
allow_single_file
|
default = None 这与 allow_files 类似,但标签必须对应于单个 File。可通过 ctx.file.<attribute_name> 访问它。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
providers
|
default = [] 此属性中显示的任何依赖项都必须提供的提供程序。 此参数的格式为一系列提供程序,即 |
allow_rules
|
sequence of strings; or None ;
default = None允许使用哪些规则目标(类名称)。此版本已弃用(仅用于确保兼容性),请改用提供程序。 |
cfg
|
default = None 属性的配置。它可以是 "exec" (表示依赖项是为 execution platform 构建的),也可以是 "target" (表示依赖项是为 target platform 构建的)。典型的区别在于构建移动应用时,target platform 为 Android 或 iOS ,而 execution platform 为 Linux 、macOS 或 Windows 。如果 executable 为 True,为了防止在目标配置中意外构建主机工具,您必须提供此参数。"target" 没有语义影响,因此请勿在 executable 为 False 时设置,除非它确实有助于阐明您的意图。 |
aspects
|
sequence of Aspects ;
default = []应该应用于此属性指定的一个或多个依赖项的方面。 |
label_keyed_string_dict
Attribute attr.label_keyed_string_dict(allow_empty=True, *, default={}, doc=None, allow_files=None, allow_rules=None, providers=[], flags=[], mandatory=False, cfg=None, aspects=[])
为包含字典的属性创建架构,其中键是标签,值是字符串。这是一个依赖项属性。
此属性包含唯一的 Label
值。如果提供了字符串来代替 Label
,它将使用标签构造函数进行转换。标签路径的相对部分(包括可能重命名的)将针对实例化的目标的软件包进行解析。
在分析时(在规则的实现函数内),从 ctx.attr
检索属性值时,标签会被替换为相应的 Target
。这样一来,您就可以访问当前目标依赖项的提供程序。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
default
|
dict; or function ;
default = {}在实例化规则时,如果未为此特性指定值,则可以使用默认值。请使用字符串或 Label 函数指定默认值,例如 attr.label_keyed_string_dict(default = {"//a:b": "value", "//a:c": "string"}) 。
|
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
allow_files
|
bool; or sequence of strings; or None ;
default = None是否允许 File 目标。可以是 True 、False (默认)或可以使用的文件扩展名列表(例如 [".cc", ".cpp"] )。
|
allow_rules
|
sequence of strings; or None ;
default = None允许使用哪些规则目标(类名称)。此版本已弃用(仅用于确保兼容性),请改用提供程序。 |
providers
|
default = [] 此属性中显示的任何依赖项都必须提供的提供程序。 此参数的格式为一系列提供程序,即 |
flags
|
sequence of strings ;
default = []已弃用,将被移除。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
cfg
|
default = None 属性的配置。它可以是 "exec" (表示依赖项是为 execution platform 构建的),也可以是 "target" (表示依赖项是为 target platform 构建的)。典型的区别在于构建移动应用时,target platform 为 Android 或 iOS ,而 execution platform 为 Linux 、macOS 或 Windows 。
|
aspects
|
sequence of Aspects ;
default = []应该应用于此属性指定的一个或多个依赖项的方面。 |
label_list
Attribute attr.label_list(allow_empty=True, *, default=[], doc=None, allow_files=None, allow_rules=None, providers=[], flags=[], mandatory=False, cfg=None, aspects=[])
为标签列表属性创建架构。这是一个依赖项属性。对应的 ctx.attr
属性的列表类型为 Target
。
此属性包含唯一的 Label
值。如果提供了字符串来代替 Label
,它将使用标签构造函数进行转换。标签路径的相对部分(包括可能重命名的)将针对实例化的目标的软件包进行解析。
在分析时(在规则的实现函数内),从 ctx.attr
检索属性值时,标签会被替换为相应的 Target
。这样一来,您就可以访问当前目标依赖项的提供程序。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
default
|
sequence of Labels; or function ;
default = []在实例化规则时,如果未为此特性指定任何值,则可以使用默认值。请使用字符串或 Label 函数指定默认值,例如 attr.label_list(default = ["//a:b", "//a:c"]) 。
|
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
allow_files
|
bool; or sequence of strings; or None ;
default = None是否允许 File 目标。可以是 True 、False (默认)或可以使用的文件扩展名列表(例如 [".cc", ".cpp"] )。
|
allow_rules
|
sequence of strings; or None ;
default = None允许使用哪些规则目标(类名称)。此版本已弃用(仅用于确保兼容性),请改用提供程序。 |
providers
|
default = [] 此属性中显示的任何依赖项都必须提供的提供程序。 此参数的格式为一系列提供程序,即 |
flags
|
sequence of strings ;
default = []已弃用,将被移除。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
cfg
|
default = None 属性的配置。它可以是 "exec" (表示依赖项是为 execution platform 构建的),也可以是 "target" (表示依赖项是为 target platform 构建的)。典型的区别在于构建移动应用时,target platform 为 Android 或 iOS ,而 execution platform 为 Linux 、macOS 或 Windows 。
|
aspects
|
sequence of Aspects ;
default = []应该应用于此属性指定的一个或多个依赖项的方面。 |
输出
Attribute attr.output(doc=None, mandatory=False)
为输出(标签)属性创建架构。
此属性包含唯一的 Label
值。如果提供了字符串来代替 Label
,它将使用标签构造函数进行转换。标签路径的相对部分(包括可能重命名的)将针对实例化的目标的软件包进行解析。
在分析时,您可以使用 ctx.outputs
检索对应的 File
。
参数
参数 | 说明 |
---|---|
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
输出列表
Attribute attr.output_list(allow_empty=True, *, doc=None, mandatory=False)为输出列表属性创建架构。
此属性包含唯一的 Label
值。如果提供了字符串来代替 Label
,它将使用标签构造函数进行转换。标签路径的相对部分(包括可能重命名的)将针对实例化的目标的软件包进行解析。
在分析时,您可以使用 ctx.outputs
检索对应的 File
。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
string
Attribute attr.string(default='', doc=None, mandatory=False, values=[])为“字符串”属性创建架构。
参数
参数 | 说明 |
---|---|
default
|
string; or NativeComputedDefault ;
default = ''在实例化规则时,如果未为此特性指定任何值,则可以使用默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
values
|
sequence of strings ;
default = []属性允许使用的值列表。如果提供了任何其他值,则会引发错误。 |
字符串字典
Attribute attr.string_dict(allow_empty=True, *, default={}, doc=None, mandatory=False)为包含字典的属性创建架构,其中键和值都是字符串。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
default
|
default = {} 在实例化规则时,如果未为此特性指定值,则可以使用默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
字符串列表
Attribute attr.string_list(mandatory=False, allow_empty=True, *, default=[], doc=None)为字符串列表属性创建架构。
参数
参数 | 说明 |
---|---|
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
default
|
sequence of strings; or NativeComputedDefault ;
default = []如果在实例化规则时未提供此属性的任何值,则为默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
string_list_dict
Attribute attr.string_list_dict(allow_empty=True, *, default={}, doc=None, mandatory=False)为包含字典的属性创建架构,其中键是字符串,值是字符串列表。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果特性可以为空,则为 true。 |
default
|
default = {} 在实例化规则时,如果未为此特性指定值,则可以使用默认值。 |
doc
|
string; or None ;
default = None对属性的说明,可通过生成工具的文档提取。 |
mandatory
|
default = False 如果为 true,则必须明确指定值(即使具有 default )。
|