I have a may-be-weird request for bazel to generate a binary with a build timestamp baked in.
In my Go program I can define a variable named "buildTime" and when compiling I can pass
-X main.buildTime=`date -u '+%Y%m%d-%I%M%S%Z'`
it then bake the current system time into the binary.
I know go_library doesn't support the X flag at right now (I can add the feature easily). But what's the best way to specify the time in a BUILD file? What I am looking for looks like:
go_binary(
name = "my_bin",
srcs = glob(["main.go"]),
x-def = [
"main.buildTime=$(date -u '+%Y%m%d-%I%M%S%Z')",
"main.commitID=$(git rev-parse --short HEAD)",
],
)
Is it possible?
Thanks!
genrule(name = "hello_gen",outs = ["hello.txt"],cmd = "echo hello world >$@",)
Do ensure that tools run by a genrule are deterministic and hermetic. They should not write timestamps to their output, and they should use stable ordering for sets and maps, as well as write only relative file paths to the output, no absolute paths. Not following this rule will lead to unexpected build behavior (Bazel not rebuilding a genrule you thought it would) and degrade cache performance. http://bazel.io/docs/be/general.html
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/310527b4-fd21-4b49-8e7a-2cbfa26ab302%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I fully understand and appreciate bazel's design principle on deterministic and hermetic. But, there are still use cases a build-time dependant value is useful. Above all, even bazel command itself supports "bazel version" which contains a build timestamp, right?
Thank you for the reply, Justine.
I fully understand and appreciate bazel's design principle on deterministic and hermetic. But, there are still use cases a build-time dependant value is useful. Above all, even bazel command itself supports "bazel version" which contains a build timestamp, right?
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0dff4941-de9a-4c6e-a609-752b3216aac1%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAKTZs%2BoY-2JxhCfyu9f1RBWKPB0te7%3DVpbkizjQ8mQAzuCaJHw%40mail.gmail.com.
Is it intended for the same purpose?
genrule(
name = "app_deploy",
srcs = ["app"],
outs = ["app_deploy"],
cmd = "sed -e s/XX:XX:XXTXX:XX:XXZ/$(TZ=UTC date +%Y-%m-%dT%H:%M:%SZ)/ <$< >$@",
executable = True,)
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/98d0ec18-8e19-4a01-b00f-36f496a0d663%40googlegroups.com.
rules_go has an unused attr "stamp": https://github.com/bazelbuild/rules_go/blob/master/go/def.bzl#L511
Is it intended for the same purpose?
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/21e4e0e2-976c-4269-917e-c5f3f766937e%40googlegroups.com.
Yes, we are on it: https://github.com/bazelbuild/rules_go/pull/27