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

Fix _virtual_includes handling for absolute strip_include_prefix paths #5969

Merged

Conversation

sfc-gh-abalik
Copy link
Contributor

@sfc-gh-abalik sfc-gh-abalik commented Jan 19, 2024

Checklist

  • I have filed an issue about this change and discussed potential changes with the maintainers.
  • I have received the approval from the maintainers to make this change.
  • This is not a stylistic, refactoring, or cleanup change.

Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.

Discussion thread for this change

Issue number: #5513

Description of this change

This change updates the VirtualIncludesHandler.java to detect if the stripPrefix is a repository-relative path (e.g. starts with '//') and if so, skips concatenating it to the package path. This enables CLion to find headers in targets that use repository-relative paths for strip_include_prefix.

I also fixed a small bug where the plugin raises an IllegalArgumentException when the strip_include_prefix ends with a '/'. To fix it we just need to trim the trailing '/' before creating the WorkspacePath object.

stripPrefix = stripPrefix.substring(0, stripPrefix.length() - 1);
}
String externalWorkspaceName = key.getLabel().externalWorkspaceName();
WorkspacePath stripPrefixWorkspacePath = stripPrefix.startsWith("//") ?
Copy link
Collaborator

@ujohnny ujohnny Jan 23, 2024

Choose a reason for hiding this comment

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

could you please make // a constant?

Copy link
Collaborator

@ujohnny ujohnny left a comment

Choose a reason for hiding this comment

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

Thank you for submitting the PR and my apologies that I wasn't able to check the issue earlier. There's already a test in ExecutionRootPathResolverTest, could you please add extra tests there that test both issues mentioned?

}
String externalWorkspaceName = key.getLabel().externalWorkspaceName();
WorkspacePath stripPrefixWorkspacePath = stripPrefix.startsWith("//") ?
new WorkspacePath(stripPrefix.substring(2)) :
Copy link
Collaborator

Choose a reason for hiding this comment

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

also could you please make 2 a constant as well

@sfc-gh-abalik sfc-gh-abalik force-pushed the abalik-fix-strip_include_prefix branch from 3421a98 to d556502 Compare January 25, 2024 04:47
@sfc-gh-abalik sfc-gh-abalik requested a review from ujohnny January 25, 2024 05:04
@sfc-gh-abalik
Copy link
Contributor Author

@ujohnny - I just pushed some commits to address feedback.

@sfc-gh-abalik
Copy link
Contributor Author

@ujohnny - Could you take a look at the updates? I believe I've addressed all the feedback.

Copy link
Collaborator

@ujohnny ujohnny left a comment

Choose a reason for hiding this comment

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

@ujohnny - Could you take a look at the updates? I believe I've addressed all the feedback.

My apologies for a little delay with reviews. Overall LGTM, though I spotted some caching issue that after upgrade to the version with the patch the header is still resolved incorrectly (from target with strip..//) unless I perform "Non-incremental sync".

@ujohnny ujohnny merged commit ef91e15 into bazelbuild:master Feb 8, 2024
6 checks passed
@github-actions github-actions bot removed the awaiting-review Awaiting review from Bazel team on PRs label Feb 8, 2024
@ujohnny
Copy link
Collaborator

ujohnny commented Feb 8, 2024

Just merged it and spotted a minor issue. Could you please submit a PR with this simple change?

Index: base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java b/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java
--- a/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java	(revision f3554378b44dbae5d4252a7b694f55b6eb2fa3c7)
+++ b/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java	(date 1707400715307)
@@ -102,7 +102,7 @@
             WorkspacePath stripPrefixWorkspacePath = stripPrefix.startsWith(ABSOLUTE_LABEL_PREFIX) ?
               new WorkspacePath(stripPrefix.substring(ABSOLUTE_LABEL_PREFIX_LENGTH)) :
               new WorkspacePath(key.getLabel().blazePackage(), stripPrefix);
-            if (key.getLabel().externalWorkspaceName() != null) {
+            if (externalWorkspaceName != null) {
                 ExecutionRootPath external = new ExecutionRootPath(
                     ExecutionRootPathResolver.externalPath.toPath()
                         .resolve(externalWorkspaceName)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants