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 ?
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: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
, whereAction2
producesArtifact
, andAction1
takesArtifact
as an input, Bazel knows to runAction2
beforeAction1
.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.
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 ofctx.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 usearguments
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