@@ -15,6 +15,7 @@ use std::fs::{self, DirEntry};
15
15
use std:: path:: { Path , PathBuf } ;
16
16
17
17
use anyhow:: Context as _;
18
+ use cargo_util:: paths;
18
19
use cargo_util_schemas:: manifest:: {
19
20
PathValue , StringOrBool , StringOrVec , TomlBenchTarget , TomlBinTarget , TomlExampleTarget ,
20
21
TomlLibTarget , TomlManifest , TomlTarget , TomlTestTarget ,
@@ -133,7 +134,7 @@ pub fn normalize_lib(
133
134
warnings : & mut Vec < String > ,
134
135
) -> CargoResult < Option < TomlLibTarget > > {
135
136
if is_normalized ( original_lib, autodiscover) {
136
- let Some ( lib) = original_lib. cloned ( ) else {
137
+ let Some ( mut lib) = original_lib. cloned ( ) else {
137
138
return Ok ( None ) ;
138
139
} ;
139
140
@@ -143,6 +144,10 @@ pub fn normalize_lib(
143
144
validate_proc_macro ( & lib, "library" , edition, warnings) ?;
144
145
validate_crate_types ( & lib, "library" , edition, warnings) ?;
145
146
147
+ if let Some ( PathValue ( path) ) = & lib. path {
148
+ lib. path = Some ( PathValue ( paths:: normalize_path ( path) . into ( ) ) ) ;
149
+ }
150
+
146
151
Ok ( Some ( lib) )
147
152
} else {
148
153
let inferred = inferred_lib ( package_root) ;
@@ -184,6 +189,10 @@ pub fn normalize_lib(
184
189
}
185
190
}
186
191
192
+ if let Some ( PathValue ( path) ) = lib. path . as_ref ( ) {
193
+ lib. path = Some ( PathValue ( paths:: normalize_path ( & path) . into ( ) ) ) ;
194
+ }
195
+
187
196
Ok ( Some ( lib) )
188
197
}
189
198
}
@@ -255,11 +264,15 @@ pub fn normalize_bins(
255
264
has_lib : bool ,
256
265
) -> CargoResult < Vec < TomlBinTarget > > {
257
266
if are_normalized ( toml_bins, autodiscover) {
258
- let toml_bins = toml_bins. cloned ( ) . unwrap_or_default ( ) ;
259
- for bin in & toml_bins {
267
+ let mut toml_bins = toml_bins. cloned ( ) . unwrap_or_default ( ) ;
268
+ for bin in toml_bins. iter_mut ( ) {
260
269
validate_bin_name ( bin, warnings) ?;
261
270
validate_bin_crate_types ( bin, edition, warnings, errors) ?;
262
271
validate_bin_proc_macro ( bin, edition, warnings, errors) ?;
272
+
273
+ if let Some ( PathValue ( path) ) = & bin. path {
274
+ bin. path = Some ( PathValue ( paths:: normalize_path ( path) . into ( ) ) ) ;
275
+ }
263
276
}
264
277
Ok ( toml_bins)
265
278
} else {
@@ -300,7 +313,7 @@ pub fn normalize_bins(
300
313
}
301
314
} ) ;
302
315
let path = match path {
303
- Ok ( path) => path,
316
+ Ok ( path) => paths :: normalize_path ( & path) . into ( ) ,
304
317
Err ( e) => anyhow:: bail!( "{}" , e) ,
305
318
} ;
306
319
bin. path = Some ( PathValue ( path) ) ;
@@ -603,13 +616,17 @@ fn normalize_targets_with_legacy_path(
603
616
autodiscover_flag_name : & str ,
604
617
) -> CargoResult < Vec < TomlTarget > > {
605
618
if are_normalized ( toml_targets, autodiscover) {
606
- let toml_targets = toml_targets. cloned ( ) . unwrap_or_default ( ) ;
607
- for target in & toml_targets {
619
+ let mut toml_targets = toml_targets. cloned ( ) . unwrap_or_default ( ) ;
620
+ for target in toml_targets. iter_mut ( ) {
608
621
// Check early to improve error messages
609
622
validate_target_name ( target, target_kind_human, target_kind, warnings) ?;
610
623
611
624
validate_proc_macro ( target, target_kind_human, edition, warnings) ?;
612
625
validate_crate_types ( target, target_kind_human, edition, warnings) ?;
626
+
627
+ if let Some ( PathValue ( path) ) = & target. path {
628
+ target. path = Some ( PathValue ( paths:: normalize_path ( path) . into ( ) ) ) ;
629
+ }
613
630
}
614
631
Ok ( toml_targets)
615
632
} else {
@@ -651,7 +668,7 @@ fn normalize_targets_with_legacy_path(
651
668
continue ;
652
669
}
653
670
} ;
654
- target. path = Some ( PathValue ( path) ) ;
671
+ target. path = Some ( PathValue ( paths :: normalize_path ( & path) . into ( ) ) ) ;
655
672
result. push ( target) ;
656
673
}
657
674
Ok ( result)
@@ -1037,7 +1054,14 @@ pub fn normalize_build(build: Option<&StringOrBool>, package_root: &Path) -> Opt
1037
1054
}
1038
1055
}
1039
1056
// Explicitly no build script.
1040
- Some ( StringOrBool :: Bool ( false ) ) | Some ( StringOrBool :: String ( _) ) => build. cloned ( ) ,
1057
+ Some ( StringOrBool :: Bool ( false ) ) => build. cloned ( ) ,
1058
+ Some ( StringOrBool :: String ( build_file) ) => {
1059
+ let build_file = paths:: normalize_path ( Path :: new ( build_file) ) ;
1060
+ let build = build_file. into_os_string ( ) . into_string ( ) . expect (
1061
+ "`build_file` started as a String and `normalize_path` shouldn't have changed that" ,
1062
+ ) ;
1063
+ Some ( StringOrBool :: String ( build) )
1064
+ }
1041
1065
Some ( StringOrBool :: Bool ( true ) ) => Some ( StringOrBool :: String ( BUILD_RS . to_owned ( ) ) ) ,
1042
1066
}
1043
1067
}
0 commit comments