-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
subst.bzl
44 lines (42 loc) · 1.2 KB
/
subst.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Generate files from templates with substitutions."""
def _subst_template_impl(ctx):
"""Implementation of substitution from template."""
output = ctx.actions.declare_file(ctx.label.name)
ctx.actions.expand_template(
template = ctx.file.src,
output = output,
substitutions = ctx.attr.substitutions,
)
runfiles = ctx.runfiles(files = [output])
files = depset([output])
if ctx.attr.executable:
return [
DefaultInfo(
executable = output,
runfiles = runfiles,
),
]
else:
return [
DefaultInfo(
files = files,
runfiles = runfiles,
),
]
subst_template = rule(
implementation = _subst_template_impl,
attrs = {
"src": attr.label(
doc = "Source template to generate from.",
mandatory = True,
allow_single_file = True,
),
"substitutions": attr.string_dict(
doc = "Substitutions to apply to the template",
),
"executable": attr.bool(
default = False,
doc = "Set if the substitution is an executable.",
),
},
)