规则
sh_binary
查看规则源代码sh_binary(name, deps, srcs, data, args, compatible_with, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, output_licenses, 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 规则定义的典型属性。
此属性应用于列出提供 |
srcs
|
标签列表;默认值为
此属性应用于列出属于此库的 Shell 脚本源文件。脚本可以使用 shell 的 |
env_inherit
|
字符串列表;默认值为 |
sh_library
查看规则源代码sh_library(name, deps, srcs, data, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
此规则的主要用途是汇总逻辑“库”,其中包含相关脚本(不需要编译或链接的解释型语言中的程序,例如 Bourne shell)以及这些程序在运行时需要的任何数据。然后,您可以通过一个或多个 sh_binary 规则的 data 属性使用此类“库”。
您可以使用 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 的一般说明,请参阅大多数 build 规则定义的典型属性。
此属性应用于列出提供 |
srcs
|
标签列表;默认值为
此属性应用于列出属于此库的 Shell 脚本源文件。脚本可以使用 shell 的 |
sh_test
查看规则源代码sh_test(name, deps, srcs, data, args, compatible_with, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, local, 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 规则定义的典型属性。
此属性应用于列出提供 |
srcs
|
标签列表;默认值为
此属性应用于列出属于此库的 Shell 脚本源文件。脚本可以使用 shell 的 |