rule()
和 aspect()
的 attrs
字典引數值。會員
- bool
- int
- int_list
- label
- 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 ;
預設值 = []在執行個體化規則時,若未提供這個屬性的值,系統會使用預設值。 |
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 ,不過標籤的限制必須與單一檔案對應。可透過 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='', 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可以使用哪些規則目標 (類別名稱)。這個項目已淘汰 (只為了相容性保留),請改用供應商。 |
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='', 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可以使用哪些規則目標 (類別名稱)。這個項目已淘汰 (只為了相容性保留),請改用供應商。 |
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 = []應套用至這個屬性指定的依附元件或依附元件的切面。 |
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 )。
|
字串
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 ;
預設值 = []在執行個體化規則時,若未提供這個屬性的值,系統會使用預設值。 |
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 )。
|