Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force-rebuild a package in Bazel to measure build time

Tags:

bazel

I am currently trying to measure the time bazel build //api/... takes to build our "api" project with different --spawn_strategys. I am having a hard time doing so because Bazel doesn't rebuild anything as long as I don't touch the source files.

I was able to force rebuilds by editing all files inside our "api" project, but doing this repeatedly is cumbersome.

What is the best way to force Bazel to rebuild so that I can measure build times for our repository?

Preferably, I would like to use something like bazel build //api/... --some_option_which_forces_rebuilding or something similar.

like image 349
Vogelsgesang Avatar asked Nov 28 '19 20:11

Vogelsgesang


People also ask

What does Bazel clean -- expunge do?

Bazel expunge will remove all downloaded artifacts.

How do you debug a Bazel build?

Debugging Bazel To debug the C++ client, run it from gdb or lldb as usual. However, to debug Java code, attach to the server using the following: Run Bazel with the debugging option --host_jvm_debug before the command (such as bazel --host_jvm_debug build //src:bazel ). Attach a debugger to the port 5005.

Where is Bazelrc?

On Linux/macOS/Unixes: /etc/bazel. bazelrc. On Windows: %ProgramData%\bazel.

Where does Bazel build output?

The Bazel user's build state is located beneath outputRoot/_bazel_$USER . This is called the outputUserRoot directory. Beneath the outputUserRoot directory there is an install directory, and in it is an installBase directory whose name is the MD5 hash of the Bazel installation manifest.


Video Answer


1 Answers

A bit dirty, but you could use --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.

also (from 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).

Just setting a random variable should be enough:

> bazel build --action_env="avariable=1" :mytarget
> bazel build --action_env="avariable=2" :mytarget
> ...
like image 126
dms Avatar answered Oct 18 '22 10:10

dms