规则
sh_binary
查看规则源代码sh_binary(name, deps, srcs, data, args, aspect_hints, 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, use_bash_launcher, visibility)
sh_binary 规则用于声明可执行的 shell 脚本。
(sh_binary 是一个误称:其输出不一定是二进制文件。)此规则可确保
所有依赖项都已构建,并在执行时显示在 runfiles 区域中。
我们建议您根据脚本的名称(不含扩展名,例如 .sh)来命名 sh_binary() 规则;规则名称和文件名必须不同。sh_binary 遵循 Shebang,因此可以使用任何可用的解释器(例如
#!/bin/zsh)
示例
对于没有依赖项和一些数据文件的简单 shell 脚本:
sh_binary(
name = "foo",
srcs = ["foo.sh"],
data = glob(["datafiles/*.txt"]),
)
实参
| 属性 | |
|---|---|
name |
名称;必需 此目标的唯一名称。 |
deps
|
要汇总到此目标中的“库”目标列表。
如需了解有关 deps
的一般注释,请参阅大多数构建规则定义的
典型属性。
此属性应用于列出其他 |
srcs
|
包含 shell 脚本的文件。
此属性必须是单例列表,其元素是 shell 脚本。
此脚本必须是可执行文件,并且可以是源文件或生成的文件。
运行时所需的所有其他文件(无论是脚本还是数据)都属于
|
env_inherit
|
字符串列表;默认值为 |
use_bash_launcher
|
布尔值;默认值为 |
sh_library
查看规则源代码sh_library(name, deps, srcs, data, aspect_hints, 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)组成的逻辑
"库"以及这些程序在运行时所需的任何数据汇总在一起。然后,此类“库”可以从
data 属性的一个或
多个 sh_binary 规则中使用。
您可以使用 filegroup 规则来汇总数据
文件。
在解释型编程语言中,“代码”和“数据”之间并不总是存在明确的
区别:毕竟,从解释器的角度来看,程序只是
“数据”。因此,此规则具有三个属性,它们本质上是等效的:srcs、deps 和 data。当前实现不会区分这些列表的元素。这三个属性都接受规则、源文件和生成的文件。
不过,最好将这些属性用于其通常用途(与其他规则一样)。
示例
sh_library(
name = "foo",
data = [
":foo_service_script", # an sh_binary with srcs
":deploy_foo", # another sh_binary with srcs
],
)
实参
| 属性 | |
|---|---|
name |
名称;必需 此目标的唯一名称。 |
deps
|
要汇总到此目标中的“库”目标列表。
如需了解有关 deps
的一般注释,请参阅大多数构建规则定义的
典型属性。
此属性应用于列出其他 |
srcs
|
输入文件列表。
此属性应用于列出属于
此库的 shell 脚本源文件。脚本可以使用 shell 的 |
sh_test
查看规则源代码sh_test(name, deps, srcs, data, args, aspect_hints, 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, use_bash_launcher, 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 |
名称;必需 此目标的唯一名称。 |
deps
|
要汇总到此目标中的“库”目标列表。
如需了解有关 deps
的一般注释,请参阅大多数构建规则定义的
典型属性。
此属性应用于列出其他 |
srcs
|
包含 shell 脚本的文件。
此属性必须是单例列表,其元素是 shell 脚本。
此脚本必须是可执行文件,并且可以是源文件或生成的文件。
运行时所需的所有其他文件(无论是脚本还是数据)都属于
|
use_bash_launcher
|
布尔值;默认值为 |