The manual goes into the details of how you can stamp binaries (https://docs.bazel.build/versions/master/user-manual.html) with build information.
My question is "how can you read that information from a binary?"
The manual goes into the details of how you can stamp binaries (https://docs.bazel.build/versions/master/user-manual.html) with build information.
My question is "how can you read that information from a binary?"
It depends on what kind of binary you're talking about. Most of them are very poorly documented. I've worked out how to do it for some languages, mainly by reading the Bazel source code.
For C++, you set the (undocumented) linkstamp
attribute of a cc_library
to a .cc
file which will have BUILD_SCM_REVISION
, BUILD_TIMESTAMP
, and the rest defined to the appropriate values when it's compiled. bazelbuild/bazel#2893 is an open bug to document this better.
For a genrule
, you set the stamp
attribute to 1
, and then it can access bazel-out/volatile-status.txt
/bazel-out/stable-status.txt
with the information. bazelbuild/bazel#944 talks about this a bit.
I've seen Bazel code for doing something with a .properties
file for Java, but I've never actually figured out how to use it.