Shell Rules

Report an issue View source Nightly · 7.3 · 7.2 · 7.1 · 7.0 · 6.5

Rules

sh_binary

View rule source
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)

The sh_binary rule is used to declare executable shell scripts. (sh_binary is a misnomer: its outputs aren't necessarily binaries.) This rule ensures that all dependencies are built, and appear in the runfiles area at execution time. We recommend that you name your sh_binary() rules after the name of the script minus the extension (e.g. .sh); the rule name and the file name must be distinct. sh_binary respects shebangs, so any available interpreter may be used (eg. #!/bin/zsh)

Example

For a simple shell script with no dependencies and some data files:

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

Arguments

Attributes
name

Name; required

A unique name for this target.

deps

List of labels; default is []

The list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules.

This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target.

srcs

List of labels; required

The file containing the shell script.

This attribute must be a singleton list, whose element is the shell script. This script must be executable, and may be a source file or a generated file. All other files required at runtime (whether scripts or data) belong in the data attribute.

sh_test

View rule source
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)

A sh_test() rule creates a test written as a Bourne shell script.

See the attributes common to all test rules (*_test).

Examples

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

Arguments

Attributes
name

Name; required

A unique name for this target.

deps

List of labels; default is []

The list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules.

This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target.

srcs

List of labels; required

The file containing the shell script.

This attribute must be a singleton list, whose element is the shell script. This script must be executable, and may be a source file or a generated file. All other files required at runtime (whether scripts or data) belong in the data attribute.