Skip to main content

Rules

sh_binary

View rule sourceopen_in_new
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:

Arguments

sh_library

View rule sourceopen_in_new
The main use for this rule is to aggregate together a logical “library” consisting of related scripts—programs in an interpreted language that does not require compilation or linking, such as the Bourne shell—and any data those programs need at run-time. Such “libraries” can then be used from the data attribute of one or more sh_binary rules. You can use the filegroup rule to aggregate data files. In interpreted programming languages, there’s not always a clear distinction between “code” and “data”: after all, the program is just “data” from the interpreter’s point of view. For this reason this rule has three attributes which are all essentially equivalent: srcs, deps and data. The current implementation does not distinguish between the elements of these lists. All three attributes accept rules, source files and generated files. It is however good practice to use the attributes for their usual purpose (as with other rules).

Examples

Arguments

sh_test

View rule sourceopen_in_new
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:

Arguments