Skip to content

bootstrap: Simplify absolute path handling - #160855

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Zalathar:absolute
Aug 11, 2026
Merged

bootstrap: Simplify absolute path handling#160855
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Zalathar:absolute

Conversation

@Zalathar

Copy link
Copy Markdown
Member

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:

r? Kobzol (who last modified this code), or bootstrap

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 10, 2026
@rustbot

rustbot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Kobzol is not on the review rotation at the moment.
They may take a while to respond.

@Zalathar

Zalathar commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

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:

  • Paths relative to the repository root, and arguments that aren't physical paths, should both continue to work regardless of working directory.
  • Absolute paths to files/directories in the repository root should be correctly stripped. Any other absolute path is passed-through as-is, and will likely lead to failure (as expected).

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

View changes since this review

@Zalathar

Copy link
Copy Markdown
Member Author

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.

@rustbot

rustbot commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

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.

@Zalathar

Copy link
Copy Markdown
Member Author

I added a check and early-exit for absolute paths that weren't resolved (diff).

Comment thread src/bootstrap/src/core/builder/cli_paths.rs Outdated
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.
@Kobzol

Kobzol commented Aug 11, 2026

Copy link
Copy Markdown
Member

Ok. The error can still a bit misleading in theory, but hopefully people will understand what it means. Thank you!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b531faf has been approved by Kobzol

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 11, 2026
@Zalathar

Copy link
Copy Markdown
Member Author

Ok. The error can still a bit misleading in theory, but hopefully people will understand what it means.

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. 😅

rust-bors Bot pushed a commit that referenced this pull request Aug 11, 2026
Rollup of 4 pull requests

Successful merges:

 - #159064 (Add offload support to the dist-x86_64-linux CI job)
 - #160746 (add regression tests for the fn sig ice)
 - #160855 (bootstrap: Simplify absolute path handling)
 - #160898 (Put `{:#?}` into backticks)
@rust-bors
rust-bors Bot merged commit b1ca78b into rust-lang:main Aug 11, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 11, 2026
rust-timer added a commit that referenced this pull request Aug 11, 2026
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
@Zalathar
Zalathar deleted the absolute branch August 12, 2026 01:35
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 12, 2026
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
rust-timer added a commit that referenced this pull request Aug 12, 2026
Rollup merge of #160970 - Kobzol:fix-paths, r=jieyouxu

Fix handling of relative paths starting with a dot in bootstrap

We missed this in #160855.

Fixes: #160968

CC @Zalathar

r? jieyouxu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants