Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle empty string rustc wrapper envs #7

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 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,23 @@ impl ApplyEnv for TermProgress {
Ok(())
}
}

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

use super::ApplyEnv;
taiki-e marked this conversation as resolved.
Show resolved Hide resolved

#[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