From e12df0f4043f89bc59eb40e351fdb58f0b545abb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 6 Aug 2022 19:31:20 -0400 Subject: [PATCH] also forward --manifest-path to 'cargo metadata' --- cargo-miri/src/phases.rs | 1 + cargo-miri/src/util.rs | 38 +++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cargo-miri/src/phases.rs b/cargo-miri/src/phases.rs index 4ba627de482c..376b191192f4 100644 --- a/cargo-miri/src/phases.rs +++ b/cargo-miri/src/phases.rs @@ -117,6 +117,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator) { cmd.arg(cargo_cmd); // Forward all arguments before `--` other than `--target-dir` and its value to Cargo. + // (We want to *change* the target-dir value, so we must not forward it.) let mut target_dir = None; for arg in ArgSplitFlagValue::new(&mut args, "--target-dir") { match arg { diff --git a/cargo-miri/src/util.rs b/cargo-miri/src/util.rs index d6a42a2f855d..729794ed9930 100644 --- a/cargo-miri/src/util.rs +++ b/cargo-miri/src/util.rs @@ -287,29 +287,33 @@ pub fn write_to_file(filename: &Path, content: &str) { fs::rename(temp_filename, filename).unwrap(); } -pub fn get_cargo_metadata() -> Metadata { - // The `build.target-dir` config can be passed by `--config` flags, so forward them to - // `cargo metadata`. - let mut additional_options = Vec::new(); +// Computes the extra flags that need to be passed to cargo to make it behave like the current +// cargo invocation. +fn cargo_extra_flags() -> Vec { + let mut flags = Vec::new(); // `-Zunstable-options` is required by `--config`. - additional_options.push("-Zunstable-options".to_string()); + flags.push("-Zunstable-options".to_string()); + // Forward `--config` flags. let config_flag = "--config"; - for arg in ArgSplitFlagValue::new( - env::args().skip(3), // skip the program name, "miri" and "run" / "test" - config_flag, - ) - // Only look at `Ok` - .flatten() - { - additional_options.push(config_flag.to_string()); - additional_options.push(arg); + for arg in ArgFlagValueIter::new(config_flag) { + flags.push(config_flag.to_string()); + flags.push(arg); } - let metadata = - MetadataCommand::new().no_deps().other_options(additional_options).exec().unwrap(); + // Forward `--manifest-path`. + let manifest_flag = "--manifest-path"; + if let Some(manifest) = get_arg_flag_value(manifest_flag) { + flags.push(manifest_flag.to_string()); + flags.push(manifest); + } - metadata + flags +} + +pub fn get_cargo_metadata() -> Metadata { + // This will honor the `CARGO` env var the same way our `cargo()` does. + MetadataCommand::new().no_deps().other_options(cargo_extra_flags()).exec().unwrap() } /// Pulls all the crates in this workspace from the cargo metadata.