Skip to content

Instantly share code, notes, and snippets.

@jayeye
Created April 27, 2017 05:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jayeye/14c91816d10d5b899e1baaaaa9ba4848 to your computer and use it in GitHub Desktop.
Save jayeye/14c91816d10d5b899e1baaaaa9ba4848 to your computer and use it in GitHub Desktop.
stamping with build information. Obviously, replace _slash_ in the filenames with an actual slash!
from pprint import pprint
import buildinfo
pprint(buildinfo.buildinfo)
package(default_visibility = ["//visibility:public"])
genrule(
name = "genpybuildinfo",
outs = [
"buildinfo.py",
],
stamp = 1,
cmd = "./$(location tools/mkpybuildinfo.sh) > \"$@\"",
tools = [
"tools/mkpybuildinfo.sh",
],
)
py_library(
name = "buildinfo",
srcs = [
":genpybuildinfo",
],
)
# Use this for testing, remove in production!
py_binary(
name = "bi",
srcs = [
"bi.py",
],
deps = [
":buildinfo",
],
)
build --workspace_status_command=./tools/mkstamp.sh
#!/bin/sh
cat << @EOF
_status = '''
$(cat bazel-out/stable-status.txt bazel-out/volatile-status.txt)
'''
buildinfo = dict()
for l in _status.splitlines():
ll = l.strip().split(None, 1)
if len(ll) == 2:
buildinfo[ll[0]] = ll[1]
#!/bin/sh
echo BUILD_DATE $(TZ=Etc/UTC date -Iseconds)
echo BUILD_SCM_HASH $(git rev-parse HEAD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment