forked from bazelbuild/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.bzl
33 lines (28 loc) · 1020 Bytes
/
execute.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
"""Create an executable with runfiles.
Runfiles are files that are needed at runtime (when the executable in run).
This example also shows a use of `ctx.expand_location`.
"""
def _impl(ctx):
# Expand the label in the command string to a runfiles-relative path.
# The second arg is the list of labels that may be expanded.
command = ctx.expand_location(ctx.attr.command, ctx.attr.data)
# Create the output executable file with command as its content.
ctx.actions.write(
output = ctx.outputs.executable,
content = command,
is_executable = True,
)
# Create runfiles from the files specified in the data attribute.
# The shell executable - the output of this rule - can use them at
# runtime.
return [DefaultInfo(
runfiles = ctx.runfiles(files = ctx.files.data),
)]
execute = rule(
implementation = _impl,
executable = True,
attrs = {
"command": attr.string(),
"data": attr.label_list(allow_files = True),
},
)