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

Store the package and name of a Label as strings rather than paths, to avoid occurrence of backslashes on Windows #7271

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

odisseus
Copy link
Contributor

@odisseus odisseus commented Feb 3, 2025

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: #7258

Description of this change

@github-actions github-actions bot added the awaiting-review Awaiting review from Bazel team on PRs label Feb 3, 2025
}
}

private static String withForwardSlashes(Path p) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

com.intellij.openapi.util.io.FileUtilRt#toSystemIndependentName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out not so easy to refactor. This package is pretty low in the dependency hierarchy, and it doesn't depend on the IntelliJ API.

@@ -57,17 +56,22 @@ public static Label of(String label) {
}

public static Label fromWorkspacePackageAndName(String workspace, Path packagePath, Path name) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

add test too, to see that it works with WindowsPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the subclass of java.nio.file.Path? Unfortunately, it only exists on Windows JVMs. However, I have verified manually that my changes fix the issue on Windows.

@@ -202,8 +202,8 @@ public int index(String s) {
public Query.StoredLabel indexLabel(Label l) {
return Query.StoredLabel.newBuilder()
.setWorkspace(index(l.getWorkspaceName()))
.setBuildPackage(index(l.getPackage().toString()))
.setName(index(l.getName().toString()))
.setBuildPackage(index(l.buildPackage()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I searched for getPackage() and subsequent call to toString that introduces backslashes and found

public Builder add(Label target) {

Copy link
Contributor Author

@odisseus odisseus Feb 7, 2025

Choose a reason for hiding this comment

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

I'm not sure this has any adverse effects (FWIW TargetTreeTest passes on Windows), but I will fix this just in case.

Copy link
Collaborator

@LeFrosch LeFrosch left a comment

Choose a reason for hiding this comment

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

Just tried to import our repository on windows with your changes and got this exception. Without your changes it was possible to import our repository (after removing excluded directories from the project view file).

image
idea.log

@odisseus odisseus force-pushed the issue-7258 branch 2 times, most recently from 4c01421 to 9bc1431 Compare February 12, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Awaiting review from Bazel team on PRs product: IntelliJ IntelliJ plugin
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

4 participants