matt b
matt b

Reputation: 139931

Why does Bazel do a full rebuild whenever switching between IntelliJ and command-line?

For the same project, I work both in the Bazel IntelliJ plugin and the command-line.

Whenever I re "Sync Project with BUILD files" from within IntelliJ, or do a new bazel build from the command-line, whichever one I have done last forces the other one to do a full rebuild of my project (with 100s of targets).

For example, if I run a test from within IntelliJ, and then do something from the command line like bazel build //... or even run the same test from the CLI, I get:

$ bazel test //foo:bar
INFO: Build options have changed, discarding analysis cache.
...

which is forcing my project to rebuild Protobuf and other native things that are not quick.

Why is this?

I can see that when IntelliJ invokes a test, for example, it has this full set of arguments to the bazel command, which I never specify any of at the CLI:

/usr/local/bin/bazel test --tool_tag=ijwb:IDEA:ultimate \
--curses=no --color=yes --experimental_ui=no \
--progress_in_terminal_title=no --runs_per_test=1 \
--flaky_test_attempts=1 \
--build_event_binary_file=/var/folders/08/fk59w_xd4zz2phs6q6r3r5mc0000gn/T/intellij-bep-b37bc093-86b4-4a03-9599-a45e7285f6ac \
--nobuild_event_binary_file_path_conversion \
--test_filter=com.spotify.spyglass.knightcrock.CommitInfoParserTest# 
-- //knightcrock-consumer:CommitInfoParserTest

What I am experiencing is exactly what is described in https://github.com/bazelbuild/bazel/issues/3433, which was closed without much comment for being opened in the wrong place.

Upvotes: 7

Views: 4116

Answers (1)

ahumesky
ahumesky

Reputation: 5006

The specific option that's causing analysis to be rerun is --test_filter. The other options shouldn't affect the build configuration, so if you specify the same test filter on the command line, you shouldn't see analysis being rerun.

Fixing this so that not all analysis is rerun requires configuration trimming, which is a large effort that's actively being worked on.

Note though that only analysis should be rerunning. There's still a local action cache, so bazel should be noticing that not everything needs to actually be rebuilt. It might be good to confirm this by running with --subcommands to see what bazel runs when you try from the command line with a different --test_filter.

Also, it's probably worth filing an issue about printing which options caused the analysis cache to be dropped, so that it's easier to diagnose this sort of thing.

Upvotes: 2

Related Questions