Skip to content

Commit 914b0e5

Browse files
authored
Update docs to show $(var) usage and using ctx.var directly. (#621)
Add example of new ctx.var and $(var) usage in file names. Update common docs - fix since regexp - use 0.8.0 for since - remove unneeded load
1 parent de81967 commit 914b0e5

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

doc_build/common.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ These attributes are used in several rules within this module.
99
| Name | Description | Type | Mandatory | Default |
1010
| :------------- | :------------- | :-------------: | :-------------: | :------------- |
1111
| out | Name of the output file. This file will always be created and used to access the package content. If `package_file_name` is also specified, `out` will be a symlink. | String | required | |
12-
| package_file_name | The name of the file which will contain the package. The name may contain variables in the form `{var}`. The values for substitution are specified through `package_variables`. | String | optional | package type specific |
12+
| package_file_name | The name of the file which will contain the package. The name may contain variables in the forms `{var}` and $(var)`. The values for substitution are specified through `package_variables` or taken from [ctx.var](https://bazel.build/rules/lib/ctx#var). | String | optional | package type specific |
1313
| package_variables | A target that provides `PackageVariablesInfo` to substitute into `package_file_name`. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
1414
| attributes | Attributes to set on entities created within packages. Not to be confused with bazel rule attributes. See 'Mapping "Attributes"' below | Undefined. | optional | Varies. Consult individual rule documentation for details. |
1515

@@ -18,6 +18,10 @@ See
1818
for examples of how `out`, `package_file_name`, and `package_variables`
1919
interact.
2020

21+
@since(0.8.0): File name substitution now supports the $(var) syntax.
22+
@since(0.8.0): File name substitution now supports direct use of [ctx.var](https://bazel.build/rules/lib/ctx#var).
23+
24+
2125
<a name="mapping-attrs"></a>
2226
### Mapping "Attributes"
2327

doc_build/merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
ID_RE = re.compile(r'<a id="#(.*)">')
2727
WRAPS_RE = re.compile(r'@wraps\((.*)\)')
28-
SINCE_RE = re.compile(r'@since\((.*)\)')
28+
SINCE_RE = re.compile(r'@since\(([^)]*)\)')
2929
CENTER_RE = re.compile(r'<p align="center">([^<]*)</p>')
3030

3131

docs/latest.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ These attributes are used in several rules within this module.
3838
| Name | Description | Type | Mandatory | Default |
3939
| :------------- | :------------- | :-------------: | :-------------: | :------------- |
4040
| out | Name of the output file. This file will always be created and used to access the package content. If `package_file_name` is also specified, `out` will be a symlink. | String | required | |
41-
| package_file_name | The name of the file which will contain the package. The name may contain variables in the form `{var}`. The values for substitution are specified through `package_variables`. | String | optional | package type specific |
41+
| package_file_name | The name of the file which will contain the package. The name may contain variables in the forms `{var}` and $(var)`. The values for substitution are specified through `package_variables` or taken from [ctx.var](https://bazel.build/rules/lib/ctx#var). | String | optional | package type specific |
4242
| package_variables | A target that provides `PackageVariablesInfo` to substitute into `package_file_name`. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
4343
| attributes | Attributes to set on entities created within packages. Not to be confused with bazel rule attributes. See 'Mapping "Attributes"' below | Undefined. | optional | Varies. Consult individual rule documentation for details. |
4444

@@ -47,6 +47,10 @@ See
4747
for examples of how `out`, `package_file_name`, and `package_variables`
4848
interact.
4949

50+
<div class="since"><i>Since 0.8.0</i></div>: File name substitution now supports the $(var) syntax.
51+
<div class="since"><i>Since 0.8.0</i></div>: File name substitution now supports direct use of [ctx.var](https://bazel.build/rules/lib/ctx#var).
52+
53+
5054
<a name="mapping-attrs"></a>
5155
### Mapping "Attributes"
5256

examples/naming_package_files/BUILD

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,43 @@ pkg_tar(
8181
)
8282

8383
#
84-
# names_from_toolchains() extracts variables from the CC toolchain.
84+
# names_from_toolchains() extracts variables from the CC toolchain, like `compiler`.
8585
#
8686
names_from_toolchains(
8787
name = "toolchain_vars",
8888
)
8989

9090
pkg_tar(
91-
name = "example3",
91+
name = "using_toolchain_elements",
9292
srcs = [
9393
":BUILD",
9494
],
95-
package_file_name = "example3-{cc_cpu}-{compiler}-{compilation_mode}.tar",
95+
package_file_name = "example-{cc_cpu}-{compiler}-{compilation_mode}.tar",
9696
package_variables = ":toolchain_vars",
9797
)
9898

99+
#
100+
#
101+
#
102+
pkg_tar(
103+
name = "using_variable_from_ctx_var",
104+
srcs = [
105+
":BUILD",
106+
],
107+
package_file_name = "using_variable_from_ctx_var-{TARGET_CPU}-{COMPILATION_MODE}.tar",
108+
)
109+
110+
#
111+
# We can also use the familiar $(var) syntax.
112+
#
113+
pkg_tar(
114+
name = "using_make_variable_syntax",
115+
srcs = [
116+
":BUILD",
117+
],
118+
package_file_name = "using_make_variable_syntax-$(TARGET_CPU)-$(COMPILATION_MODE).tar",
119+
)
120+
99121
#
100122
# Demonstrate how the .changes file defaults based on package_file_name.
101123
#

0 commit comments

Comments
 (0)