Skip to content

Commit dc51e86

Browse files
committed
Command debug printing prints the environment these days, we can kill some custom debugging code
1 parent 147c8dc commit dc51e86

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

cargo-miri/src/util.rs

+1-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::collections::HashMap;
21
use std::env;
32
use std::ffi::OsString;
4-
use std::fmt::Write as _;
53
use std::fs::File;
64
use std::io::{self, BufWriter, Read, Write};
75
use std::ops::Not;
@@ -247,46 +245,10 @@ pub fn local_crates(metadata: &Metadata) -> String {
247245
local_crates
248246
}
249247

250-
fn env_vars_from_cmd(cmd: &Command) -> Vec<(String, String)> {
251-
let mut envs = HashMap::new();
252-
for (key, value) in std::env::vars() {
253-
envs.insert(key, value);
254-
}
255-
for (key, value) in cmd.get_envs() {
256-
if let Some(value) = value {
257-
envs.insert(key.to_string_lossy().to_string(), value.to_string_lossy().to_string());
258-
} else {
259-
envs.remove(&key.to_string_lossy().to_string());
260-
}
261-
}
262-
let mut envs: Vec<_> = envs.into_iter().collect();
263-
envs.sort();
264-
envs
265-
}
266-
267248
/// Debug-print a command that is going to be run.
268249
pub fn debug_cmd(prefix: &str, verbose: usize, cmd: &Command) {
269250
if verbose == 0 {
270251
return;
271252
}
272-
// We only do a single `eprintln!` call to minimize concurrency interactions.
273-
let mut out = prefix.to_string();
274-
writeln!(out, " running command: env \\").unwrap();
275-
if verbose > 1 {
276-
// Print the full environment this will be called in.
277-
for (key, value) in env_vars_from_cmd(cmd) {
278-
writeln!(out, "{key}={value:?} \\").unwrap();
279-
}
280-
} else {
281-
// Print only what has been changed for this `cmd`.
282-
for (var, val) in cmd.get_envs() {
283-
if let Some(val) = val {
284-
writeln!(out, "{}={val:?} \\", var.to_string_lossy()).unwrap();
285-
} else {
286-
writeln!(out, "--unset={}", var.to_string_lossy()).unwrap();
287-
}
288-
}
289-
}
290-
write!(out, "{cmd:?}").unwrap();
291-
eprintln!("{out}");
253+
eprintln!("{prefix} running command: {cmd:?}");
292254
}

0 commit comments

Comments
 (0)