rule() 和 aspect() 的 attrs 字典引數值。成員
- bool
- int
- int_list
- 標籤
- label_keyed_string_dict
- label_list
- output
- output_list
- 字串
- string_dict
- string_keyed_label_dict
- string_list
- string_list_dict
bool
Attribute attr.bool(default=False, doc=None, mandatory=False)
ctx.attr 屬性類型為 bool。
          
      參數
| 參數 | 說明 | 
|---|---|
| default | 預設值為 False如果例項規則時未提供這項屬性的值,則要使用的預設值。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
int
Attribute attr.int(default=0, doc=None, mandatory=False, values=[])
ctx.attr 屬性類型為 int。
          
      參數
| 參數 | 說明 | 
|---|---|
| default | 預設值為 0如果例項規則時未提供這項屬性的值,則要使用的預設值。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| values | int 的序列;
                                     預設值為 []屬性的允許值清單。如果提供任何其他值,系統就會發出錯誤。 | 
int_list
Attribute attr.int_list(mandatory=False, allow_empty=True, *, default=[], doc=None)
參數
| 參數 | 說明 | 
|---|---|
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| allow_empty | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | sequence of ints;
                                     default is []A default value to use if no value for this attribute is given when instantiating the rule. | 
| doc | string;或 None;預設為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=[], flags=[])
建立標籤屬性的結構定義。這是依附元件屬性。
這項屬性包含不重複的 Label 值。如果提供字串來取代 Label,系統會使用標籤建構函式轉換字串。標籤路徑的相對部分 (包括可能已重新命名的存放區) 會根據已例項化的目標套件解析。
在分析期間 (規則實作函式內),從 ctx.attr 擷取屬性值時,標籤會替換為對應的 Target。這樣您就能存取目前目標依附元件的供應商。
除了普通來源檔案,這類屬性通常也用於參照工具 (例如編譯器)。這類工具會視為依附元件,就像來源檔案一樣。如要避免使用者在 BUILD 檔案中使用規則時,每次都必須指定工具的標籤,您可以將標準工具的標籤硬式編碼為這個屬性的 default 值。如要禁止使用者覆寫這個預設值,可以為屬性指派底線開頭的名稱,將屬性設為私有。詳情請參閱「規則」頁面。
          
      
參數
| 參數 | 說明 | 
|---|---|
| default | Label;或 string;或 LateBoundDefault;或 NativeComputedDefault;或 function;或 None;
                                     預設值為None如果例項化規則時未提供這個屬性的值,則使用預設值。使用字串或 Label函式指定預設值,例如attr.label(default = "//a:b")。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| executable | 預設值為 False如果依附元件必須是可執行檔,則為 True。也就是說,標籤必須參照可執行檔,或是輸出可執行檔的規則。使用 ctx.executable.<attribute_name>存取標籤。 | 
| allow_files | bool;或 sequence 的 string;或 None;預設值為None是否允許 File目標。可以是True、False(預設值),或允許的副檔名清單 (例如[".cc", ".cpp"])。 | 
| allow_single_file | 預設為 None這與 allow_files類似,但限制是標籤必須對應單一 File。如要存取,請前往ctx.file.<attribute_name>。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| providers | 預設值為 []必須提供這個屬性中顯示的任何依附元件。 這個引數的格式為提供者清單的清單,也就是  | 
| allow_rules | string 的序列;或 None;
                                     預設值為None允許哪些規則目標 (類別名稱)。這項功能已淘汰 (僅保留相容性),請改用供應商。 | 
| cfg | 預設值為屬性的 NoneConfiguration。可以是 "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 is []Aspects that should be applied to the dependency or dependencies specified by this attribute. | 
| flags | sequence of strings;預設為 []已淘汰,將會移除。 | 
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 | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | dict 或 function;
                                     預設值為 {}如果例項化規則時未提供這個屬性的值,則要使用的預設值。請使用字串或 Label函式指定預設值,例如attr.label_keyed_string_dict(default = {"//a:b": "value", "//a:c": "string"})。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| allow_files | bool;或 sequence 的 string;或 None;預設值為None是否允許 File目標。可以是True、False(預設值),或允許的副檔名清單 (例如[".cc", ".cpp"])。 | 
| allow_rules | string 的序列;或 None;
                                     預設值為None允許哪些規則目標 (類別名稱)。這項功能已淘汰 (僅保留相容性),請改用供應商。 | 
| providers | 預設值為 []必須提供這個屬性中顯示的任何依附元件。 這個引數的格式為提供者清單的清單,也就是  | 
| flags | sequence of strings;預設為 []已淘汰,將會移除。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| cfg | 預設值為屬性的 NoneConfiguration。可以是 "exec"(表示依附元件是為execution platform建構),也可以是"target"(表示依附元件是為target platform建構)。舉例來說,在建構行動應用程式時,target platform是Android或iOS,而execution platform則是Linux、macOS或Windows。 | 
| aspects | sequence of Aspects;
                                     default is []Aspects that should be applied to the dependency or dependencies specified by this attribute. | 
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 的 list 類型。
這項屬性包含不重複的 Label 值。如果提供字串來取代 Label,系統會使用標籤建構函式轉換字串。標籤路徑的相對部分 (包括可能已重新命名的存放區) 會根據已例項化的目標套件解析。
在分析期間 (規則實作函式內),從 ctx.attr 擷取屬性值時,標籤會替換為對應的 Target。這樣一來,您就能存取目前目標依附元件的供應商。
          
      
參數
| 參數 | 說明 | 
|---|---|
| allow_empty | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | 標籤的序列;或函式;
                                     預設值為 []如果例項化規則時未提供這個屬性的值,則使用預設值。使用字串或 Label函式指定預設值,例如attr.label_list(default = ["//a:b", "//a:c"])。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| allow_files | bool;或 sequence 的 string;或 None;預設值為None是否允許 File目標。可以是True、False(預設值),或允許的副檔名清單 (例如[".cc", ".cpp"])。 | 
| allow_rules | string 的序列;或 None;
                                     預設值為None允許哪些規則目標 (類別名稱)。這項功能已淘汰 (僅保留相容性),請改用供應商。 | 
| providers | 預設值為 []必須提供這個屬性中顯示的任何依附元件。 這個引數的格式為提供者清單的清單,也就是  | 
| flags | sequence of strings;預設為 []已淘汰,將會移除。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| cfg | 預設值為屬性的 NoneConfiguration。可以是 "exec"(表示依附元件是為execution platform建構),也可以是"target"(表示依附元件是為target platform建構)。舉例來說,在建構行動應用程式時,target platform是Android或iOS,而execution platform則是Linux、macOS或Windows。 | 
| aspects | sequence of Aspects;
                                     default is []Aspects that should be applied to the dependency or dependencies specified by this attribute. | 
output
Attribute attr.output(doc=None, mandatory=False)
為輸出 (標籤) 屬性建立結構定義。
這項屬性包含不重複的 Label 值。如果提供字串來取代 Label,系統會使用標籤建構函式轉換字串。標籤路徑的相對部分 (包括可能已重新命名的存放區) 會根據已例項化的目標套件解析。
在分析時,可以使用 ctx.outputs 擷取對應的 File。
          
      
參數
| 參數 | 說明 | 
|---|---|
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
output_list
Attribute attr.output_list(allow_empty=True, *, doc=None, mandatory=False)
這項屬性包含不重複的 Label 值。如果提供字串來取代 Label,系統會使用標籤建構函式轉換字串。標籤路徑的相對部分 (包括可能已重新命名的存放區) 會根據已例項化的目標套件解析。
在分析時,可以使用 ctx.outputs 擷取對應的 File。
          
      
參數
| 參數 | 說明 | 
|---|---|
| allow_empty | 預設值為 True。如果屬性可以為空,則為 True。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
字串
Attribute attr.string(default='', doc=None, mandatory=False, values=[])
參數
| 參數 | 說明 | 
|---|---|
| default | string 或 NativeComputedDefault;預設值為 ''如果例項化規則時未提供這個屬性的值,則使用預設值。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| values | 字串的序列;
                                     預設值為 []屬性的允許值清單。如果提供任何其他值,系統就會發出錯誤。 | 
string_dict
Attribute attr.string_dict(allow_empty=True, *, default={}, doc=None, mandatory=False)
參數
| 參數 | 說明 | 
|---|---|
| allow_empty | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | 預設值為 {}如果例項規則時未提供這項屬性的值,則要使用的預設值。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
string_keyed_label_dict
Attribute attr.string_keyed_label_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 | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | dict 或 function;
                                     預設值為 {}如果例項化規則時未提供這個屬性的值,則要使用的預設值。請使用字串或 Label函式指定預設值,例如attr.string_keyed_label_dict(default = {"foo": "//a:b", "bar": "//a:c"})。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| allow_files | bool;或 sequence 的 string;或 None;預設值為None是否允許 File目標。可以是True、False(預設值),或允許的副檔名清單 (例如[".cc", ".cpp"])。 | 
| allow_rules | string 的序列;或 None;
                                     預設值為None允許哪些規則目標 (類別名稱)。這項功能已淘汰 (僅保留相容性),請改用供應商。 | 
| providers | 預設值為 []必須提供這個屬性中顯示的任何依附元件。 這個引數的格式為提供者清單的清單,也就是  | 
| flags | sequence of strings;預設為 []已淘汰,將會移除。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| cfg | 預設值為屬性的 NoneConfiguration。可以是 "exec"(表示依附元件是為execution platform建構),也可以是"target"(表示依附元件是為target platform建構)。舉例來說,在建構行動應用程式時,target platform是Android或iOS,而execution platform則是Linux、macOS或Windows。 | 
| aspects | sequence of Aspects;
                                     default is []Aspects that should be applied to the dependency or dependencies specified by this attribute. | 
string_list
Attribute attr.string_list(mandatory=False, allow_empty=True, *, default=[], doc=None)
參數
| 參數 | 說明 | 
|---|---|
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 | 
| allow_empty | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | 字串的序列;或 NativeComputedDefault;
預設值為 []如果例項化規則時未提供這個屬性的值,則使用預設值。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
string_list_dict
Attribute attr.string_list_dict(allow_empty=True, *, default={}, doc=None, mandatory=False)
參數
| 參數 | 說明 | 
|---|---|
| allow_empty | 預設值為 True。如果屬性可以為空,則為 True。 | 
| default | 預設值為 {}如果例項規則時未提供這項屬性的值,則要使用的預設值。 | 
| doc | string;或 None;預設為None可由文件生成工具擷取的屬性說明。 | 
| mandatory | 預設值為 False如果為 true,則必須明確指定值 (即使有 default)。 |