英文:
How to force Bazel to stamp all binaries?
问题
--stamp
参数在Bazel用户手册中的文档中说明:
> 如果依赖项未更改,指定--stamp不会强制重新构建受影响的目标。
是否有一种方法可以强制构建受影响的目标,以便所有输出二进制文件都具有相同的标记,即使它们的依赖项未更改?
具体的用例是,我正在构建大量相关的Go二进制文件(使用rules_go),我希望可靠地为它们全部打上相同的版本号(取自最新的git提交哈希)。我可以在之前运行bazel clean
,但这在某种程度上违背了使用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!
答案1
得分: 1
你能将.git/refs/heads/<release branch>
文件添加为数据输入吗?这样当提交发生变化时,你的输入将会自动改变。你可以将它包装在一个genrule中,以添加一些检查或避免在开发分支上重新构建所有内容:
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
# 如果我们不在发布分支上,不要在提交时取消缓存。
echo "dev"
fi
""",
)
如果你感兴趣,可以跟踪/评论这个错误,它可以强制重新运行操作。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论