Skip to content

Commit

Permalink
handle empty string rustc wrapper envs (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tofay authored Feb 23, 2023
1 parent 8ad4c8d commit 1d7d634
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
47 changes: 43 additions & 4 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,40 @@ impl ApplyEnv for BuildConfig {
// 1. RUSTC_WRAPPER
// 2. build.rustc-wrapper (CARGO_BUILD_RUSTC_WRAPPER)
// https://doc.rust-lang.org/nightly/cargo/reference/config.html#buildrustc-wrapper
// Setting this to an empty string instructs cargo to not use a wrapper.
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
if let Some(rustc_wrapper) = cx.env("RUSTC_WRAPPER")? {
self.rustc_wrapper = Some(rustc_wrapper);
if rustc_wrapper.val.is_empty() {
self.rustc_wrapper = None;
} else {
self.rustc_wrapper = Some(rustc_wrapper);
}
} else if let Some(rustc_wrapper) = cx.env("CARGO_BUILD_RUSTC_WRAPPER")? {
self.rustc_wrapper = Some(rustc_wrapper);
if rustc_wrapper.val.is_empty() {
self.rustc_wrapper = None;
} else {
self.rustc_wrapper = Some(rustc_wrapper);
}
}
// 1. RUSTC_WORKSPACE_WRAPPER
// 2. build.rustc-workspace-wrapper (CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER)
// https://doc.rust-lang.org/nightly/cargo/reference/config.html#buildrustc-workspace-wrapper
// Setting this to an empty string instructs cargo to not use a wrapper.
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
if let Some(rustc_workspace_wrapper) = cx.env("RUSTC_WORKSPACE_WRAPPER")? {
self.rustc_workspace_wrapper = Some(rustc_workspace_wrapper);
if rustc_workspace_wrapper.val.is_empty() {
self.rustc_workspace_wrapper = None;
} else {
self.rustc_workspace_wrapper = Some(rustc_workspace_wrapper);
}
} else if let Some(rustc_workspace_wrapper) =
cx.env("CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER")?
{
self.rustc_workspace_wrapper = Some(rustc_workspace_wrapper);
if rustc_workspace_wrapper.val.is_empty() {
self.rustc_workspace_wrapper = None;
} else {
self.rustc_workspace_wrapper = Some(rustc_workspace_wrapper);
}
}
// 1. RUSTDOC
// 2. build.rustdoc (CARGO_BUILD_RUSTDOC)
Expand Down Expand Up @@ -246,3 +266,22 @@ impl ApplyEnv for TermProgress {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::ApplyEnv;
use crate::{value::Value, ResolveOptions};

#[test]
fn empty_string_wrapper_envs() {
let env_list = [("RUSTC_WRAPPER", ""), ("RUSTC_WORKSPACE_WRAPPER", "")];
let mut config = crate::de::BuildConfig::default();
let cx = &ResolveOptions::default().env(env_list).into_context();
config.rustc_wrapper = Some(Value { val: "rustc_wrapper".to_string(), definition: None });
config.rustc_workspace_wrapper =
Some(Value { val: "rustc_workspace_wrapper".to_string(), definition: None });
config.apply_env(cx).unwrap();
assert!(config.rustc_wrapper.is_none());
assert!(config.rustc_workspace_wrapper.is_none());
}
}
9 changes: 1 addition & 8 deletions src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,7 @@ mod tests {
("CARGO_TERM_PROGRESS_WIDTH", "100"),
];
let mut config = crate::de::Config::default();
let cx = &ResolveOptions::default()
.env(env_list)
.cargo_home(None)
.rustc(PathAndArgs::new("rustc"))
.into_context();
for (k, v) in env_list {
assert_eq!(cx.env[k], v, "key={k},value={v}");
}
let cx = &ResolveOptions::default().env(env_list).into_context();
config.apply_env(cx).unwrap();
}

Expand Down

0 comments on commit 1d7d634

Please sign in to comment.