|
| 1 | +//! High-level overview of how `fix` works: |
| 2 | +//! |
| 3 | +//! The main goal is to run `cargo check` to get rustc to emit JSON |
| 4 | +//! diagnostics with suggested fixes that can be applied to the files on the |
| 5 | +//! filesystem, and validate that those changes didn't break anything. |
| 6 | +//! |
| 7 | +//! Cargo begins by launching a `LockServer` thread in the background to |
| 8 | +//! listen for network connections to coordinate locking when multiple targets |
| 9 | +//! are built simultaneously. It ensures each package has only one fix running |
| 10 | +//! at once. |
| 11 | +//! |
| 12 | +//! The `RustfixDiagnosticServer` is launched in a background thread (in |
| 13 | +//! `JobQueue`) to listen for network connections to coordinate displaying |
| 14 | +//! messages to the user on the console (so that multiple processes don't try |
| 15 | +//! to print at the same time). |
| 16 | +//! |
| 17 | +//! Cargo begins a normal `cargo check` operation with itself set as a proxy |
| 18 | +//! for rustc by setting `cargo_as_rustc_wrapper` in the build config. When |
| 19 | +//! cargo launches rustc to check a crate, it is actually launching itself. |
| 20 | +//! The `FIX_ENV` environment variable is set so that cargo knows it is in |
| 21 | +//! fix-proxy-mode. It also sets the `RUSTC` environment variable to the |
| 22 | +//! actual rustc so Cargo knows what to execute. |
| 23 | +//! |
| 24 | +//! Each proxied cargo-as-rustc detects it is in fix-proxy-mode (via `FIX_ENV` |
| 25 | +//! environment variable in `main`) and does the following: |
| 26 | +//! |
| 27 | +//! - Acquire a lock from the `LockServer` from the master cargo process. |
| 28 | +//! - Launches the real rustc (`rustfix_and_fix`), looking at the JSON output |
| 29 | +//! for suggested fixes. |
| 30 | +//! - Uses the `rustfix` crate to apply the suggestions to the files on the |
| 31 | +//! file system. |
| 32 | +//! - If rustfix fails to apply any suggestions (for example, they are |
| 33 | +//! overlapping), but at least some suggestions succeeded, it will try the |
| 34 | +//! previous two steps up to 4 times as long as some suggestions succeed. |
| 35 | +//! - Assuming there's at least one suggestion applied, and the suggestions |
| 36 | +//! applied cleanly, rustc is run again to verify the suggestions didn't |
| 37 | +//! break anything. The change will be backed out if it fails (unless |
| 38 | +//! `--broken-code` is used). |
| 39 | +//! - If there are any warnings or errors, rustc will be run one last time to |
| 40 | +//! show them to the user. |
| 41 | +
|
1 | 42 | use std::collections::{BTreeSet, HashMap, HashSet};
|
2 | 43 | use std::env;
|
3 | 44 | use std::ffi::OsString;
|
|
0 commit comments