其他動作規則

回報問題 查看來源 Nightly · 8.3 · 8.2 · 8.1 · 8.0 · 7.6

規則

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)

警告:額外動作已淘汰。請改用aspects

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

名稱:必填

這個目標的專屬名稱。

extra_actions

標籤清單 (必要)

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

字串清單 (必要)

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)

警告:額外動作已淘汰。請改用aspects

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

詳情請參閱 action_listener,瞭解如何啟用 extra_action

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

與所有其他動作一樣,額外動作會受到沙箱保護,因此設計時應考量這點。

引數

屬性
name

名稱:必填

這個目標的專屬名稱。

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

字串;必填

要執行的指令。

genrule cmd 屬性類似,但有下列差異:

  1. 沒有擴充的啟發式標籤。只有使用 $(location ...) 的標籤會展開。

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

    例如 out_template $(ACTION_ID).analysis 可與 $(output $(ACTION_ID).analysis) 相符。

    實際上,這與 $(location) 的替代項目相同,但範圍不同。

out_templates

字串清單;預設值為 []

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

範本可使用下列變數:

  • $(ACTION_ID):這個 extra_action 的專屬 ID。 用於產生專屬輸出檔案。

requires_action_output

布林值;預設值為 False

指出這個 extra_action 需要原始動作的輸出內容,做為這個 extra_action 的輸入內容。

如果為 true (預設為 false),extra_action 可以假設原始動作輸出內容是輸入內容的一部分。

tools

標籤清單;預設值為 []

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

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

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

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