如何迫使Bazel标记所有二进制文件?

The documentation for --stamp in the Bazel User Manual states:

Specifying --stamp does not force affected targets to be rebuilt, if their dependencies have not changed.

Is there a way to force affected targets to be built so that all output binaries have the same stamp, even if their dependencies have not changed?

The specific use case is that I'm building a large number of related Go binaries (using rules_go), and I'd like to reliably stamp them all with the same version number (taken from the latest git commit hash). I could do a bazel clean beforehand, but this somewhat defeats the point of using Bazel :)

Thanks!

Could you add the .git/refs/heads/<release branch> file as a data input? Then when the commit changes, your inputs will change "automatically." You could wrap it in a genrule to add some check or avoid rebuilding everything on the development branch:

genrule(
    name = "stamper",
    outs = ["stamper.out"],
    srcs = [
        ".git/HEAD",
        ".git/refs/heads/master",
    ],
    cmd = """
if [[ $$(cat $(location :.git/HEAD)) = "refs: refs/heads/<release branch>" ]]; then
  cat $(location :.git/refs/heads/master)
else
  # If we're not on the release branch, don't uncache things on commit.
  echo "dev"  
fi
""",
)

There's a bug for forcing actions to be rerun that you could track/comment on, if interested.