@@ -20,7 +20,7 @@ use std::path::PathBuf;
2020use std::process::{Child, Command};
2121use std::time::Instant;
2222
23- use dylib_util::{dylib_path, dylib_path_var};
23+ use dylib_util::{dylib_path, dylib_path_var, exe };
2424
2525#[path = "../utils/bin_helpers.rs"]
2626mod bin_helpers;
@@ -29,8 +29,10 @@ mod bin_helpers;
2929mod dylib_util;
3030
3131fn main() {
32- let args = env::args_os().skip(1).collect::<Vec<_>>();
33- let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
32+ let orig_args = env::args_os().skip(1).collect::<Vec<_>>();
33+ let mut args = orig_args.clone();
34+ let arg =
35+ |name| orig_args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
3436
3537 let verbose = bin_helpers::parse_rustc_verbose();
3638
@@ -54,12 +56,33 @@ fn main() {
5456 let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
5557 let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);
5658
57- let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
59+ let rustc_real = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
5860 let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
5961 let mut dylib_path = dylib_path();
6062 dylib_path.insert(0, PathBuf::from(&libdir));
6163
62- let mut cmd = Command::new(rustc);
64+ // if we're running clippy, trust cargo-clippy to set clippy-driver appropriately (and don't override it with rustc).
65+ // otherwise, substitute whatever cargo thinks rustc should be with RUSTC_REAL.
66+ // NOTE: this means we ignore RUSTC in the environment.
67+ // FIXME: We might want to consider removing RUSTC_REAL and setting RUSTC directly?
68+ let target_name = target
69+ .map(|s| s.to_owned())
70+ .unwrap_or_else(|| env::var("CFG_COMPILER_HOST_TRIPLE").unwrap());
71+ let is_clippy = args[0].to_string_lossy().ends_with(&exe("clippy-driver", &target_name));
72+ let rustc_driver = if is_clippy {
73+ args.remove(0)
74+ } else {
75+ args.remove(0);
76+ rustc_real
77+ };
78+
79+ let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER_REAL") {
80+ let mut cmd = Command::new(wrapper);
81+ cmd.arg(rustc_driver);
82+ cmd
83+ } else {
84+ Command::new(rustc_driver)
85+ };
6386 cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
6487
6588 // Get the name of the crate we're compiling, if any.
0 commit comments