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

bugfix: Fix the @@ prefix issue if bazel.module and WORKSPACE are used together #533

Closed
wants to merge 1 commit into from

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Feb 29, 2024

It's not uncommon to have both BAZEL.module file and WORKSPACE, in that case Bazel BSP will not detect all targets, or in case of the repository I am working on it would detect none of them.

There doesn't seem to be any actual way to discover if a target should have a @ or @@ prefix, so instead I changed the behaviour to replace @@ with @, which should work in most cases.

@tgodzik tgodzik marked this pull request as ready for review February 29, 2024 16:08
@tgodzik
Copy link
Contributor Author

tgodzik commented Feb 29, 2024

Ok, it seems this hasn't broken anything. Opinions? This is also related to https://youtrack.jetbrains.com/issue/BAZEL-863/Bazel-7.x-will-always-try-to-create-module.bazel

@agluszak
Copy link
Contributor

LGTM. I don't remember why we decided to use @@ here in the first place, but for context: https://bazel.build/external/overview#canonical-repo-name

@tgodzik
Copy link
Contributor Author

tgodzik commented Feb 29, 2024

Do we have a project in tests that only uses BAZEL.module? I think it should still work with the changes, since it would be very rare to have a target with @ and @@ in the same workspace as far as I can see.

in 0..3 -> throw RuntimeException("Unsupported Bazel version, use Bazel 4 or newer")
in 4..5 -> "//"
else ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was basically a guess previously, since the targets can come with @ and @@ within a single workspace.

@@ -68,7 +68,7 @@ class ProjectResolver(
val rootTargets = buildAspectResult.bepOutput.rootTargets().let { formatTargetsIfNeeded(it) }
val targets = measured(
"Parsing aspect outputs"
) { targetInfoReader.readTargetMapFromAspectOutputs(aspectOutputs) }
) { targetInfoReader.readTargetMapFromAspectOutputs(aspectOutputs).let { it.mapKeys { it.key.replace("@@", "@") } } }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we instead normalize anything to have single @, which should be safe since this seems to be only a target lookup structure.

@abrams27
Copy link
Member

with this change it's not possible to import this repo

@tgodzik
Copy link
Contributor Author

tgodzik commented Feb 29, 2024

with this change it's not possible to import this repo

How does it break though? I didn't think it would break anything that worked previously 🤔

Any other ideas how to fix this? The main problem is that we cannot know if a project should have @ or @@ inside bazel-bsp. Why isn't that saved when exporting via aspect?

@tgodzik
Copy link
Contributor Author

tgodzik commented Feb 29, 2024

If anyone needs a reproduction then https://github.com/susliko/metals-bazel should behave similarly to the private repo I am working on. We don't get any targets there be it Metals or Intellij.

@abrams27
Copy link
Member

How does it break though? I didn't think it would break anything that worked previously

there are places where we reference the id directly, so it's still with @@ there, but im not 100% sure will it still be enough (but prob it's worth a try)

@tgodzik tgodzik closed this Mar 1, 2024
@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 1, 2024

Created an alternative approach here #534 since something weird happened with this PR when I pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants