rule()
和 aspect()
的 attrs
字典参数的值。成员
- bool
- int
- int_list
- 标签
- label_keyed_string_dict
- label_list
- 输出
- output_list
- 字符串
- string_dict
- string_list
- string_list_dict
bool
Attribute attr.bool(default=False, doc='', mandatory=False)为布尔值属性创建架构。
参数
参数 | 说明 |
---|---|
default
|
default = False 在实例化规则时未提供此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
int
Attribute attr.int(default=0, doc='', mandatory=False, values=[])为整数属性创建架构。该值必须在有符号的 32 位范围内。
参数
参数 | 说明 |
---|---|
default
|
default = 0 在实例化规则时未指定此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
values
|
sequence of ints ;
default = []属性允许使用的值的列表。如果指定任何其他值,则会引发错误。 |
int_list
Attribute attr.int_list(mandatory=False, allow_empty=True, *, default=[], doc='')用于为整数列表属性创建架构。每个元素都必须在有符号的 32 位范围内。
参数
参数 | 说明 |
---|---|
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
allow_empty
|
default = True 如果属性可以为空,则为 True。 |
default
|
sequence of ints ;
default = []在实例化规则时未提供此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
标签
Attribute attr.label(default=None, doc='', 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
|
default = '' 可通过文档生成工具提取的属性说明。 |
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允许哪些规则目标(类名称)。此 API 已废弃(仅出于兼容性方面的考虑),请改用提供程序。 |
cfg
|
default = None 属性的 Configuration。它可以是 "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='', 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
|
default = '' 可通过文档生成工具提取的属性说明。 |
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允许哪些规则目标(类名称)。此 API 已废弃(仅出于兼容性方面的考虑),请改用提供程序。 |
providers
|
default = [] 此属性中出现的任何依赖项都必须提供的提供程序。 此参数的格式是提供程序列表,其中包含 |
flags
|
sequence of strings ;
默认值 = []已弃用,将被移除。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
cfg
|
default = None 属性的 Configuration。它可以是 "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='', allow_files=None, allow_rules=None, providers=[], flags=[], mandatory=False, cfg=None, aspects=[])
为标签列表属性创建架构。这是一个依赖项属性。
此属性包含唯一的 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
|
default = '' 可通过文档生成工具提取的属性说明。 |
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允许哪些规则目标(类名称)。此 API 已废弃(仅出于兼容性方面的考虑),请改用提供程序。 |
providers
|
default = [] 此属性中出现的任何依赖项都必须提供的提供程序。 此参数的格式是提供程序列表,其中包含 |
flags
|
sequence of strings ;
默认值 = []已弃用,将被移除。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
cfg
|
default = None 属性的 Configuration。它可以是 "exec" (表示依赖项是针对 execution platform 构建的)或 "target" (表示依赖项是针对 target platform 构建的)。差异的一个典型示例是构建移动应用时,target platform 为 Android 或 iOS ,而 execution platform 为 Linux 、macOS 或 Windows 。 |
aspects
|
sequence of Aspects ;
default = []应应用于此属性指定的一个或多个依赖项的方面。 |
output
Attribute attr.output(doc='', mandatory=False)
为输出(标签)属性创建架构。
此属性包含唯一的 Label
值。如果用字符串代替 Label
,系统会使用标签构造函数对其进行转换。标签路径的相对部分(包括(可能已重命名的)仓库)会根据实例化的目标的软件包进行解析。
在分析时,可以使用 ctx.outputs
检索相应的 File
。
参数
参数 | 说明 |
---|---|
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
output_list
Attribute attr.output_list(allow_empty=True, *, doc='', mandatory=False)为输出列表属性创建架构。
此属性包含唯一的 Label
值。如果用字符串代替 Label
,系统会使用标签构造函数对其进行转换。标签路径的相对部分(包括(可能已重命名的)仓库)会根据实例化的目标的软件包进行解析。
在分析时,可以使用 ctx.outputs
检索相应的 File
。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果属性可以为空,则为 True。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
string
Attribute attr.string(default='', doc='', mandatory=False, values=[])为字符串属性创建架构。
参数
参数 | 说明 |
---|---|
default
|
string; or NativeComputedDefault ;
default = ''在实例化规则时未提供此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
values
|
sequence of strings ;
default = []属性允许使用的值的列表。如果指定任何其他值,则会引发错误。 |
string_dict
Attribute attr.string_dict(allow_empty=True, *, default={}, doc='', mandatory=False)为包含字典的属性创建架构,其中键和值是字符串。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果属性可以为空,则为 True。 |
default
|
default = {} 在实例化规则时未提供此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
string_list
Attribute attr.string_list(mandatory=False, allow_empty=True, *, default=[], doc='')为字符串列表属性创建架构。
参数
参数 | 说明 |
---|---|
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|
allow_empty
|
default = True 如果属性可以为空,则为 True。 |
default
|
sequence of strings; or NativeComputedDefault ;
default = []在实例化规则时未提供此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
string_list_dict
Attribute attr.string_list_dict(allow_empty=True, *, default={}, doc='', mandatory=False)为保存字典的属性创建架构,其中键为字符串,值为字符串列表。
参数
参数 | 说明 |
---|---|
allow_empty
|
default = True 如果属性可以为空,则为 True。 |
default
|
default = {} 在实例化规则时未提供此属性的值时使用的默认值。 |
doc
|
default = '' 可通过文档生成工具提取的属性说明。 |
mandatory
|
default = False 如果为 true,则必须明确指定该值(即使具有 default 也是如此)。
|