Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bazel cacheing of compilation / test failures?

Tags:

bazel

When compilation succeeds or a test passes, Bazel caches the result so if we repeat the build / test with the exact same code we get the result immediately.

That's great.

However, if the compilation fails - and I repeat the build with the exact same code - Bazel will attempt to recompile the code (and will fail again, with the exact same result)

Same for tests - if a test fails, and I rerun the test with the exact same code - Bazel will repeat the test.

Is there a way to tell Bazel to cache test / compilation failures as well as successes?


Usecase example:

  • I changed a lot of code in multiple files
  • I run bazel test //...:all
  • 100 tests run, 4 different tests fail
  • I fix the code of one of the tests and rerun bazel test //...:all
  • All the failing tests run again, even though 3 of the failing tests have no dependency change and there's no point rerunning them
  • I have to wait 4x longer than necessary for the tests to finish, and I'm sad :(

Something similar for the build failures. Sometimes a failed build can take many minutes to run on our codebase. If I rebuild without changing the files - it's a waste of time for bazel to rerun the failing build if it can use the cache...

like image 208
rabensky Avatar asked Dec 05 '25 16:12

rabensky


2 Answers

I can see why this might be useful, but I'm not aware of a flag or other option that does something like this. At least in the case of a failing test, Bazel re-runs the failed test even if the inputs haven't changed to account for flaky tests. I suppose the same could be said for actions (a flaky compiler sounds pretty scary though). You might consider filing a feature request: https://github.com/bazelbuild/bazel/issues.

My advice would be to test only the specific target you're working on after running //...:all. You can also combine that with --test_filter to test only a specific test method within the test target.

like image 145
ahumesky Avatar answered Dec 10 '25 06:12

ahumesky


Partial answer:

If we want to cache test failures, we can add --cache_test_results=yes (as opposed to the default auto which only caches successes). Personally, I've added it to my .bazelrc...

I haven't found a way to cache compilation failures yet, unfortunately...

like image 40
rabensky Avatar answered Dec 10 '25 08:12

rabensky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!