Skip to content

Commit 6af3194

Browse files
author
Nick Flueckiger
committed
Adapt implementation with reviewer suggestions and requested changes
1 parent 6ea8abc commit 6af3194

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/cargo/util/config/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,14 @@ impl Config {
213213
})
214214
.collect();
215215

216-
let mut upper_case_env: HashMap<String, String> = HashMap::new();
217-
218-
if !cfg!(windows) {
219-
upper_case_env = env
220-
.clone()
216+
let upper_case_env = if cfg!(windows) {
217+
HashMap::new()
218+
} else {
219+
env.clone()
221220
.into_iter()
222221
.map(|(k, _)| (k.to_uppercase().replace("-", "_"), k))
223-
.collect();
224-
}
222+
.collect()
223+
};
225224

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

569568
fn check_environment_key_case_mismatch(&self, key: &ConfigKey) {
570569
if cfg!(windows) {
570+
// In the case of windows the check for case mismatch in keys can be skipped
571+
// as windows already converts its environment keys into the desired format.
571572
return;
572573
}
574+
573575
match self.upper_case_env.get(key.as_env_key()) {
574576
Some(env_key) => {
575577
let _ = self.shell().warn(format!(
576-
"Variables in environment require uppercase,
577-
but given variable: {}, contains lowercase or dash.",
578+
"Environment variables require uppercase letters, \
579+
but the variable: `{}` contains lowercase letters or dashes.",
578580
env_key
579581
));
580582
}

tests/testsuite/tool_paths.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,32 @@ fn target_in_environment_contains_lower_case() {
368368
.env(target_key, "nonexistent-linker")
369369
.with_status(101)
370370
.with_stderr_contains(format!(
371-
"warning: Variables in environment require uppercase,
372-
but given variable: {}, contains lowercase or dash.",
371+
"warning: Environment variables require uppercase letters, \
372+
but the variable: `{}` contains lowercase letters or dashes.",
373373
target_key
374374
))
375375
.run();
376376
}
377377
}
378378

379+
#[cargo_test]
380+
#[cfg(windows)]
381+
fn target_in_environment_contains_lower_case_on_windows() {
382+
let p = project().file("src/main.rs", "fn main() {}").build();
383+
384+
let target_keys = [
385+
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_musl_LINKER",
386+
"CARGO_TARGET_x86_64_unknown_linux_musl_LINKER",
387+
];
388+
389+
for target_key in &target_keys {
390+
p.cargo("build -v --target x86_64-unknown-linux-musl")
391+
.env(target_key, "nonexistent-linker")
392+
.without_status()
393+
.run();
394+
}
395+
}
396+
379397
#[cargo_test]
380398
fn cfg_ignored_fields() {
381399
// Test for some ignored fields in [target.'cfg()'] tables.

0 commit comments

Comments
 (0)