bootstrap: Simplify absolute path handling - #160855
Conversation
|
|
|
I believe this simpler implementation handles all the useful cases imagined by the previous PRs, but I could use a second opinion in case there's something I overlooked. Specifically:
|
There was a problem hiding this comment.
This is indeed easier, thanks!
One thing that has changed though is that non-existing absolute paths no longer panic. I think that would be nice to keep, otherwise the path might get "too far" in bootstrap, and fail somewhere where the error message might be much less understandable.
Hmm yeah, it might be worth being more defensive here. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I added a check and early-exit for absolute paths that weren't resolved (diff). |
The existing code takes a command-line argument (that might not even be a path), glues it to the repository path, makes it absolute relative to the working directory, then tries to strip the repository path off again. That all seems needlessly complicated. The new approach is much simpler: If an argument is an absolute path that exists, try to strip the repository path from it, or otherwise change nothing. That should hopefully give the same results in every useful case.
|
Ok. The error can still a bit misleading in theory, but hopefully people will understand what it means. Thank you! @bors r+ rollup |
I agree that the error isn't great (which is why I tried to improve it), but in the end I didn't want the cleanup itself to get derailed by the harder problem of emitting good error messages. So for now I'll settle for not-worse. 😅 |
Rollup merge of #160855 - Zalathar:absolute, r=Kobzol bootstrap: Simplify absolute path handling The existing code takes a command-line argument (that might not even be a path), glues it to the repository path, makes it absolute relative to the working directory, then tries to strip the repository path off again. That all seems needlessly complicated. The new approach is much simpler: If an argument is an absolute path that exists, try to strip the repository path from it, or otherwise change nothing. That should hopefully give the same results in every useful case. --- Relevant earlier PRs: - #126782 - #146774 r? Kobzol (who last modified this code), or bootstrap
Fix handling of relative paths starting with a dot in bootstrap We missed this in rust-lang#160855. Fixes: rust-lang#160968 CC @Zalathar r? jieyouxu
The existing code takes a command-line argument (that might not even be a path), glues it to the repository path, makes it absolute relative to the working directory, then tries to strip the repository path off again.
That all seems needlessly complicated.
The new approach is much simpler: If an argument is an absolute path that exists, try to strip the repository path from it, or otherwise change nothing. That should hopefully give the same results in every useful case.
Relevant earlier PRs:
x <cmd> <path>from a different directory #146774r? Kobzol (who last modified this code), or bootstrap