From 914e483c89c9b1619001e2c9dcc75a53968da3e7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 8 May 2020 09:55:28 +0200 Subject: [PATCH] fix cargo-miri intercepting --help/--version arguments --- src/bin/cargo-miri.rs | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 1d93654e33e..4392cb93ddb 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -401,31 +401,6 @@ fn setup(subcommand: MiriCommand) { } } -fn main() { - // Check for version and help flags even when invoked as `cargo-miri`. - if std::env::args().any(|a| a == "--help" || a == "-h") { - show_help(); - return; - } - if std::env::args().any(|a| a == "--version" || a == "-V") { - show_version(); - return; - } - - if let Some("miri") = std::env::args().nth(1).as_deref() { - // This arm is for when `cargo miri` is called. We call `cargo check` for each applicable target, - // but with the `RUSTC` env var set to the `cargo-miri` binary so that we come back in the other branch, - // and dispatch the invocations to `rustc` and `miri`, respectively. - in_cargo_miri(); - } else if let Some("rustc") = std::env::args().nth(1).as_deref() { - // This arm is executed when `cargo-miri` runs `cargo check` with the `RUSTC_WRAPPER` env var set to itself: - // dependencies get dispatched to `rustc`, the final test/binary to `miri`. - inside_cargo_rustc(); - } else { - show_error(format!("must be called with either `miri` or `rustc` as first argument.")) - } -} - fn in_cargo_miri() { let (subcommand, skip) = match std::env::args().nth(2).as_deref() { Some("test") => (MiriCommand::Test, 3), @@ -593,3 +568,28 @@ fn is_runnable_crate() -> bool { Err(e) => panic!("error running {:?}:\n{:?}", command, e), } } + +fn main() { + // Check for version and help flags even when invoked as `cargo-miri`. + if has_arg_flag("--help") || has_arg_flag("-h") { + show_help(); + return; + } + if has_arg_flag("--version") || has_arg_flag("-V") { + show_version(); + return; + } + + if let Some("miri") = std::env::args().nth(1).as_deref() { + // This arm is for when `cargo miri` is called. We call `cargo check` for each applicable target, + // but with the `RUSTC` env var set to the `cargo-miri` binary so that we come back in the other branch, + // and dispatch the invocations to `rustc` and `miri`, respectively. + in_cargo_miri(); + } else if let Some("rustc") = std::env::args().nth(1).as_deref() { + // This arm is executed when `cargo-miri` runs `cargo check` with the `RUSTC_WRAPPER` env var set to itself: + // dependencies get dispatched to `rustc`, the final test/binary to `miri`. + inside_cargo_rustc(); + } else { + show_error(format!("must be called with either `miri` or `rustc` as first argument.")) + } +} -- 2.44.0