@@ -167,6 +167,8 @@ pub struct Config {
167
167
target_dir : Option < Filesystem > ,
168
168
/// Environment variables, separated to assist testing.
169
169
env : HashMap < String , String > ,
170
+ /// Environment variables, converted to uppercase to check for case mismatch
171
+ upper_case_env : HashMap < String , String > ,
170
172
/// Tracks which sources have been updated to avoid multiple updates.
171
173
updated_sources : LazyCell < RefCell < HashSet < SourceId > > > ,
172
174
/// Lock, if held, of the global package cache along with the number of
@@ -211,6 +213,14 @@ impl Config {
211
213
} )
212
214
. collect ( ) ;
213
215
216
+ let mut upper_case_env : HashMap < String , String > = HashMap :: new ( ) ;
217
+
218
+ if !cfg ! ( windows) {
219
+ upper_case_env = env. clone ( ) . into_iter ( ) . map ( |( k, _) | {
220
+ ( k. to_uppercase ( ) . replace ( "-" , "_" ) , k)
221
+ } ) . collect ( ) ;
222
+ }
223
+
214
224
let cache_rustc_info = match env. get ( "CARGO_CACHE_RUSTC_INFO" ) {
215
225
Some ( cache) => cache != "0" ,
216
226
_ => true ,
@@ -244,6 +254,7 @@ impl Config {
244
254
creation_time : Instant :: now ( ) ,
245
255
target_dir : None ,
246
256
env,
257
+ upper_case_env,
247
258
updated_sources : LazyCell :: new ( ) ,
248
259
package_cache_lock : RefCell :: new ( None ) ,
249
260
http_config : LazyCell :: new ( ) ,
@@ -525,7 +536,10 @@ impl Config {
525
536
definition,
526
537
} ) )
527
538
}
528
- None => Ok ( None ) ,
539
+ None => {
540
+ self . check_environment_key_case_mismatch ( key) ;
541
+ Ok ( None )
542
+ } ,
529
543
}
530
544
}
531
545
@@ -545,9 +559,26 @@ impl Config {
545
559
return true ;
546
560
}
547
561
}
562
+ self . check_environment_key_case_mismatch ( key) ;
563
+
548
564
false
549
565
}
550
566
567
+ fn check_environment_key_case_mismatch ( & self , key : & ConfigKey ) {
568
+ if cfg ! ( windows) {
569
+ return ;
570
+ }
571
+ match self . upper_case_env . get ( key. as_env_key ( ) ) {
572
+ Some ( env_key) => {
573
+ let _ = self . shell ( ) . warn (
574
+ format ! ( "Variables in environment require uppercase,
575
+ but given variable: {}, contains lowercase or dash." , env_key)
576
+ ) ;
577
+ } ,
578
+ None => { } ,
579
+ }
580
+ }
581
+
551
582
/// Get a string config value.
552
583
///
553
584
/// See `get` for more details.
@@ -640,7 +671,10 @@ impl Config {
640
671
) -> CargoResult < ( ) > {
641
672
let env_val = match self . env . get ( key. as_env_key ( ) ) {
642
673
Some ( v) => v,
643
- None => return Ok ( ( ) ) ,
674
+ None => {
675
+ self . check_environment_key_case_mismatch ( key) ;
676
+ return Ok ( ( ) )
677
+ } ,
644
678
} ;
645
679
646
680
let def = Definition :: Environment ( key. as_env_key ( ) . to_string ( ) ) ;
0 commit comments