about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-08-06 19:31:20 -0400
committerRalf Jung <post@ralfj.de>2022-08-06 19:42:32 -0400
commite12df0f4043f89bc59eb40e351fdb58f0b545abb (patch)
treea3861fec5fd196cff1f8adfe30eb9eb13c530ba0
parentf0cd09814bac7aff3259ff543bef5397743cd572 (diff)
downloadrust-e12df0f4043f89bc59eb40e351fdb58f0b545abb.tar.gz
rust-e12df0f4043f89bc59eb40e351fdb58f0b545abb.zip
also forward --manifest-path to 'cargo metadata'
-rw-r--r--cargo-miri/src/phases.rs1
-rw-r--r--cargo-miri/src/util.rs38
2 files changed, 22 insertions, 17 deletions
diff --git a/cargo-miri/src/phases.rs b/cargo-miri/src/phases.rs
index 4ba627de482..376b191192f 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<Item = String>) {
     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 d6a42a2f855..729794ed993 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<String> {
+    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);
+    }
+
+    // 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);
     }
 
-    let metadata =
-        MetadataCommand::new().no_deps().other_options(additional_options).exec().unwrap();
+    flags
+}
 
-    metadata
+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.