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

Resolve external paths to their workspaces #4063

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

cpsauer
Copy link
Contributor

@cpsauer cpsauer commented Nov 1, 2022

Please see #2766 for context.
@sgowroji offered to shepherd.

String regexSep = Pattern.quote(f.separator);
// Workspace name defaults to __main__ per DEFAULT_REPOSITORY_DIRECTORY in
// https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/cmdline/LabelConstants.java
// Valid workspace name regex copied from LEGAL_WORKSPACE_NAME in
Copy link
Contributor Author

@cpsauer cpsauer Nov 1, 2022

Choose a reason for hiding this comment

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

If you all already know of a better way of referencing Bazel source from within the IntelliJ plugin, please say something. Ideally, it'd be good to reference LEGAL_WORKSPACE_NAME instead of duplicating the regex. (But of course, way better to fix the external workspaces then to block on this.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think there is a way to use LEGAL_WORKSPACE_NAME here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍🏻 Sounds like we proceed then. Figured I should ask, though :)

@mai93 mai93 assigned tpasternak and unassigned mai93 Dec 6, 2022
@mai93
Copy link
Collaborator

mai93 commented Dec 6, 2022

Reassigned to @tpasternak. I wonder if it will be safer to guard this change with an experiment to be gradually released, just to allow the users to opt-out of it in case it breaks anything.

@cpsauer
Copy link
Contributor Author

cpsauer commented Dec 8, 2022

Thanks for taking a look, and looking forward to working with you, @tpasternak.

[Totally up to you guys on flagging of course. But I thought I should note that this bug has been pretty widely fixed in the other Bazel IDE adaptors w/o incident. More in the issue, linked up top.]

@cpsauer
Copy link
Contributor Author

cpsauer commented Jan 3, 2023

Gentle bump @tpasternak, since it's been a good while and y'all explicitly asked me to post this one?

@tpasternak
Copy link
Collaborator

Sure, going to look at it, sorry for the delay

Copy link
Collaborator

@tpasternak tpasternak left a comment

Choose a reason for hiding this comment

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

So I think the diagnosis and the solution is correct.

The only thing I would prefer to avoid is the regex-based path replacement. What do you think about adding a new outputBase constructor parameter to ExecutionRootPathResolver and just calling path.getRootedAt(outputBase) instead of path.getRootedAt(executionRoot)?

This would IMO make it more consistent with other parts of code, where we make use of outputBase as well

@tpasternak tpasternak added awaiting-user-response Awaiting response from author on PRs and removed awaiting-review Awaiting review from Bazel team on PRs labels Jan 13, 2023
cpsauer added a commit to cpsauer/intellij that referenced this pull request Jan 31, 2023
…putBase)

Based on tpasternak's good feedback.
Please see bazelbuild#2766 and bazelbuild#4063 for context.
cpsauer added a commit to cpsauer/intellij that referenced this pull request Jan 31, 2023
…putBase)

Based on tpasternak's good feedback.
Please see bazelbuild#2766 and bazelbuild#4063 for context.
@cpsauer
Copy link
Contributor Author

cpsauer commented Jan 31, 2023

@tpasternak, that's definitely better. Done. Thanks for great feedback.
[The previous had just been a quick workaround to get folks back moving. Really appreciate your review and suggestions on how to improve it! Sorry for not being as quick as usual; got totally buried over the holidays.]

Some more minor notes:

  • If small things get in the way of merging, feel free to just modify to save a RTT. You should have access.
  • Had to break out the cases a little more finely for path resolution, so I simplified things by making it explicit that the main workspace was the fallback case. The actual case logic hasn't changed.
  • Separable/less important improvement opportunities I saw while editing, but didn't do:
    • BlazeConfigurationResolver's call to the ExecutionRootPathResolver constructor could be a call to ExecutionRootPathResolver .fromProject, but it's unclear to me whether it should really be taking the workspace root from the parameter in the calling function instead. Either way, the prior code probably isn't optimal, but it isn't clear which way to chance it without more context than I have. (But which you might have!)
    • This preserves the duplicated logic between buildArtifactDirectories and resolveToIncludeDirectories, with some expanded documentation. They could maybe be merged into a single function, but I'm not sure you'll gain that much cleanliness because of the different return types and workspace implementations. Up to you; feel free to do if you want.

Thanks!
Chris

…putBase)

Based on tpasternak's good feedback.
Please see bazelbuild#2766 and bazelbuild#4063 for context.
// Build artifacts accumulate under the execution root, independent of symlink settings
return path.getFileRootedAt(executionRoot);
}
if (firstPathComponent.equals("external")) { // In external workspace
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey, I'm not sure if I get it correctly, why do we need to modify resolveExecutionRootPath method? Isn't it enough just to modify resolveToIncludeDirectories? And is it possible that ExecutionRootPath starts from "external"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey hey! Thanks for taking another look, @tpasternak.

I'd think we'd need to modify execution root paths--and not just directories--because one might try to browse to an external file path. More generally, those execroot paths are unstable for all files, not just directories, so I'd think we'd always want to point to the stable paths, lest they disappear under the editor when a build gets run that uses different external workspaces. This ended up being important for Xcode/VSCode, anyway. I think this is a case we want to defend against. (Unless I'm misunderstanding your question; you all are the experts, immersed in this day-to-day.)

@tpasternak tpasternak merged commit 2837f42 into bazelbuild:master Feb 13, 2023
@tpasternak
Copy link
Collaborator

Thank you @cpsauer !

@cpsauer
Copy link
Contributor Author

cpsauer commented Feb 14, 2023

Yay! Thank you, @tpasternak!

cpsauer added a commit to hedronvision/bazelbuild-intellij that referenced this pull request Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-user-response Awaiting response from author on PRs product: IntelliJ IntelliJ plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants