Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing output base results in failed builds due to parsing the contents of the convenience symlinks #13951

Closed
adamporich opened this issue Sep 8, 2021 · 12 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Bazel General Bazel product/strategy issues type: bug

Comments

@adamporich
Copy link

Description of the problem / feature request:

When changing the output base. Bazel no longer recognizes the bazel-* symlinks as it's own and parses the contents resulting in build failues

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Example repo at https://github.com/adamporich/simple-bazel-test just consists of a single passing test.

> bazel --output_base=/tmp/bazel_1 test //...
INFO: Invocation ID: bda33659-6dbb-4d03-9f8f-fb273b5bafa9
INFO: Analyzed target //:test (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
Target //:test up-to-date:
  bazel-bin/test
INFO: Elapsed time: 0.075s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
//:test                                                         (cached) PASSED in 0.0s

Executed 0 out of 1 test: 1 test passes.
INFO: Build completed successfully, 1 total action

> bazel --output_base=/tmp/bazel_2 test //...
Starting local Bazel server and connecting to it...
INFO: Invocation ID: bb24dd33-6bbb-4c47-a943-ed4bfc65a34a
ERROR: error loading package 'bazel-bazel_symlink_test/external/bazel_tools/tools/cpp': in /home/gimo/dev/bazel_symlink_test/bazel-bazel_symlink_test/external/bazel_tools/tools/cpp/compiler_flag.bzl: Label '//tools/cpp:toolchain_utils.bzl' is invalid because 'tools/cpp' is not a package; perhaps you meant to put the colon here: '//:tools/cpp/toolchain_utils.bzl'?
INFO: Elapsed time: 1.998s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (8 packages loaded)
FAILED: Build did NOT complete successfully (8 packages loaded)

What operating system are you running Bazel on?

Above output is from Linux but occurs on Windows as well

What's the output of bazel info release?

> bazel info release
INFO: Invocation ID: 4d53a63f-daf5-43a2-b0ff-f3ab4927c52c
release 4.2.1

Have you found anything relevant by searching the web?

#11875 is a similar issue but in this case we don't need a root level glob to trigger

Any other information, logs, or outputs that you want to share?

I did try and use the https://docs.bazel.build/versions/4.2.1/command-line-reference.html#flag--experimental_convenience_symlinks option but it didn't seem to have an effect.

@dmivankov
Copy link
Contributor

looks related #10653

@gregestren gregestren added team-Rules-Server Issues for serverside rules included with Bazel type: bug untriaged labels Sep 13, 2021
@comius comius added team-Configurability Issues for Configurability team team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website and removed team-Rules-Server Issues for serverside rules included with Bazel labels Aug 26, 2022
@comius
Copy link
Contributor

comius commented Aug 26, 2022

Hey, I think output paths are more concern of Configurability team? Or perhaps OSS? Please triage.

brentleyjones added a commit to MobileNativeFoundation/rules_xcodeproj that referenced this issue Sep 1, 2022
And run them after spec validations, for quicker feedback on those.

And add a temp fix to `.bazelignore` to work around bazelbuild/bazel#13951.
@katre
Copy link
Member

katre commented Sep 1, 2022

I don't know if there's a good way to fix this, but I'll ask @gregestren to investigate when he's back.

@aiuto aiuto added team-Bazel General Bazel product/strategy issues P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed team-Configurability Issues for Configurability team team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website untriaged labels Sep 16, 2022
@aiuto
Copy link
Contributor

aiuto commented Sep 16, 2022

This is one of those things that just falls between the cracks. Not really Configurability or OSS.
I labeled it P3 on the grounds that it is not a common condition:

  • most projects don't build //... while changing --output-base frequently
  • you could just add bazel-* to .bazelignore

@brentleyjones
Copy link
Contributor

you could just add bazel-* to .bazelignore

It doesn't support wildcards though, right? #7093

@gregestren gregestren removed their assignment Sep 16, 2022
@aiuto
Copy link
Contributor

aiuto commented Sep 17, 2022 via email

@brentleyjones
Copy link
Contributor

brentleyjones commented Sep 18, 2022

There are only 4 to add if you know the workspace name. One is based on the name of the directory the workspace is placed in, which can be different for each user. And that is the one that has caused me the most issues so far, because of the external inside of it.

@aiuto
Copy link
Contributor

aiuto commented Sep 19, 2022 via email

@tpudlik
Copy link
Contributor

tpudlik commented Mar 1, 2023

Just ran into this issue, too. Should the documentation for --output_base mention that you need to add the bazel-* symlinks to .bazelignore to use this flag?

Are there any downsides to this workaround? It's not very clear to me what are the consequences of adding output directories to .bazelignore (I thought bazel would already ignore them by default!).

@aiuto
Copy link
Contributor

aiuto commented Mar 2, 2023

Changing the docs seems like a good step.
It seems though, like bazel should ignore symlinks in ... processing, regardless of them being used in output_base.
Or, I think that the use bazel test //... is weird. Most code immediately gets more complex than that so you don't want the same options for every tree.
As a very rare user of --output_base, and a non-user of //..., I don't have enough flight time with the problem to offer good solutions.

copybara-service bot pushed a commit to google/pigweed that referenced this issue Mar 2, 2023
A workaround for bazelbuild/bazel#13951 that
allows setting `--output_base=outbazel` while building with Bazel.

Change-Id: Ie024fff2a145f57d3767c270c512b1f3d110d9f8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/131612
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Ted Pudlik <tpudlik@google.com>
@cameron-martin
Copy link
Contributor

I labeled it P3 on the grounds that it is not a common condition:

most projects don't build //... while changing --output-base frequently
you could just add bazel-* to .bazelignore

This is a common thing for IDE extensions to do while syncing. It is recommened to use a different output base in the Bazel docs.

This looks like a duplication of #10653 anyway.

bazel-io pushed a commit to bazel-io/bazel that referenced this issue Feb 27, 2024
When the output base is changed after the convenience symlinks have been created, queries such as `//...` try to traverse into them and load them as packages since they are only excluded based on whether the resolved location is in the output base. This adds some heuristics to determine if a symlink is a convenience symlink:

1. The symlink name has an appropriate suffix.
2. An ancestor of the symlink target at the appropriate level is called `execroot`.
3. The `execroot` directory contains a file called `DO_NOT_BUILD_HERE`.

These heuristics should work if both the output base and the symlink prefix change while being quite robust to false positives.

This is important for IDE integration, where the [output base is often changed](https://bazel.build/run/scripts#output-base-option) for queries, to prevent concurrent builds from blocking them. An example of this is the vscode-bazel extension.

Fixes bazelbuild#10653
Fixes bazelbuild#13951

Closes bazelbuild#21005.

PiperOrigin-RevId: 610667735
Change-Id: I1869c9a2063f7f526950e48c0b1ee6efa89fd202
github-merge-queue bot pushed a commit that referenced this issue Mar 4, 2024
…21505)

When the output base is changed after the convenience symlinks have been
created, queries such as `//...` try to traverse into them and load them
as packages since they are only excluded based on whether the resolved
location is in the output base. This adds some heuristics to determine
if a symlink is a convenience symlink:

1. The symlink name has an appropriate suffix.
2. An ancestor of the symlink target at the appropriate level is called
`execroot`.
3. The `execroot` directory contains a file called `DO_NOT_BUILD_HERE`.

These heuristics should work if both the output base and the symlink
prefix change while being quite robust to false positives.

This is important for IDE integration, where the [output base is often
changed](https://bazel.build/run/scripts#output-base-option) for
queries, to prevent concurrent builds from blocking them. An example of
this is the vscode-bazel extension.

Fixes #10653
Fixes #13951

Closes #21005.

Commit
8f74ace

PiperOrigin-RevId: 610667735
Change-Id: I1869c9a2063f7f526950e48c0b1ee6efa89fd202

Co-authored-by: Cameron Martin <cameronmartin123@gmail.com>
Co-authored-by: Yun Peng <pcloudy@google.com>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.1.0 RC2. Please test out the release candidate and report any issues as soon as possible.
If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.1.0rc2. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Bazel General Bazel product/strategy issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants