额外操作规则

规则

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> 选项,build 将使用指定的 action_listenerextra_action 插入 build 图。

示例

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 应添加到 build 图的 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)

警告:额外操作已废弃。请改用 aspects

指定为常规构建目标时,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 的路径。

所有工具及其数据依赖项被合并到一个树中,命令可以在其中使用相对路径。工作目录将是该统一树的根目录。