Shell 规则

报告问题 查看源代码 Nightly · 8.3 · 8.2 · 8.1 · 8.0 · 7.6

规则

sh_binary

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

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

示例

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

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

参数

属性
name

名称;必需

相应目标的唯一名称。

deps

标签列表;默认值为 []

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

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

srcs

标签列表;默认值为 []

输入文件列表。

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

env_inherit

字符串列表;默认值为 []

sh_library

查看规则来源
sh_library(name, deps, srcs, data, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, 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

名称;必需

相应目标的唯一名称。

deps

标签列表;默认值为 []

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

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

srcs

标签列表;默认值为 []

输入文件列表。

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

sh_test

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

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

示例

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

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

参数

属性
name

名称;必需

相应目标的唯一名称。

deps

标签列表;默认值为 []

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

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

srcs

标签列表;默认值为 []

输入文件列表。

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