其他動作規則

規則

action_listener

action_listener(name, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, extra_actions, features, licenses, mnemonics, restricted_to, tags, target_compatible_with, testonly, visibility)

警告:額外動作已不適用。請改用長寬比

action_listener 規則不會產生任何輸出內容。相反地,它可提供動作與 extra_action 的對應關係,讓工具開發人員將 extra_action 插入建構系統。

這項規則的引數會將動作記憶稱作對應至 extra_action 規則。

指定 --experimental_action_listener=<label> 選項後,建構作業會使用指定的 action_listenerextra_action 插入建構圖中。

範例

action_listener(
    name = "index_all_languages",
    mnemonics = [
        "Javac",
        "CppCompile",
        "Python",
    ],
    extra_actions = [":indexer"],
)

action_listener(
    name = "index_java",
    mnemonics = ["Javac"],
    extra_actions = [":indexer"],
)

extra_action(
    name = "indexer",
    tools = ["//my/tools:indexer"],
    cmd = "$(location //my/tools:indexer)" +
          "--extra_action_file=$(EXTRA_ACTION_FILE)",
)

引數

屬性
name

Name; required

此目標的專屬名稱。

extra_actions

List of labels; required

這個 action_listenerextra_action 目標清單應新增至建構圖表。例如 [ "//my/tools:analyzer" ]
mnemonics

List of strings; required

這個 action_listener 應監聽的動作記憶清單,例如 [ "Javac" ]

Mnemonics 並非公開介面。我們無法保證記憶和所採取的行動將維持不變。

extra_action

extra_action(name, data, cmd, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, licenses, out_templates, requires_action_output, restricted_to, tags, target_compatible_with, testonly, toolchains, tools, visibility)

警告:額外動作已不適用。請改用長寬比

如果將 extra_action 規則指定為一般建構目標,則不會產生任何有意義的輸出內容。而是讓工具開發人員在建構圖中插入其他動作,藉此遮蔽現有動作。

如要進一步瞭解如何啟用 extra_action,請參閱 action_listener

extra_action 會以指令列的形式執行。指令列工具能夠以 $(EXTRA_ACTION_FILE) 的形式存取含有通訊協定緩衝區的檔案,並詳細介紹遮蔽原本的動作。同時可存取原始動作可存取的所有輸入檔案。如要進一步瞭解儲存在通訊協定緩衝區中的資料,請參閱 extra_actions_base.proto。每個 proto 檔案都包含 ExtraActionInfo 訊息。

如同其他所有動作,其他動作也都會採用沙箱機制,且應處理此情況。

引數

屬性
name

Name; required

此目標的專屬名稱。

您可以透過 action_listener 規則的 extra_actions 引數中的 label 參照這項規則。
cmd

String; required

要執行的指令。

例如 genrule cmd 屬性,但有下列差異:

  1. 無法擴充經驗法則標籤。系統只會展開使用 $(location ...) 的標籤。

  2. 系統會為字串套用額外傳遞,以取代所有透過 out_templates 屬性建立的輸出內容。所有的 $(output out_template) 都會以檔案路徑 (以 label 表示) 取代。

    例如,out_template $(ACTION_ID).analysis 可與 $(output $(ACTION_ID).analysis) 比對。

    實際上,這與 $(location) 相同,但範圍不同。

out_templates

List of strings; optional

extra_action 指令產生的檔案適用的範本清單。

範本可使用下列變數:

  • $(ACTION_ID),用來識別此 extra_action 的專屬 ID。用於產生專屬的輸出檔案。

requires_action_output

Boolean; optional; default is False

表示這項 extra_action 要求原始動作的輸出內容做為此 extra_action 的輸入內容。

設為 true (預設為 false) 時, extra_action 可能會假設原始動作輸出內容已納入其輸入內容中。

tools

List of labels; optional

這項規則的 tool 依附元件清單。

詳情請參閱「依附元件」的定義。

建構系統可確保在執行 extra_action 指令前建構這些先決條件;使用 host 設定進行建構,因為必須在建構期間以工具的形式執行。您可以使用 $(location //x:y) 取得個別 tools 目標 //x:y 的路徑。

所有工具及其資料依附元件都會合併成單一樹狀結構,並在其中使用相對路徑。工作目錄是該統合樹狀結構的根目錄。