Public API for expanding variables ## expand_locations
expand_locations(ctx, input, targets)Expand location templates. Expands all `$(execpath ...)`, `$(rootpath ...)` and legacy `$(location ...)` templates in the given string by replacing with the expanded path. Expansion only works for labels that point to direct dependencies of this rule or that are explicitly listed in the optional argument targets. See https://docs.bazel.build/versions/main/be/make-variables.html#predefined_label_variables. Use `$(rootpath)` and `$(rootpaths)` to expand labels to the runfiles path that a built binary can use to find its dependencies. This path is of the format: - `./file` - `path/to/file` - `../external_repo/path/to/file` Use `$(execpath)` and `$(execpaths)` to expand labels to the execroot (where Bazel runs build actions). This is of the format: - `./file` - `path/to/file` - `external/external_repo/path/to/file` - `
[]
|
**RETURNS**
The expanded path or the original path
## expand_variables
expand_variables(ctx, s, outs, output_dir, attribute_name)Expand make variables and substitute like genrule does. This function is the same as ctx.expand_make_variables with the additional genrule-like substitutions of: - $@: The output file if it is a single file. Else triggers a build error. - $(@D): The output directory. If there is only one file name in outs, this expands to the directory containing that file. If there are multiple files, this instead expands to the package's root directory in the bin tree, even if all generated files belong to the same subdirectory! - $(RULEDIR): The output directory of the rule, that is, the directory corresponding to the name of the package containing the rule under the bin tree. See https://docs.bazel.build/versions/main/be/general.html#genrule.cmd and https://docs.bazel.build/versions/main/be/make-variables.html#predefined_genrule_variables for more information of how these special variables are expanded. **PARAMETERS** | Name | Description | Default Value | | :------------- | :------------- | :------------- | | ctx | starlark rule context | none | | s | expression to expand | none | | outs | declared outputs of the rule, for expanding references to outputs |
[]
|
| output_dir | whether the rule is expected to output a directory (TreeArtifact) | False
|
| attribute_name | name of the attribute containing the expression | "args"
|
**RETURNS**
s with the variables expanded