bazel: Change of --output_base causes subsequent builds to fail
Description of the problem / feature request:
Change in --output_base parameter causes the build to break with very obscure error messages.
Feature requests: what underlying problem are you trying to solve with this feature?
When build is done using some IDEs (VSCode or IntelliJ) they tend to set their own --output_base, different from the one configured by the user for the command line builds. This should not cause any problems, but unfortunately it appears that after --output_base changes the build is broken.
Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Select any simplest Bazel project. Build it with bazel --output_base=C:/blah1 build ... so it builds successfully. Then try to build it with bazel --output_base=C:/blah2 build ... this time it breaks with the error messages which don’t make any sense.
What operating system are you running Bazel on?
The problem does not seem to be OS dependent.
What’s the output of bazel info release?
2.0.0
Any other information, logs, or outputs that you want to share?
I figured that the problem is must probably caused by the stale “courtesy” symlink in WORKSPACE folder. After the first build Bazel creates “courtesy” symlink such as bazel-<workspace_name> in the workspace folder and it points inside output_base. When we issue second build command with the different output_base Bazel is smart enough to realize that and spawn second build server process, but unfortunately that stale bazel-<workspace_name> symlink still stays and points inside the old output_base which seems to confuse Bazel. Running bazel clean between builds or simply deleting of that symlink fixes the problem. It looks like when Bazel discovers the change in startup parameters which warrants spawning new build server it should at the same time remove existing courtesy symlinks as they are not valid anymore and cause the build to fail.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 28
- Comments: 18 (12 by maintainers)
Commits related to this issue
- Added .bazelignore for compatibility with VS Code. See https://github.com/bazelbuild/bazel/issues/10653#issuecomment-694230015 for explanation. — committed to odisseus/python-ascii-art by odisseus 5 years ago
- Workaround the VSCODE Bazel extension. See https://github.com/bazelbuild/bazel/issues/10653 — committed to jpwoodbu/ari-backup by jpwoodbu 3 years ago
- Ignore convenience symlinks when traversing build workspace. https://github.com/bazelbuild/bazel/issues/10653#issuecomment-694230015 — committed to sleexyz/puddlejumper by sleexyz 3 years ago
- Ignore convenience symlinks when traversing build workspace. https://github.com/bazelbuild/bazel/issues/10653#issuecomment-694230015 — committed to sleexyz/puddlejumper by sleexyz 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks, queries such as `//...` try to traverse into them and load them as packages... — committed to cameron-martin/bazel by cameron-martin 3 years ago
- Make queries share the same server by default (#270) The bazel query used to introspect the targets available incorrectly traverses convenience symlinks when the output base has changed. This is a bu... — committed to bazel-contrib/vscode-bazel by limdor 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and loa... — committed to cameron-martin/bazel by cameron-martin 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and loa... — committed to cameron-martin/bazel by cameron-martin 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and loa... — committed to cameron-martin/bazel by cameron-martin 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and loa... — committed to cameron-martin/bazel by cameron-martin 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and loa... — committed to bazel-io/bazel by cameron-martin 3 years ago
- Exclude convenience symlinks after changing the output base When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and loa... — committed to bazel-io/bazel by cameron-martin 3 years ago
- Add a workaround for https://github.com/bazelbuild/bazel/issues/10653 — committed to phst/rules_elisp by phst 3 years ago
- [7.1.0] Exclude convenience symlinks after changing the output base (#21505) When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse ... — committed to bazelbuild/bazel by bazel-io 3 years ago
- Revert "Add a workaround for https://github.com/bazelbuild/bazel/issues/10653" This reverts commit 535226922dae3b1351d2baee132585e2da3450f4. — committed to phst/rules_elisp by phst 2 years ago
- Revert "Add a workaround for https://github.com/bazelbuild/bazel/issues/10653" This reverts commit 535226922dae3b1351d2baee132585e2da3450f4. — committed to phst/rules_elisp by phst 2 years ago
The basic problem here is that the bazel-$WORKSPACE convenience symlink is blindly traversed by Bazel: you can even do
bazel build //bazel-$WORKSPACE/...and it will load the labels without any issues, and even build the targets there if you’re lucky. When you switch output bases, the symlinks are broken, but the fundamental issue is visiting that convenience symlink in the first place.My suggestion for a workaround for now is to do
echo "bazel-$WORKSPACE" >> .bazelignore. The .bazelignore file in the root of the workspace tells Bazel not to consider those directories. Of course, Bazel should be smart enough to not consider them on its own.cc @mhy1992
For those who are having this failure with the VSCode Bazel Extension with an error along the lines of:
For me, this problem was rectified by opening the VSCode Bazel extension settings, finding the “Queries Share Server” checkbox, and ensuring it is ticked (unticked by default).
The box has the description: “Use the same Bazel server for queries and builds. By default, vscode-bazel uses a separate server for queries so that they can be executed in parallel with builds. You can enable this setting if running multiple Bazel servers has a negative performance impact on your system, but you may experience degraded performance in Visual Studio Code for operations that require queries.”
I think the root cause is probably related to this issue, because (I think) to get the separate server the
--output_baseargument is provided, which then runs into the issue you describe here.Is anyone actively working on this? This is a pretty annoying bug that affects how e.g. Jenkins build nodes have to be spawned because the cannot handle multiple executors being isolated with
output_base. I’d be willing to investigate a fix but am not familiar enough with bazel’s codebase to even know where to start looking. Any pointers would be appreciated 😃For those coming from the future: You’ll also get this sort of error if the workspace name in your WORKSPACE file differs from the enclosing directory name.
e.g. if you have foo/WORKSPACE and that file contains ‘workspace(name=“bar”)’ you will get weird and confusing errors.
I found a workaround, but I don’t know why it works:
bazel-appecho "dummy" >| bazel-appfailed to create one or more convenience symlinks for prefix 'bazel-'I tried setting
--symlink_prefix,--experimental_use_sandboxfs, but it did not work. It’s as if ‘bazel-’ is hardcoded somewhere.I hope that helps.