Shell 规则

报告问题 查看源代码

规则

sh_binary

查看规则来源
sh_binary(name, deps, srcs, data, args, compatible_with, deprecation, distribs, env, exec_compatible_with, exec_properties, features, licenses, output_licenses, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)

sh_binary 规则用于声明可执行的 shell 脚本。(sh_binary 不恰当:其输出未必是二进制文件。)此规则可确保所有依赖项均已构建,并在执行时出现在 runfiles 区域中。我们建议您以脚本名称减去扩展名(例如 .sh)来命名 sh_binary() 规则;规则名称和文件名必须不同。sh_binary 会遵循 Sheban,因此可以使用任何可用的解释器(例如#!/bin/zsh

示例

对于没有依赖项和一些数据文件的简单 shell 脚本:

sh_binary(
    name = "foo",
    srcs = ["foo.sh"],
    data = glob(["datafiles/*.txt"]),
)

参数

属性
name

Name; required

此目标的唯一名称。

deps

List of labels; optional

要汇总到此目标的“库”目标的列表。请参阅大多数 build 规则定义的典型属性中关于 deps 的一般注释。

此属性应该用于列出其他 sh_library 规则,这些规则提供 srcs 中的代码所依赖的已解释程序源代码。这些规则提供的文件将存在于此目标的 runfiles 中。

srcs

List of labels; required

包含 shell 脚本的文件。

此属性必须是单例列表,其元素是 shell 脚本。此脚本必须是可执行文件,可以是源文件或生成的文件。 运行时所需的所有其他文件(无论是脚本还是数据)都属于 data 属性。

sh_library

查看规则来源
sh_library(name, deps, srcs, data, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, licenses, restricted_to, tags, target_compatible_with, testonly, visibility)

此规则的主要用途是汇总一个逻辑“库”,其中包含相关脚本(使用解释型语言、无需编译或链接的程序,例如 Bourne shell),以及这些程序在运行时所需的任何数据。然后,可以通过一个或多个 sh_binary 规则的 data 属性来使用此类“库”。

您可以使用 filegroup 规则来汇总数据文件。

在解释型编程语言中,“代码”和“数据”并不总是有明确的区别:毕竟,从解释器的角度来看,程序只是“数据”。因此,此规则有三个属性,它们基本上等同:srcsdepsdata。 当前的实现不区分这些列表的元素。 所有这三个属性都接受规则、源文件和生成的文件。 不过,最好将特性用于其常规用途(与其他规则一样)。

示例

sh_library(
    name = "foo",
    data = [
        ":foo_service_script",  # an sh_binary with srcs
        ":deploy_foo",  # another sh_binary with srcs
    ],
)

参数

属性
name

Name; required

此目标的唯一名称。

deps

List of labels; optional

要汇总到此目标的“库”目标的列表。请参阅大多数 build 规则定义的典型属性中关于 deps 的一般注释。

此属性应该用于列出其他 sh_library 规则,这些规则提供 srcs 中的代码所依赖的已解释程序源代码。这些规则提供的文件将存在于此目标的 runfiles 中。

srcs

List of labels; optional

输入文件列表。

此属性应该用于列出属于此库的 Shell 脚本源文件。脚本可以使用 shell 的 source. 命令加载其他脚本。

sh_test

查看规则来源
sh_test(name, deps, srcs, data, args, compatible_with, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, licenses, local, restricted_to, shard_count, size, tags, target_compatible_with, testonly, timeout, toolchains, visibility)

sh_test() 规则可创建作为 Bourne shell 脚本编写的测试。

请参阅所有测试规则通用的属性 (*_test)

示例

sh_test(
    name = "foo_integration_test",
    size = "small",
    srcs = ["foo_integration_test.sh"],
    deps = [":foo_sh_lib"],
    data = glob(["testdata/*.txt"]),
)

参数

属性
name

Name; required

此目标的唯一名称。

deps

List of labels; optional

要汇总到此目标的“库”目标的列表。请参阅大多数 build 规则定义的典型属性中关于 deps 的一般注释。

此属性应该用于列出其他 sh_library 规则,这些规则提供 srcs 中的代码所依赖的已解释程序源代码。这些规则提供的文件将存在于此目标的 runfiles 中。

srcs

List of labels; required

包含 shell 脚本的文件。

此属性必须是单例列表,其元素是 shell 脚本。此脚本必须是可执行文件,可以是源文件或生成的文件。 运行时所需的所有其他文件(无论是脚本还是数据)都属于 data 属性。