mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-03-01 22:07:15 +00:00
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
This commit is contained in:
commit
7c61be615a
2 changed files with 35 additions and 6 deletions
12
.github/driver.sh
vendored
12
.github/driver.sh
vendored
|
@ -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
|
||||
|
|
|
@ -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`.
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue