5

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?"

grandmasterj7
  • 51
  • 1
  • 2
  • Welcome to Stack Overflow! What have you tried so far? Please review [how-to-ask](https://stackoverflow.com/help/how-to-ask) and [how-to-create-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example) to help you to ask a good question, and thus get a good answer – Selim Yildiz Nov 21 '19 at 19:04

1 Answers1

2

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.

Brian Silverman
  • 3,085
  • 11
  • 13