Skip to main content
Version: 1.32.x

expand_template

Public API for expand template

Rules

expand_template

Template expansion

This performs a simple search over the template file for the keys in substitutions, and replaces them with the corresponding values.

Values may also use location templates as documented in expand_locations as well as configuration variables such as $(BINDIR), $(TARGET_CPU), and $(COMPILATION_MODE) as documented in expand_variables.

Example usage (generated):

load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")

expand_template(
# A unique name for this target.
name = "",
# Where to write the expanded file.
out = "",
# The template file to expand.
template = "",
)

name

Required name.

A unique name for this target.

data

Optional list of labels. Default: []

List of targets for additional lookup information.

is_executable

Optional boolean. Default: False

Whether to mark the output file as executable.

out

Required label.

Where to write the expanded file.

stamp

Optional integer. Default: -1

Whether to encode build information into the output. Possible values:

  • stamp = 1: Always stamp the build information into the output, even in --nostamp builds. This setting should be avoided, since it is non-deterministic. It potentially causes remote cache misses for the target and any downstream actions that depend on the result.
  • stamp = 0: Never stamp, instead replace build information by constant values. This gives good build result caching.
  • stamp = -1: Embedding of build information is controlled by the --[no]stamp flag. Stamped targets are not rebuilt unless their dependencies change.

stamp_substitutions

Optional dictionary: String → String. Default: {}

Mapping of strings to substitutions.

There are overlayed on top of substitutions when stamping is enabled for the target.

Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target.

substitutions

Optional dictionary: String → String. Default: {}

Mapping of strings to substitutions.

Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target.

template

Required label.

The template file to expand.