mirror of https://github.com/rust-lang/rust.git
Merge pull request #2087 from Aaron1011/rustc_wrapper
Set RUSTC_WRAPPER instead of RUSTC when invoking Cargo
This commit is contained in:
commit
13caa00c93
18
src/main.rs
18
src/main.rs
|
@ -181,7 +181,7 @@ pub fn main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
if "clippy" == std::env::args().nth(1).as_ref().expect("cargo-clippy should be called with at least one argument!") {
|
||||||
// this arm is executed on the initial call to `cargo clippy`
|
// this arm is executed on the initial call to `cargo clippy`
|
||||||
|
|
||||||
let manifest_path_arg = std::env::args()
|
let manifest_path_arg = std::env::args()
|
||||||
|
@ -285,7 +285,7 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC`
|
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC_WRAPPER`
|
||||||
// env var set to itself
|
// env var set to itself
|
||||||
|
|
||||||
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
||||||
|
@ -310,13 +310,17 @@ pub fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
rustc_driver::in_rustc_thread(|| {
|
rustc_driver::in_rustc_thread(|| {
|
||||||
|
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
|
||||||
|
// We're invoking the compiler programatically, so we ignore this/
|
||||||
|
let orig_args: Vec<String> = env::args().skip(1).collect();
|
||||||
|
|
||||||
// this conditional check for the --sysroot flag is there so users can call
|
// this conditional check for the --sysroot flag is there so users can call
|
||||||
// `cargo-clippy` directly
|
// `cargo-clippy` directly
|
||||||
// without having to pass --sysroot or anything
|
// without having to pass --sysroot or anything
|
||||||
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
|
let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") {
|
||||||
env::args().collect()
|
orig_args.clone()
|
||||||
} else {
|
} else {
|
||||||
env::args()
|
orig_args.clone().into_iter()
|
||||||
.chain(Some("--sysroot".to_owned()))
|
.chain(Some("--sysroot".to_owned()))
|
||||||
.chain(Some(sys_root))
|
.chain(Some(sys_root))
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -325,7 +329,7 @@ pub fn main() {
|
||||||
// this check ensures that dependencies are built but not linted and the final
|
// this check ensures that dependencies are built but not linted and the final
|
||||||
// crate is
|
// crate is
|
||||||
// linted but not built
|
// linted but not built
|
||||||
let clippy_enabled = env::args().any(|s| s == "--emit=metadata");
|
let clippy_enabled = orig_args.iter().any(|s| s == "--emit=metadata");
|
||||||
|
|
||||||
if clippy_enabled {
|
if clippy_enabled {
|
||||||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
|
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
|
||||||
|
@ -361,7 +365,7 @@ where
|
||||||
let path = std::env::current_exe().expect("current executable path invalid");
|
let path = std::env::current_exe().expect("current executable path invalid");
|
||||||
let exit_status = std::process::Command::new("cargo")
|
let exit_status = std::process::Command::new("cargo")
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.env("RUSTC", path)
|
.env("RUSTC_WRAPPER", path)
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("could not run cargo")
|
.expect("could not run cargo")
|
||||||
.wait()
|
.wait()
|
||||||
|
|
Loading…
Reference in New Issue