额外操作规则

规则

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 的路径。

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