Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver: print rustc --version --verbose on "clippy-driver rustc --version" #5166

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,30 @@ fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<Pat
})
}

fn print_rustc_version(args: &[String]) {
// make "clippy-driver rustc --version" print rustc --version output
if args.len() > 2 && args[1..2] == ["rustc".to_string(), "--version".to_string()] {
let rustc_version = Command::new("rustc")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there's no guarantee that there's a rustc in the path, or that if there is, it has anything to do with the version of clippy-driver we're running.

.arg("--version")
.arg("--verbose")
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.unwrap();
print!("{}", rustc_version);
exit(0);
}
}

pub fn main() {
rustc_driver::init_rustc_env_logger();
lazy_static::initialize(&ICE_HOOK);
exit(
rustc_driver::catch_fatal_errors(move || {
let mut orig_args: Vec<String> = env::args().collect();

print_rustc_version(&orig_args);

if orig_args.iter().any(|a| a == "--version" || a == "-V") {
let version_info = rustc_tools_util::get_version_info!();
println!("{}", version_info);
Expand Down