@@ -2338,11 +2338,11 @@ fn prepare_toml_for_publish(
2338
2338
package. workspace = None ;
2339
2339
if let Some ( StringOrBool :: String ( path) ) = & package. build {
2340
2340
let path = paths:: normalize_path ( Path :: new ( path) ) ;
2341
- package. build = Some ( StringOrBool :: String (
2341
+ package. build = Some ( StringOrBool :: String ( normalize_path_string_sep (
2342
2342
path. into_os_string ( )
2343
2343
. into_string ( )
2344
2344
. map_err ( |_err| anyhow:: format_err!( "non-UTF8 `package.build`" ) ) ?,
2345
- ) ) ;
2345
+ ) ) ) ;
2346
2346
}
2347
2347
let current_resolver = package
2348
2348
. resolver
@@ -2372,10 +2372,12 @@ fn prepare_toml_for_publish(
2372
2372
let abs_license_path = paths:: normalize_path ( & package_root. join ( license_path) ) ;
2373
2373
if let Ok ( license_file) = abs_license_path. strip_prefix ( package_root) {
2374
2374
package. license_file = Some ( manifest:: InheritableField :: Value (
2375
- license_file
2376
- . to_str ( )
2377
- . ok_or_else ( || anyhow:: format_err!( "non-UTF8 `package.license-file`" ) ) ?
2378
- . to_owned ( ) ,
2375
+ normalize_path_string_sep (
2376
+ license_file
2377
+ . to_str ( )
2378
+ . ok_or_else ( || anyhow:: format_err!( "non-UTF8 `package.license-file`" ) ) ?
2379
+ . to_owned ( ) ,
2380
+ ) ,
2379
2381
) ) ;
2380
2382
} else {
2381
2383
// This path points outside of the package root. `cargo package`
@@ -2401,10 +2403,14 @@ fn prepare_toml_for_publish(
2401
2403
let abs_readme_path = paths:: normalize_path ( & package_root. join ( readme_path) ) ;
2402
2404
if let Ok ( readme_path) = abs_readme_path. strip_prefix ( package_root) {
2403
2405
package. readme = Some ( manifest:: InheritableField :: Value ( StringOrBool :: String (
2404
- readme_path
2405
- . to_str ( )
2406
- . ok_or_else ( || anyhow:: format_err!( "non-UTF8 `package.license-file`" ) ) ?
2407
- . to_owned ( ) ,
2406
+ normalize_path_string_sep (
2407
+ readme_path
2408
+ . to_str ( )
2409
+ . ok_or_else ( || {
2410
+ anyhow:: format_err!( "non-UTF8 `package.license-file`" )
2411
+ } ) ?
2412
+ . to_owned ( ) ,
2413
+ ) ,
2408
2414
) ) ) ;
2409
2415
} else {
2410
2416
// This path points outside of the package root. `cargo package`
@@ -2426,14 +2432,14 @@ fn prepare_toml_for_publish(
2426
2432
}
2427
2433
2428
2434
let lib = if let Some ( target) = & me. lib {
2429
- Some ( prepare_target_for_publish ( target) )
2435
+ Some ( prepare_target_for_publish ( target, "lib" ) ? )
2430
2436
} else {
2431
2437
None
2432
2438
} ;
2433
- let bin = prepare_targets_for_publish ( me. bin . as_ref ( ) ) ;
2434
- let example = prepare_targets_for_publish ( me. example . as_ref ( ) ) ;
2435
- let test = prepare_targets_for_publish ( me. test . as_ref ( ) ) ;
2436
- let bench = prepare_targets_for_publish ( me. bench . as_ref ( ) ) ;
2439
+ let bin = prepare_targets_for_publish ( me. bin . as_ref ( ) , "bin" ) ? ;
2440
+ let example = prepare_targets_for_publish ( me. example . as_ref ( ) , "example" ) ? ;
2441
+ let test = prepare_targets_for_publish ( me. test . as_ref ( ) , "test" ) ? ;
2442
+ let bench = prepare_targets_for_publish ( me. bench . as_ref ( ) , "bench" ) ? ;
2437
2443
2438
2444
let all = |_d : & manifest:: TomlDependency | true ;
2439
2445
let mut manifest = manifest:: TomlManifest {
@@ -2591,22 +2597,46 @@ fn prepare_toml_for_publish(
2591
2597
2592
2598
fn prepare_targets_for_publish (
2593
2599
targets : Option < & Vec < manifest:: TomlTarget > > ,
2594
- ) -> Option < Vec < manifest:: TomlTarget > > {
2595
- let targets = targets?;
2600
+ context : & str ,
2601
+ ) -> CargoResult < Option < Vec < manifest:: TomlTarget > > > {
2602
+ let Some ( targets) = targets else {
2603
+ return Ok ( None ) ;
2604
+ } ;
2596
2605
2597
2606
let mut prepared = Vec :: with_capacity ( targets. len ( ) ) ;
2598
2607
for target in targets {
2599
- let target = prepare_target_for_publish ( target) ;
2608
+ let target = prepare_target_for_publish ( target, context ) ? ;
2600
2609
prepared. push ( target) ;
2601
2610
}
2602
2611
2603
- Some ( prepared)
2612
+ Ok ( Some ( prepared) )
2604
2613
}
2605
2614
2606
- fn prepare_target_for_publish ( target : & manifest:: TomlTarget ) -> manifest:: TomlTarget {
2615
+ fn prepare_target_for_publish (
2616
+ target : & manifest:: TomlTarget ,
2617
+ context : & str ,
2618
+ ) -> CargoResult < manifest:: TomlTarget > {
2607
2619
let mut target = target. clone ( ) ;
2608
2620
if let Some ( path) = target. path {
2609
- target. path = Some ( manifest:: PathValue ( normalize_path ( & path. 0 ) ) ) ;
2621
+ let path = normalize_path ( & path. 0 ) ;
2622
+ target. path = Some ( manifest:: PathValue ( normalize_path_sep ( path, context) ?) ) ;
2623
+ }
2624
+ Ok ( target)
2625
+ }
2626
+
2627
+ fn normalize_path_sep ( path : PathBuf , context : & str ) -> CargoResult < PathBuf > {
2628
+ let path = path
2629
+ . into_os_string ( )
2630
+ . into_string ( )
2631
+ . map_err ( |_err| anyhow:: format_err!( "non-UTF8 path for {context}" ) ) ?;
2632
+ let path = normalize_path_string_sep ( path) ;
2633
+ Ok ( path. into ( ) )
2634
+ }
2635
+
2636
+ fn normalize_path_string_sep ( path : String ) -> String {
2637
+ if std:: path:: MAIN_SEPARATOR != '/' {
2638
+ path. replace ( std:: path:: MAIN_SEPARATOR , "/" )
2639
+ } else {
2640
+ path
2610
2641
}
2611
- target
2612
2642
}
0 commit comments