Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions stamping/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2022 Swift Navigation Inc.
# Contact: Swift Navigation <dev@swift-nav.com>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

exports_files(
glob(["*.bzl"]) + ["stamping.py"],
visibility = ["//visibility:public"],
)
35 changes: 35 additions & 0 deletions stamping/stamping.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def _stamping_impl(ctx):
file = ctx.version_file
tpl = ctx.file.template
out = ctx.actions.declare_file(ctx.attr.out)

args = ctx.actions.args()
args.add(file)
args.add(tpl)
args.add(out)

ctx.actions.run(
inputs = [file, tpl],
executable = ctx.executable.exec,
arguments = [args],
outputs = [out],
)

return [DefaultInfo(files = depset([out]))]

stamping = rule(
implementation = _stamping_impl,
attrs = {
"out": attr.string(),
"template": attr.label(
allow_single_file = [".in"],
mandatory = True,
),
"exec": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
default = "//stamping:stamping.py",
),
},
)
33 changes: 33 additions & 0 deletions stamping/stamping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

"""
Script for lulz.
"""

from string import Template

import argparse


def init() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("input")
parser.add_argument("template")
parser.add_argument("output")
return parser.parse_args()


def main() -> None:
args = init()
with open(args.input) as input, open(args.template) as tpl, open(
args.output, "w"
) as out:
subs = dict(
(line.split(" ")[0], line.split(" ")[1]) for line in input.readlines()
)
s = Template(tpl.read())
out.write(s.substitute(subs))


if __name__ == "__main__":
main()