> ## Documentation Index
> Fetch the complete documentation index at: https://bazel-pr-31269.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# template_ctx {#modules.template_ctx}

A context object that is passed to the action template expansion function.

## Members

* [args](#args)
* [declare\_file](#declare_file)
* [declare\_subdirectory](#declare_subdirectory)
* [run](#run)

<h2 id="args">
  args
</h2>

```
Args template_ctx.args()
```

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

<h2 id="declare_file">
  declare\_file
</h2>

```
File template_ctx.declare_file(filename, *, directory)
```

Declares that implementation creates a file with the given filename within the specified directory.

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.

### Parameters

| Parameter | Description |
| - | - |
| `filename` | [string](../core/string); required  The relative path of the file within the directory. |
| `directory` | [File](../builtins/File); required  The directory in which the file should be created. |

<h2 id="declare_subdirectory">
  declare\_subdirectory
</h2>

```
File template_ctx.declare_subdirectory(subdirectory, *, directory)
```

Declares that implementation creates a subdirectory with the given name within the specified directory.

Remember that in addition to declaring a subdirectory, you must separately create an action that emits the subdirectory. Creating that action will require passing the returned `File` object to the action's construction function.

### Parameters

| Parameter | Description |
| - | - |
| `subdirectory` | [string](../core/string); required  The relative path of the subdirectory within the directory. |
| `directory` | [File](../builtins/File); required  The directory in which the subdirectory should be created. |

<h2 id="run">
  run
</h2>

```
None template_ctx.run(*, outputs, inputs=[], executable, tools=None, arguments=[], progress_message=None)
```

Creates an action that runs an executable.

### Parameters

| Parameter | Description |
| - | - |
| `outputs` | [sequence](../core/list) of [File](../builtins/File)s; required  List of the output files of the action. |
| `inputs` | [sequence](../core/list) of [File](../builtins/File)s; or [depset](../builtins/depset); default is `[]`  List or depset of the input files of the action. |
| `executable` | [File](../builtins/File); or [string](../core/string); or [FilesToRunProvider](../providers/FilesToRunProvider); required  The executable file to be called by the action. |
| `tools` | <a class="anchor" href="../core/list.html">sequence</a>; or <a class="anchor" href="../builtins/depset.html">depset</a>; or <code>None</code>;                                      default is <code>None</code><br />                           List or <a href="../builtins/depset.html"><code>depset</code></a> of any tools needed by the action. Tools are executable inputs that may have their own runfiles which are automatically made available to the action. <p> When a list is provided, it can be a heterogenous collection of: <ul> <li><code>File</code>s</li> <li><code>FilesToRunProvider</code> instances</li> <li><code>depset</code>s of <code>File</code>s</li> </ul> <code>File</code>s from <a href="../builtins/ctx#executable"><code>ctx.executable</code></a> and <code>FilesToRunProvider</code>s which are directly in the list will have their runfiles automatically added. All tools are implicitly added as inputs. </p> |
| `arguments` | [sequence](../core/list); default is `[]`  Command line arguments of the action. Must be a list of strings or [`actions.args()`](#args) objects. |
| `progress_message` | [string](../core/string); or `None`; default is `None`  Progress message to show to the user during the build. |
