Skip to content

Commit aecfa0a

Browse files
xtask: Update command_to_string to exclude cleared env vars
Rather than maintaining a list of all variables cleared by `fix_nested_cargo_env`, just skip over all variables that are cleared by checking if the value is `Some`. That PATH var is still excluded by name since it's set (usually to a long value) rather than cleared.
1 parent 07938b6 commit aecfa0a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

xtask/src/util.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ use std::process::Command;
88
/// Example: "VAR=val program --arg1 arg2".
99
pub fn command_to_string(cmd: &Command) -> String {
1010
// Format env vars as "name=val".
11-
let ignore_var = ["PATH", "RUSTC", "RUSTDOC"];
1211
let mut parts = cmd
1312
.get_envs()
14-
// Filter out some internally-set variables that would just
15-
// clutter the output.
16-
.filter(|(name, _)| !ignore_var.contains(&name.to_str().unwrap_or_default()))
13+
// Filter out variables that are set or cleared by
14+
// `fix_nested_cargo_env`, as they would clutter the output.
15+
.filter(|(name, val)| {
16+
*name != "PATH"
17+
// Exclude any variables cleared with `Command::env_remove`.
18+
&& val.is_some()
19+
})
1720
.map(|(name, val)| {
1821
format!(
1922
"{}={}",
@@ -53,13 +56,10 @@ mod tests {
5356
#[test]
5457
fn test_command_to_string() {
5558
let mut cmd = Command::new("MyCommand");
56-
cmd.args(["abc", "123"]).envs([
57-
("VAR1", "val1"),
58-
("VAR2", "val2"),
59-
("PATH", "pathval"),
60-
("RUSTC", "rustcval"),
61-
("RUSTDOC", "rustdocval"),
62-
]);
59+
cmd.args(["abc", "123"])
60+
.envs([("VAR1", "val1"), ("VAR2", "val2"), ("PATH", "pathval")])
61+
.env_remove("RUSTC")
62+
.env_remove("CARGO");
6363
assert_eq!(
6464
command_to_string(&cmd),
6565
"VAR1=val1 VAR2=val2 MyCommand abc 123"

0 commit comments

Comments
 (0)