-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgenerate_file.bzl
More file actions
28 lines (24 loc) · 901 Bytes
/
generate_file.bzl
File metadata and controls
28 lines (24 loc) · 901 Bytes
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
# -*- python -*-
# Copied from the Drake project
# https://github.com/RobotLocomotion/drake/blob/17423f8fb6f292b4af0b4cf3c6c0f157273af501/tools/workspace/generate_file.bzl
def _generate_file_impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(out, ctx.attr.content, ctx.attr.is_executable)
return [DefaultInfo(
files = depset([out]),
data_runfiles = ctx.runfiles(files = [out]),
)]
generate_file = rule(
attrs = {
"content": attr.string(mandatory = True),
"is_executable": attr.bool(default = False),
},
output_to_genfiles = True,
implementation = _generate_file_impl,
)
"""Generate a file with specified content.
This creates a rule to generate a file with specified content (which is either
static or has been previously computed).
Args:
content (:obj:`str`): Desired content of the generated file.
"""