2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-26 13:30:30 +00:00
bazel-lib/docs/expand_template.md
2023-11-15 15:07:03 -08:00

5.3 KiB
Generated

Public API for expand template

expand_template_rule

expand_template_rule(name, data, is_executable, out, stamp, stamp_substitutions, substitutions,
                     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.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data List of targets for additional lookup information. List of labels optional []
is_executable Whether to mark the output file as executable. Boolean optional False
out Where to write the expanded file.

If unset, the template must be a source file and the output file will be named the same as the template file and outputted to the same workspace-relative path. In this case there will be no pre-declared label for the output file. It can be referenced by the target label instead. This pattern is similar to copy_to_bin but with substitutions on the copy.
Label optional
stamp 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.
Integer optional -1
stamp_substitutions 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.
Dictionary: String -> String optional {}
substitutions 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.
Dictionary: String -> String optional {}
template The template file to expand. Label required

expand_template

expand_template(name, template, kwargs)

Wrapper macro for expand_template_rule.

PARAMETERS

Name Description Default Value
name name of resulting rule none
template the label of a template file, or a list of strings which are lines representing the content of the template. none
kwargs other named parameters to expand_template_rule. none