Buck: sh_binary()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

sh_binary()

This is liable to change in the future.

A sh_binary() is used to execute a shell script.

Arguments

  • name (required) #

    The short name for this build target.

  • main (required) #

    Either the path to the script (relative to the build file), or a build target. This file must be executable in order to be run.

  • resources (defaults to []) #

    A list of files or build rules that this rule requires in order to run. These could be things such as random data files.

    When the script runs, the $BUCK_DEFAULT_RUNTIME_RESOURCESenvironment variable specifies the directory that contains these resources. This directory's location is determined entirely by Buck; the script should not assume the directory's location.

    The $BUCK_EXTERNAL_RUNTIME_RESOURCES variable is also defined. Resources that are targets from external cells are placed in this directory.

    The resources are also made available in a tree structure that mirrors their locations in the source and buck-out trees. The environment variable $BUCK_PROJECT_ROOT specifies a directory that contains all the resources, laid out in their locations relative to the original buck project root.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().

Examples

This sh_binary() just cats a sample data file back at the user.

# $REPO/BUCK
sh_binary(
    name = "script",
    main = "script.sh",
    resources = [
        "data.dat",
    ],
)
# Sample data file with data we need at runtime
$ echo "I'm a datafile" > data.dat

# Create a simple script that prints out the resource
$ cat > script.sh
#!/bin/sh
cat $BUCK_DEFAULT_RUNTIME_RESOURCES/data.dat

# Make sure the script is executable
$ chmod u+x script.sh

# Run the script, and see that it prints out the resource we provided
$ buck run //:script
Building: finished in 1.9 sec (100%) 1/1 jobs, 1 updated
  Total time: 2.1 sec
I'm a datafile