Add git commit hash to bazel builds #4035
Labels
api: spanner
Issues related to the Spanner API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
We try to stamp our builds with a "git commit hash". Here's how we get this info in our CMake builds. This info is exposed in C++ in the
g::c::s::internal::BuildMetadata()
function here.The problem is that it's unclear how to get this info from bazel, so currently our bazel builds always report a git hash of "unknown".
https://github.com/googleapis/google-cloud-cpp-spanner/blob/master/google/cloud/spanner/BUILD#L26
This issue is to try to do the following:
Figure out how to get the git commit hash (i.e.,
git rev-parse --short HEAD
) when running a bazel build. This should work when our library is built directly, AND when it's build as a dep of some other project.Some notes:
Running the
git
command directly in agenrule
doesn't work because it is executed in an environment without the.git/
directory structure. It might work to add.git/**
to thesrcs
attribute of thegenrule
, but I haven't tried this.Using bazel's
--workspace_status_command=
argument does work. Almost. It works when one specifies that flag. And we could add that flag to all of our bazel invocations by adding it to our.bazelrc
file. However, this would not get picked up and used when our project is a dep of another, which is probably the common case.Related to PR googleapis/google-cloud-cpp-spanner#278
The text was updated successfully, but these errors were encountered: