Skip to content

Commit

Permalink
Emit warning on ShowEnvWriter::unset if environment variable exists
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 11, 2023
1 parent 2a61702 commit f421f58
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ impl<W: io::Write> EnvTarget for ShowEnvWriter<W> {
let prefix = if self.options.export_prefix { "export " } else { "" };
writeln!(self.target, r#"{prefix}{key}="{value}""#).context("failed to write env to stdout")
}
fn unset(&mut self, _key: &str) -> Result<()> {
fn unset(&mut self, key: &str) -> Result<()> {
if env::var_os(key).is_some() {
warn!("cannot unset environment variable `{key}`");
}
Ok(())
}
}
Expand Down Expand Up @@ -232,6 +235,7 @@ fn set_env(cx: &Context, env: &mut dyn EnvTarget, IsNextest(is_nextest): IsNexte
env.unset("CARGO_ENCODED_RUSTFLAGS")?;
}
_ => {
// First, try with RUSTFLAGS because `nextest` subcommand sometimes doesn't work well with encoded flags.
if let Ok(v) = rustflags.encode_space_separated() {
env.set("RUSTFLAGS", &v)?;
env.unset("CARGO_ENCODED_RUSTFLAGS")?;
Expand All @@ -242,6 +246,7 @@ fn set_env(cx: &Context, env: &mut dyn EnvTarget, IsNextest(is_nextest): IsNexte
}

if let Some(rustdocflags) = rustdocflags {
// First, try with RUSTDOCFLAGS because `nextest` subcommand sometimes doesn't work well with encoded flags.
if let Ok(v) = rustdocflags.encode_space_separated() {
env.set("RUSTDOCFLAGS", &v)?;
env.unset("CARGO_ENCODED_RUSTDOCFLAGS")?;
Expand Down

0 comments on commit f421f58

Please sign in to comment.