Skip to main content
Module providing functions to create actions. Access this module using ctx.actions.

Members

args

Returns an Args object that can be used to build memory-efficient command lines.

declare_directory

Declares that the rule or aspect creates a directory with the given name, in the current package. You must create an action that generates the directory. The contents of the directory are not directly accessible from Starlark, but can be expanded in an action command with Args.add_all(). Only regular files and directories can be in the expanded contents of a declare_directory.

Parameters

declare_file

Declares that the rule or aspect creates a file with the given filename. If sibling is not specified, the file name is relative to the package directory, otherwise the file is in the same directory as sibling. Files cannot be created outside of the current package. Remember that in addition to declaring a file, you must separately create an action that emits the file. Creating that action will require passing the returned File object to the action’s construction function. Note that predeclared output files do not need to be (and cannot be) declared using this function. You can obtain their File objects from ctx.outputs instead. See example of use.

Parameters

Declares that the rule or aspect creates a symlink with the given name in the current package. You must create an action that generates this symlink. Bazel will never dereference this symlink and will transfer it verbatim to sandboxes or remote executors. Symlinks inside tree artifacts are not currently supported.

Parameters

do_nothing

Creates an empty action that neither executes a command nor produces any output, but that is useful for inserting ‘extra actions’.

Parameters

expand_template

Creates a template expansion action. When the action is executed, it will generate a file based on a template. Parts of the template will be replaced using the substitutions dictionary, in the order the substitutions are specified. Whenever a key of the dictionary appears in the template (or a result of a previous substitution), it is replaced with the associated value. There is no special syntax for the keys. You may, for example, use curly braces to avoid conflicts (for example, {KEY}). See example of use.

Parameters

map_directory

Creates multiple actions based on the files within one or more input directories, to output one or more output directories.

Parameters

run

Creates an action that runs an executable. See example of use.

Parameters

run_shell

Creates an action that runs a shell command. See example of use.

Parameters

Creates an action that writes a symlink in the file system. This function must be called with exactly one of target_file or target_path specified. When you use target_file, declare output with declare_file() or declare_directory() and match the type of target_file. This makes the symlink point to target_file. Bazel invalidates the output of this action whenever the target of the symlink or its contents change. Otherwise, when you use target_path, declare output with declare_symlink()). In this case, the symlink points to target_path. Bazel never resolves the symlink and the output of this action is invalidated only when the text contents of the symlink (that is, the value of readlink()) changes. In particular, this can be used to create a dangling symlink.

Parameters

template_dict

Returns a TemplateDict object for memory-efficient template expansion.

write

Creates a file write action. When the action is executed, it will write the given content to a file. This is used to generate files using information available in the analysis phase. If the file is large and with a lot of static content, consider using expand_template.

Parameters