Skip to content

Instantly share code, notes, and snippets.

@benley
Created November 14, 2016 23:27
Show Gist options
  • Save benley/ed1bde34612a80e7fe4db81dbc9cc33f to your computer and use it in GitHub Desktop.
Save benley/ed1bde34612a80e7fe4db81dbc9cc33f to your computer and use it in GitHub Desktop.
"""gen_build_data: generate build_data from various templates.
This does something very simple: concatenates bazel's stable-status and
volatile-status linkstamp data with an optional header and footer.
"""
def _gen_build_data_impl(ctx):
cmd = ["cat"]
inputs = [
ctx.version_file, # volatile-status.txt
ctx.info_file, # stable-status.txt
]
if ctx.file.header:
cmd += [ctx.file.header.path]
inputs += [ctx.file.header]
cmd += [
ctx.version_file.path,
"<(echo)", # Add a newline in case version_file lacks one at the end
ctx.info_file.path,
"<(echo)", # Same for info_file
]
if ctx.file.footer:
cmd += [ctx.file.footer.path]
inputs += [ctx.file.footer]
cmd += [">", ctx.outputs.gen_src.path]
ctx.action(
inputs = inputs,
outputs = [ctx.outputs.gen_src],
command = " ".join(cmd),
mnemonic = "GenBuildData",
)
gen_build_data = rule(
_gen_build_data_impl,
attrs = {
"header": attr.label(allow_single_file = True),
"footer": attr.label(allow_single_file = True),
"out": attr.string(default = "%{name}"),
},
outputs = {"gen_src": "%{out}"},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment