Command debug printing prints the environment these days, we can kill some custom debugging code
This commit is contained in:
parent
27377cbd8b
commit
7fc0cbb02a
@ -1,7 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fmt::Write as _;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, BufWriter, Read, Write};
|
use std::io::{self, BufWriter, Read, Write};
|
||||||
use std::ops::Not;
|
use std::ops::Not;
|
||||||
@ -247,46 +245,10 @@ pub fn local_crates(metadata: &Metadata) -> String {
|
|||||||
local_crates
|
local_crates
|
||||||
}
|
}
|
||||||
|
|
||||||
fn env_vars_from_cmd(cmd: &Command) -> Vec<(String, String)> {
|
|
||||||
let mut envs = HashMap::new();
|
|
||||||
for (key, value) in std::env::vars() {
|
|
||||||
envs.insert(key, value);
|
|
||||||
}
|
|
||||||
for (key, value) in cmd.get_envs() {
|
|
||||||
if let Some(value) = value {
|
|
||||||
envs.insert(key.to_string_lossy().to_string(), value.to_string_lossy().to_string());
|
|
||||||
} else {
|
|
||||||
envs.remove(&key.to_string_lossy().to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut envs: Vec<_> = envs.into_iter().collect();
|
|
||||||
envs.sort();
|
|
||||||
envs
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Debug-print a command that is going to be run.
|
/// Debug-print a command that is going to be run.
|
||||||
pub fn debug_cmd(prefix: &str, verbose: usize, cmd: &Command) {
|
pub fn debug_cmd(prefix: &str, verbose: usize, cmd: &Command) {
|
||||||
if verbose == 0 {
|
if verbose == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only do a single `eprintln!` call to minimize concurrency interactions.
|
eprintln!("{prefix} running command: {cmd:?}");
|
||||||
let mut out = prefix.to_string();
|
|
||||||
writeln!(out, " running command: env \\").unwrap();
|
|
||||||
if verbose > 1 {
|
|
||||||
// Print the full environment this will be called in.
|
|
||||||
for (key, value) in env_vars_from_cmd(cmd) {
|
|
||||||
writeln!(out, "{key}={value:?} \\").unwrap();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Print only what has been changed for this `cmd`.
|
|
||||||
for (var, val) in cmd.get_envs() {
|
|
||||||
if let Some(val) = val {
|
|
||||||
writeln!(out, "{}={val:?} \\", var.to_string_lossy()).unwrap();
|
|
||||||
} else {
|
|
||||||
writeln!(out, "--unset={}", var.to_string_lossy()).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write!(out, "{cmd:?}").unwrap();
|
|
||||||
eprintln!("{out}");
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user