Skip to content

Commit 7c61be6

Browse files
authored
Rollup merge of #5178 - matthiaskrgr:rustc_arg_pass, r=flip1995
clippy-driver: pass all args to rustc if --rustc is present changelog: clippy-driver: pass all args to rustc if --rustc is present
2 parents 4cc2fa9 + 7a62380 commit 7c61be6

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

.github/driver.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ unset CARGO_MANIFEST_DIR
2626
sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr
2727
diff normalized.stderr tests/ui/cstring.stderr
2828

29+
30+
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
31+
SYSROOT=`rustc --print sysroot`
32+
diff <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)
33+
34+
35+
echo "fn main() {}" > target/driver_test.rs
36+
# we can't run 2 rustcs on the same file at the same time
37+
CLIPPY=`LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc`
38+
RUSTC=`rustc ./target/driver_test.rs`
39+
diff <($CLIPPY) <($RUSTC)
40+
2941
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR

src/driver.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Usage:
207207
208208
Common options:
209209
-h, --help Print this message
210+
--rustc Pass all args to rustc
210211
-V, --version Print version info and exit
211212
212213
Other options are the same as `cargo check`.
@@ -297,12 +298,6 @@ pub fn main() {
297298
exit(rustc_driver::catch_with_exit_code(move || {
298299
let mut orig_args: Vec<String> = env::args().collect();
299300

300-
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
301-
let version_info = rustc_tools_util::get_version_info!();
302-
println!("{}", version_info);
303-
exit(0);
304-
}
305-
306301
// Get the sysroot, looking from most specific to this invocation to the least:
307302
// - command line
308303
// - runtime environment
@@ -348,6 +343,28 @@ pub fn main() {
348343
.map(|pb| pb.to_string_lossy().to_string())
349344
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
350345

346+
// make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc"
347+
// for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver
348+
// uses
349+
if let Some(pos) = orig_args.iter().position(|arg| arg == "--rustc") {
350+
orig_args.remove(pos);
351+
orig_args[0] = "rustc".to_string();
352+
353+
// if we call "rustc", we need to pass --sysroot here as well
354+
let mut args: Vec<String> = orig_args.clone();
355+
if !have_sys_root_arg {
356+
args.extend(vec!["--sysroot".into(), sys_root]);
357+
};
358+
359+
return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None);
360+
}
361+
362+
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
363+
let version_info = rustc_tools_util::get_version_info!();
364+
println!("{}", version_info);
365+
exit(0);
366+
}
367+
351368
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
352369
// We're invoking the compiler programmatically, so we ignore this/
353370
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());

0 commit comments

Comments
 (0)