如何在 Bazel 中强制重建包以测量构建时间
How to force-rebuild a package in Bazel to measure build time
我目前正在尝试测量 bazel build //api/...
使用不同的 --spawn_strategy
构建我们的 "api" 项目所花费的时间。
我很难这样做,因为只要我不接触源文件,Bazel 就不会重建任何东西。
我能够通过编辑我们 "api" 项目中的所有文件来强制重建,但重复这样做很麻烦。
强制 Bazel 重建以便我可以测量存储库的构建时间的最佳方法是什么?
最好,我想使用 bazel build //api/... --some_option_which_forces_rebuilding
或类似的东西。
有点脏,但你可以使用 --action_env
to change the build environment and invalidate all the actions. From the docs:
Environment variables are considered an essential part of an action. In other words, an action is expected to produce a different output, if the environment it is invoked in differs; in particular, a previously cached value cannot be taken if the effective environment changes.
还有(来自this page):
[...] The value of those environment variable can be enforced from the command line with the --action_env flag (but this flag will invalidate every action of the build).
只需设置一个随机变量就足够了:
> bazel build --action_env="avariable=1" :mytarget
> bazel build --action_env="avariable=2" :mytarget
> ...
如果删除 api
包及其子包的输出目录中的所有内容(应该在 bazel-bin
符号链接下),bazel 将重新运行 所有操作产生这些东西的,而不是 运行 任何在其他包中产生东西的动作。这也应该避免重新运行分析阶段,改变config_setting
s或--action_env
就可以了。
我目前正在尝试测量 bazel build //api/...
使用不同的 --spawn_strategy
构建我们的 "api" 项目所花费的时间。
我很难这样做,因为只要我不接触源文件,Bazel 就不会重建任何东西。
我能够通过编辑我们 "api" 项目中的所有文件来强制重建,但重复这样做很麻烦。
强制 Bazel 重建以便我可以测量存储库的构建时间的最佳方法是什么?
最好,我想使用 bazel build //api/... --some_option_which_forces_rebuilding
或类似的东西。
有点脏,但你可以使用 --action_env
to change the build environment and invalidate all the actions. From the docs:
Environment variables are considered an essential part of an action. In other words, an action is expected to produce a different output, if the environment it is invoked in differs; in particular, a previously cached value cannot be taken if the effective environment changes.
还有(来自this page):
[...] The value of those environment variable can be enforced from the command line with the --action_env flag (but this flag will invalidate every action of the build).
只需设置一个随机变量就足够了:
> bazel build --action_env="avariable=1" :mytarget
> bazel build --action_env="avariable=2" :mytarget
> ...
如果删除 api
包及其子包的输出目录中的所有内容(应该在 bazel-bin
符号链接下),bazel 将重新运行 所有操作产生这些东西的,而不是 运行 任何在其他包中产生东西的动作。这也应该避免重新运行分析阶段,改变config_setting
s或--action_env
就可以了。