追加のアクション ルール

ルール

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 を有効にする方法については、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) を使用して取得できます。

すべてのツールとそのデータ依存関係は 1 つのツリーに統合され、そのツリー内で相対パスを使用できます。作業ディレクトリは、その統合ツリーのルートになります。