diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2020-06-01 00:22:29 +0200 |
|---|---|---|
| committer | Matthias Krüger <matthias.krueger@famsik.de> | 2020-06-11 12:34:19 +0200 |
| commit | 840786a93976d5885bfe6c7878cecc99e4a56432 (patch) | |
| tree | 7225f349817b607ffbc2e86ba05f84e44950a76c | |
| parent | 742706511c9f33c6a0d4380392e513e5249057e3 (diff) | |
| download | rust-840786a93976d5885bfe6c7878cecc99e4a56432.tar.gz rust-840786a93976d5885bfe6c7878cecc99e4a56432.zip | |
clippy-driver: pass all args after "--rustc" to rustc.
| -rw-r--r-- | src/driver.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/driver.rs b/src/driver.rs index 4453ae5ce44..1956effa827 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -297,12 +297,6 @@ pub fn main() { exit(rustc_driver::catch_with_exit_code(move || { let mut orig_args: Vec<String> = env::args().collect(); - if orig_args.iter().any(|a| a == "--version" || a == "-V") { - let version_info = rustc_tools_util::get_version_info!(); - println!("{}", version_info); - exit(0); - } - // Get the sysroot, looking from most specific to this invocation to the least: // - command line // - runtime environment @@ -348,6 +342,29 @@ pub fn main() { .map(|pb| pb.to_string_lossy().to_string()) .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); + // make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc" + // for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver + // uses + if let Some(pos) = orig_args.iter().position(|arg| arg == "--rustc") { + orig_args.remove(pos); + orig_args[0] = "rustc".to_string(); + + // if we call "rustc", we need to pass --sysroot here as well + let mut args: Vec<String> = orig_args.clone(); + if !have_sys_root_arg { + args.extend(vec!["--sysroot".into(), sys_root]); + }; + + println!("args: {:?}", args); + return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None); + } + + if orig_args.iter().any(|a| a == "--version" || a == "-V") { + let version_info = rustc_tools_util::get_version_info!(); + println!("{}", version_info); + exit(0); + } + // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. // We're invoking the compiler programmatically, so we ignore this/ let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref()); |
