@@ -15,6 +15,7 @@ use std::fs::{self, DirEntry};
1515use std:: path:: { Path , PathBuf } ;
1616
1717use anyhow:: Context as _;
18+ use cargo_util:: paths;
1819use cargo_util_schemas:: manifest:: {
1920 PathValue , StringOrBool , StringOrVec , TomlBenchTarget , TomlBinTarget , TomlExampleTarget ,
2021 TomlLibTarget , TomlManifest , TomlTarget , TomlTestTarget ,
@@ -133,7 +134,7 @@ pub fn normalize_lib(
133134 warnings : & mut Vec < String > ,
134135) -> CargoResult < Option < TomlLibTarget > > {
135136 if is_normalized ( original_lib, autodiscover) {
136- let Some ( lib) = original_lib. cloned ( ) else {
137+ let Some ( mut lib) = original_lib. cloned ( ) else {
137138 return Ok ( None ) ;
138139 } ;
139140
@@ -143,6 +144,10 @@ pub fn normalize_lib(
143144 validate_proc_macro ( & lib, "library" , edition, warnings) ?;
144145 validate_crate_types ( & lib, "library" , edition, warnings) ?;
145146
147+ if let Some ( PathValue ( path) ) = & lib. path {
148+ lib. path = Some ( PathValue ( paths:: normalize_path ( path) . into ( ) ) ) ;
149+ }
150+
146151 Ok ( Some ( lib) )
147152 } else {
148153 let inferred = inferred_lib ( package_root) ;
@@ -184,6 +189,10 @@ pub fn normalize_lib(
184189 }
185190 }
186191
192+ if let Some ( PathValue ( path) ) = lib. path . as_ref ( ) {
193+ lib. path = Some ( PathValue ( paths:: normalize_path ( & path) . into ( ) ) ) ;
194+ }
195+
187196 Ok ( Some ( lib) )
188197 }
189198}
@@ -255,11 +264,15 @@ pub fn normalize_bins(
255264 has_lib : bool ,
256265) -> CargoResult < Vec < TomlBinTarget > > {
257266 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 ( ) {
260269 validate_bin_name ( bin, warnings) ?;
261270 validate_bin_crate_types ( bin, edition, warnings, errors) ?;
262271 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+ }
263276 }
264277 Ok ( toml_bins)
265278 } else {
@@ -300,7 +313,7 @@ pub fn normalize_bins(
300313 }
301314 } ) ;
302315 let path = match path {
303- Ok ( path) => path,
316+ Ok ( path) => paths :: normalize_path ( & path) . into ( ) ,
304317 Err ( e) => anyhow:: bail!( "{}" , e) ,
305318 } ;
306319 bin. path = Some ( PathValue ( path) ) ;
@@ -603,13 +616,17 @@ fn normalize_targets_with_legacy_path(
603616 autodiscover_flag_name : & str ,
604617) -> CargoResult < Vec < TomlTarget > > {
605618 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 ( ) {
608621 // Check early to improve error messages
609622 validate_target_name ( target, target_kind_human, target_kind, warnings) ?;
610623
611624 validate_proc_macro ( target, target_kind_human, edition, warnings) ?;
612625 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+ }
613630 }
614631 Ok ( toml_targets)
615632 } else {
@@ -651,7 +668,7 @@ fn normalize_targets_with_legacy_path(
651668 continue ;
652669 }
653670 } ;
654- target. path = Some ( PathValue ( path) ) ;
671+ target. path = Some ( PathValue ( paths :: normalize_path ( & path) . into ( ) ) ) ;
655672 result. push ( target) ;
656673 }
657674 Ok ( result)
@@ -1023,9 +1040,12 @@ Cargo doesn't know which to use because multiple target files found at `{}` and
10231040
10241041/// Returns the path to the build script if one exists for this crate.
10251042#[ tracing:: instrument( skip_all) ]
1026- pub fn normalize_build ( build : Option < & StringOrBool > , package_root : & Path ) -> Option < StringOrBool > {
1043+ pub fn normalize_build (
1044+ build : Option < & StringOrBool > ,
1045+ package_root : & Path ,
1046+ ) -> CargoResult < Option < StringOrBool > > {
10271047 const BUILD_RS : & str = "build.rs" ;
1028- match build {
1048+ let build = match build {
10291049 None => {
10301050 // If there is a `build.rs` file next to the `Cargo.toml`, assume it is
10311051 // a build script.
@@ -1037,9 +1057,18 @@ pub fn normalize_build(build: Option<&StringOrBool>, package_root: &Path) -> Opt
10371057 }
10381058 }
10391059 // Explicitly no build script.
1040- Some ( StringOrBool :: Bool ( false ) ) | Some ( StringOrBool :: String ( _) ) => build. cloned ( ) ,
1060+ Some ( StringOrBool :: Bool ( false ) ) => build. cloned ( ) ,
1061+ Some ( StringOrBool :: String ( build_file) ) => {
1062+ let build_file = paths:: normalize_path ( Path :: new ( build_file) ) ;
1063+ let build = build_file. into_os_string ( ) . into_string ( ) . expect (
1064+ "`build_file` started as a String and `normalize_path` shouldn't have changed that" ,
1065+ ) ;
1066+ Some ( StringOrBool :: String ( build) )
1067+ }
10411068 Some ( StringOrBool :: Bool ( true ) ) => Some ( StringOrBool :: String ( BUILD_RS . to_owned ( ) ) ) ,
1042- }
1069+ } ;
1070+
1071+ Ok ( build)
10431072}
10441073
10451074fn name_or_panic ( target : & TomlTarget ) -> & str {
0 commit comments