Workspace status?

1,814 views
Skip to first unread message

Dan Fabulich

unread,
Mar 16, 2016, 7:55:10 PM3/16/16
to bazel-discuss
I need to incorporate git hash and build timestamp in my build output. https://github.com/bazelbuild/bazel/issues/216 seems relevant, but I don't understand it.

What is "workspace status"? How does it work? How can I feed workspace status information into my build outputs?

Brian Silverman

unread,
Mar 17, 2016, 12:05:27 AM3/17/16
to Dan Fabulich, bazel-discuss
For the git part, you set --workspace_status_command to a script which retrieves the information, and then Bazel can feed that information into build targets. tools/buildstamp/get_workspace_status in the Bazel source tree is a good example of retrieving the git hash, and Bazel supplies the timestamp automatically.

Retrieving the values is rule-specific. The rule types I've done that with are cc_library and genrule. You can set the linkstamp attribute of a cc_library to a .cc file which will have BUILD_SCM_REVISION and BUILD_TIMESTAMP defined to the appropriate values when it's compiled. For a genrule, if you set the stamp attribute to 1 it will be able to access bazel-out/volatile-status.txt which has the information. I've seen Bazel code for doing something with a .properties file for Java code, but I've never actually figured out how to use it.

On Wed, Mar 16, 2016 at 7:55 PM, Dan Fabulich <danfa...@gmail.com> wrote:
I need to incorporate git hash and build timestamp in my build output. https://github.com/bazelbuild/bazel/issues/216 seems relevant, but I don't understand it.

What is "workspace status"? How does it work? How can I feed workspace status information into my build outputs?

--
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/97e23591-f622-4eda-b7fe-bf63d6fcaef0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Fabulich

unread,
Mar 17, 2016, 1:47:38 PM3/17/16
to bazel-discuss, danfa...@gmail.com
http://bazel.io/docs/be/general.html#genrule doesn't say anything about "stamp." Is it documented somewhere? (Indeed, the documentation there says, "Do ensure that tools run by a genrule are deterministic and hermetic. They should not write timestamps to their output")

Does this mean users would have to launch bazel with "bazel build --workspace_status_command=status.py //:foo" every time they run it? Is there a way to check in a file that automatically specifies a workspace status command?

How could I access volatile-status.txt in a Skylark action?

Brian Silverman

unread,
Mar 17, 2016, 1:51:03 PM3/17/16
to Dan Fabulich, bazel-discuss
Yea, it's not documented... Rule with stamping are handled specially by Bazel to do the dependencies correctly.

You can write "build --workspace_status_command=./status.py" (FYI, the ./ is important) in a tools/bazel.rc to do it automatically.

I don't think there's currently a way to get at it directly from a Skylark action, but that would be useful.

Reply all
Reply to author
Forward
0 new messages