buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

Can you help me understand why running buildifier via Bazel takes so long?

Open ghost opened this issue 5 years ago • 4 comments

It appears like the protoc targets necessary to build buildifier go stale and I'm not quite sure why this is happening. It makes running buildifier via bazel very slow if you're only running it every ~5-10 minutes

ghost avatar Nov 21 '19 17:11 ghost

Often the cause of protobuf library rebuilding is environment variables changing, typically PATH. This can occur if you open a new terminal, for example. Newer versions of bazel are more resistant to this.

pcj avatar Dec 02 '19 20:12 pcj

I have this issue and most definitely don't have any variance in my environment variables. I'm also using Bazel v1.2.1.

Adding my comment from another issue:

Yeah, I have to agree that it's pretty annoying to have to wait for all 220+ protoc targets to build whenever the "sandbox goes stale" (I don't have metrics on this, but it seems to be every 5-10 minutes); I've never seen this message except when running //:buildifier just to format my Starlark files.

I want to be idiomatic and use Bazel to build buildifier, but I have to agree with @nrvnrvn; it seems much more reasonable to grab a binary (via go get or http_file()) than to wait the couple minutes (yes, minutes) every time I want to format.

Consider this; where bazel run //:buildifier is set up to execute in a pre-commit hook if WORKSPACE, BUILD, or BUILD.bazel files are detected:

➜ git commit
Formatting Bazel files...
INFO: Analyzed target //:buildifier (27 packages loaded, 595 targets configured).
INFO: Found 1 target...
Target //:buildifier up-to-date:
  bazel-bin/buildifier.bash
INFO: Elapsed time: 76.502s, Critical Path: 21.27s
INFO: 195 processes: 195 linux-sandbox.
INFO: Build completed successfully, 200 total actions
INFO: Build completed successfully, 200 total actions
[master 78c4c39] initial commit
...

sudoforge avatar Dec 03 '19 04:12 sudoforge

Does setting --incompatible_strict_action_env fix this issue? A solution from this thread: https://github.com/bazelbuild/bazel/issues/7095

Edit: it seems to work when this is set in bazelrc

jathu avatar Dec 05 '19 00:12 jathu

Since it appears that you're running buildifier as a githook, know that the PATH is different in your githook script, so you'd need to manage your action_env appropriately.

mariusgrigoriu avatar Jan 15 '20 19:01 mariusgrigoriu