標籤

BUILD 目標 ID。

成員

標籤

Label Label(label_string)

建立參照 BUILD 目標的標籤。當您想為規則的標籤屬性提供預設值,或是在透過巨集的絕對標籤參照指定目標時,可以使用這個函式。引數必須參照絕對標籤。系統會在顯示這個 Label() 呼叫的存放區環境中,解讀標籤的存放區部分 (或其是否不存在)。範例:
Label("//tools:default")

參數

參數 說明
label_string 必要
標籤字串

名稱

string Label.name

套件中此標籤的名稱。例如:
Label("//pkg/foo:abc").name == "abc"

包裹

string Label.package

這個標籤的套件部分。例如:
Label("//pkg/foo:abc").package == "pkg/foo"

相對

Label Label.relative(relName)

解析絕對 (開頭為 //) 或相對於目前套件的標籤。如果這個標籤位於遠端存放區,系統會根據該存放區解析引數。如果引數包含存放區名稱,系統會忽略目前的標籤並依原樣傳回引數,但假如存放區名稱位於目前存放區對應中,則會改寫。保留的標籤也會依原樣傳回。
例如:
Label("//foo/bar:baz").relative(":quux") == Label("//foo/bar:quux")
Label("//foo/bar:baz").relative("//wiz:quux") == Label("//wiz:quux")
Label("@repo//foo/bar:baz").relative("//wiz:quux") == Label("@repo//wiz:quux")
Label("@repo//foo/bar:baz").relative("//visibility:public") == Label("//visibility:public")
Label("@repo//foo/bar:baz").relative("@other//wiz:quux") == Label("@other//wiz:quux")

如果傳入的存放區對應為 {'@other' : '@remapped'},則會執行下列重新對應作業:

Label("@repo//foo/bar:baz").relative("@other//wiz:quux") == Label("@remapped//wiz:quux")

參數

參數 說明
relName 必要
要按照這個標籤解析的標籤。

workspace_name

string Label.workspace_name

這個標籤的存放區部分。舉例來說,
Label("@foo//bar:baz").workspace_name == "foo"

workspace_root

string Label.workspace_root

傳回這個標籤相對於 execroot 的工作區的執行根目錄。例如:
Label("@repo//pkg/foo:abc").workspace_root == "external/repo"