其他操作规则

报告问题 查看源代码

规则

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>,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 应添加到构建图的 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 命令之前构建的;它们使用 exec 配置构建而成,因为它们必须在构建过程中作为工具运行。您可以使用 $(location //x:y) 获取单个 tools 目标 //x:y 的路径。

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