Understanding "inputs" parameter of Bazel "run" action

1.9k views Asked by At

I am writing a simple Bazel rule that uses ctx.actions.run. Unfortunately, I have a hard time understanding inputs param of run action.

The doc says inputs is "a list or depset of the input files of the action". What if my action just runs an executable and passes a few file paths as its arguments ? Suppose I specify the arguments as arguments parameter of the run action. Do I still need to add these file paths to the inputs parameter ? Why ?

1

There are 1 answers

0
ahumesky On BEST ANSWER

The inputs parameter tells Bazel what files to make available to the executable of the action when Bazel runs it. This parameter is important for a few reasons:

  1. It tells Bazel what other actions need to be run to produce the input files for the given action. If you have Action1 <- Artifact <- Action2, where Action2 produces Artifact, and Action1 takes Artifact as an input, Bazel knows to run Action2 before Action1.

  2. It tells Bazel what files to make available in the action sandbox. Otherwise the action won't be able to find any of its input files.

  3. It tells Bazel what files to upload to remote execution workers, if remote execution is being used. Otherwise the file won't be available on the remote machine for the action to read.

The arguments parameter of ctx.actions.run tells Bazel what the command line for the executable of the action is. If your executable takes flags like --input and --output, you'd use arguments to construct a command line like --input artifact1 --input artifact2 --output artifact3.

See this example: https://github.com/bazelbuild/examples/blob/master/rules/actions_run/execute.bzl