Skip to content

Conversation

@shivanshjais22
Copy link

This PR adds a simple, self-contained example demonstrating how to use
--workspace_status_command in the Bazel user manual.

It includes:

  • A small workspace status script example
  • Sample output explanation
  • A minimal genrule showing how to consume volatile status values during a build

This addresses the request in issue #17163 to make the documentation clearer
and easier for new users to understand.

Following the suggestion to proceed without formal assignment.
Fixes #17163

@google-cla
Copy link

google-cla bot commented Jan 28, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added team-Documentation Documentation improvements that cannot be directly linked to other team labels awaiting-review PR is awaiting review from an assigned reviewer labels Jan 28, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request adds an example for --workspace_status_command to the user manual. While adding an example is a great improvement, the current implementation has some issues with markdown formatting and clarity that could confuse users. I've provided a suggestion to restructure the example for better readability and correctness.

Comment on lines +1212 to +1237
#### Example

The following example shows how `--workspace_status_command` can be used
to generate build metadata and consume it during a build.

Create a workspace status script:

```sh
#!/usr/bin/env sh
echo "BUILD_USER $(whoami)"
echo "BUILD_TIMESTAMP $(date +%s)"

Make the script executable:
chmod +x status.sh


bazel build //:gen_metadata --workspace_status_command=./status.sh

genrule(
name = "gen_metadata",
outs = ["metadata.txt"],
cmd = "cat bazel-out/volatile-status.txt > $@",
stamp = 1,
)


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The example for --workspace_status_command has several issues that make it confusing and will cause rendering problems:

  1. Markdown Syntax Error: There is a missing closing ```` for the code block, which will cause the rest of the document to be rendered as code.
  2. Incorrect Content in Code Block: The sh code block contains user instructions (Make the script executable:) and a genrule definition (which is Python/Starlark syntax), neither of which are part of the shell script itself.
  3. Confusing Structure: The example mixes file content, shell commands, and build rule definitions without clear separation or explanation of how they relate. For instance, the bazel build command appears before the genrule it's supposed to build.

I've suggested a rewrite that structures the example as a clear, step-by-step guide and fixes the formatting issues.

#### Example

The following example shows how `--workspace_status_command` can be used
to generate build metadata and consume it during a build.

First, create a workspace status script named `status.sh`:

```sh
#!/usr/bin/env sh
echo "BUILD_USER $(whoami)"
echo "BUILD_TIMESTAMP $(date +%s)"

Next, make the script executable:

chmod +x status.sh

Then, create a BUILD file with a genrule that consumes the status information. The stamp = 1 attribute is required for the rule to see the status files.

genrule(
    name = "gen_metadata",
    outs = ["metadata.txt"],
    cmd = "cat bazel-out/volatile-status.txt > $@",
    stamp = 1,
)

Finally, run the build, pointing to your script with the --workspace_status_command flag:

bazel build //:gen_metadata --workspace_status_command=./status.sh

@iancha1992 iancha1992 added the team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob label Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Documentation Documentation improvements that cannot be directly linked to other team labels team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bazel.build] Problem with /docs/user-manual: would be nice to document how the output of --workspace_status_command can be used

2 participants