Skip to content

Commit

Permalink
Adapt implementation with reviewer suggestions and requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Flueckiger committed Feb 13, 2021
1 parent 6ea8abc commit 6af3194
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,14 @@ impl Config {
})
.collect();

let mut upper_case_env: HashMap<String, String> = HashMap::new();

if !cfg!(windows) {
upper_case_env = env
.clone()
let upper_case_env = if cfg!(windows) {
HashMap::new()
} else {
env.clone()
.into_iter()
.map(|(k, _)| (k.to_uppercase().replace("-", "_"), k))
.collect();
}
.collect()
};

let cache_rustc_info = match env.get("CARGO_CACHE_RUSTC_INFO") {
Some(cache) => cache != "0",
Expand Down Expand Up @@ -568,13 +567,16 @@ impl Config {

fn check_environment_key_case_mismatch(&self, key: &ConfigKey) {
if cfg!(windows) {
// In the case of windows the check for case mismatch in keys can be skipped
// as windows already converts its environment keys into the desired format.
return;
}

match self.upper_case_env.get(key.as_env_key()) {
Some(env_key) => {
let _ = self.shell().warn(format!(
"Variables in environment require uppercase,
but given variable: {}, contains lowercase or dash.",
"Environment variables require uppercase letters, \
but the variable: `{}` contains lowercase letters or dashes.",
env_key
));
}
Expand Down
22 changes: 20 additions & 2 deletions tests/testsuite/tool_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,32 @@ fn target_in_environment_contains_lower_case() {
.env(target_key, "nonexistent-linker")
.with_status(101)
.with_stderr_contains(format!(
"warning: Variables in environment require uppercase,
but given variable: {}, contains lowercase or dash.",
"warning: Environment variables require uppercase letters, \
but the variable: `{}` contains lowercase letters or dashes.",
target_key
))
.run();
}
}

#[cargo_test]
#[cfg(windows)]
fn target_in_environment_contains_lower_case_on_windows() {
let p = project().file("src/main.rs", "fn main() {}").build();

let target_keys = [
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_musl_LINKER",
"CARGO_TARGET_x86_64_unknown_linux_musl_LINKER",
];

for target_key in &target_keys {
p.cargo("build -v --target x86_64-unknown-linux-musl")
.env(target_key, "nonexistent-linker")
.without_status()
.run();
}
}

#[cargo_test]
fn cfg_ignored_fields() {
// Test for some ignored fields in [target.'cfg()'] tables.
Expand Down

0 comments on commit 6af3194

Please sign in to comment.