Skip to content

Commit

Permalink
Rollup merge of rust-lang#5178 - matthiaskrgr:rustc_arg_pass, r=flip1995
Browse files Browse the repository at this point in the history
clippy-driver: pass all args to rustc if --rustc is present

changelog: clippy-driver: pass all args to rustc if --rustc is present
  • Loading branch information
flip1995 authored Jun 23, 2020
2 parents 4cc2fa9 + 7a62380 commit 7c61be6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .github/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ unset CARGO_MANIFEST_DIR
sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr
diff normalized.stderr tests/ui/cstring.stderr


# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
SYSROOT=`rustc --print sysroot`
diff <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)


echo "fn main() {}" > target/driver_test.rs
# we can't run 2 rustcs on the same file at the same time
CLIPPY=`LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc`
RUSTC=`rustc ./target/driver_test.rs`
diff <($CLIPPY) <($RUSTC)

# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
29 changes: 23 additions & 6 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Usage:
Common options:
-h, --help Print this message
--rustc Pass all args to rustc
-V, --version Print version info and exit
Other options are the same as `cargo check`.
Expand Down Expand Up @@ -297,12 +298,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
Expand Down Expand Up @@ -348,6 +343,28 @@ 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]);
};

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());
Expand Down

0 comments on commit 7c61be6

Please sign in to comment.