其他動作規則

規則

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_listener,將 extra_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_listener 應新增至建構圖表的 extra_action 目標清單。例如:[ "//my/tools:analyzer" ]
mnemonics

List of strings; required

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

語音並非公開介面。我們無法保證記憶力及其行為不會改變。

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 規則不會產生任何有意義的輸出內容。而是允許工具開發人員在覆蓋現有動作的建構圖中插入其他動作。

如要進一步瞭解如何啟用 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 設定建構,因為它們必須在建構期間以工具的形式執行。個別 tools 目標 //x:y 的路徑可使用 $(location //x:y) 取得。

所有工具及其資料依附元件都會合併為單一樹狀結構,以供指令使用相對路徑。工作目錄將是該統合樹狀結構的根層級。