forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootstrap: Add and use
-Z absolute-file-paths
It's unfortunate that this hack is necessary. A short summary of the background here: - Rust-Analyzer uses `x check --json-output` to show red underlines in the editor. - There are several different Cargo workspaces in rust-lang/rust, including src/bootstrap and src/tools/miri. - Cargo runs each invocation of rustc relative to the *workspace*, not to the current working directory of cargo itself. - Rustc prints file paths relative to its current working directory. As a result, it would print things like `config.rs:43:14` instead of `src/bootstrap/config.rs`. This adds a new flag to rustc to print the files as an absolute path instead of a relative path. I went with this approach instead of one of the wrapping tools for the following reasons: 1. Cargo considers changing the working directory to be a breaking change: rust-lang/cargo#11007 (comment). They have open feature requests for adding a flag to print absolute paths, but none have been implemented. 2. Bootstrap would potentially be able to parse and rewrite the paths that cargo emits, but I don't want to hard-code Cargo's JSON output format in both bootstrap.py and rustbuild; unlike rustbuild, bootstrap.py can't use `cargo_metadata` as a library. 3. Rust-Analyzer could potentially rewrite this output, but that wouldn't fix ctrl+click on the relative path when someone runs `cargo check`. In addition to adding and using the new flag, this also adds `local_rebuild` detection to bootstrap.py, so that I could test the change. Before: ``` error[E0425]: cannot find value `MIRI_DEFAULT_ARGS` in crate `miri` --> src/bin/miri.rs:269:33 | 269 | args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string)); | ^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `MIRI_DEFLT_ARGS` | ::: src/lib.rs:128:1 | 128 | pub const MIRI_DEFLT_ARGS: &[&str] = &[ | ---------------------------------- similarly named constant `MIRI_DEFLT_ARGS` defined here ``` After: ``` error[E0425]: cannot find value `MIRI_DEFAULT_ARGS` in crate `miri` --> /home/jyn/src/rust/src/tools/miri/src/bin/miri.rs:269:33 | 269 | args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string)); | ^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `MIRI_DEFLT_ARGS` | ::: /home/jyn/src/rust/src/tools/miri/src/lib.rs:128:1 | 128 | pub const MIRI_DEFLT_ARGS: &[&str] = &[ | ---------------------------------- similarly named constant `MIRI_DEFLT_ARGS` defined here ```
- Loading branch information
Showing
6 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/doc/unstable-book/src/compiler-flags/absolute-file-paths.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# `absolute-file-paths` | ||
|
||
This features is currently perma-unstable, with no tracking issue. | ||
|
||
------------------------ | ||
|
||
This feature allows you to configure rustc to print diagnostics and other output using absolute file paths, not relative file paths. | ||
|
||
Set `-Zabsolute-file-paths` to enable this feature. |