@@ -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`
@@ -2427,16 +2433,19 @@ fn prepare_toml_for_publish(
2427
2433
2428
2434
let lib = if let Some ( mut target) = me. lib . clone ( ) {
2429
2435
if let Some ( path) = target. path {
2430
- target. path = Some ( manifest:: PathValue ( normalize_path ( & path. 0 ) ) ) ;
2436
+ target. path = Some ( manifest:: PathValue ( normalize_path_sep (
2437
+ normalize_path ( & path. 0 ) ,
2438
+ "lib" ,
2439
+ ) ?) ) ;
2431
2440
}
2432
2441
Some ( target)
2433
2442
} else {
2434
2443
None
2435
2444
} ;
2436
- let bin = prepare_targets_for_publish ( me. bin . as_ref ( ) ) ;
2437
- let example = prepare_targets_for_publish ( me. example . as_ref ( ) ) ;
2438
- let test = prepare_targets_for_publish ( me. test . as_ref ( ) ) ;
2439
- let bench = prepare_targets_for_publish ( me. bench . as_ref ( ) ) ;
2445
+ let bin = prepare_targets_for_publish ( me. bin . as_ref ( ) , "bin" ) ? ;
2446
+ let example = prepare_targets_for_publish ( me. example . as_ref ( ) , "example" ) ? ;
2447
+ let test = prepare_targets_for_publish ( me. test . as_ref ( ) , "test" ) ? ;
2448
+ let bench = prepare_targets_for_publish ( me. bench . as_ref ( ) , "bench" ) ? ;
2440
2449
2441
2450
let all = |_d : & manifest:: TomlDependency | true ;
2442
2451
let mut manifest = manifest:: TomlManifest {
@@ -2594,17 +2603,40 @@ fn prepare_toml_for_publish(
2594
2603
2595
2604
fn prepare_targets_for_publish (
2596
2605
targets : Option < & Vec < manifest:: TomlTarget > > ,
2597
- ) -> Option < Vec < manifest:: TomlTarget > > {
2598
- let targets = targets?;
2606
+ context : & str ,
2607
+ ) -> CargoResult < Option < Vec < manifest:: TomlTarget > > > {
2608
+ let Some ( targets) = targets else {
2609
+ return Ok ( None ) ;
2610
+ } ;
2599
2611
2600
2612
let mut prepared = Vec :: with_capacity ( targets. len ( ) ) ;
2601
2613
for target in targets {
2602
2614
let mut target = target. clone ( ) ;
2603
2615
if let Some ( path) = target. path {
2604
- target. path = Some ( manifest:: PathValue ( normalize_path ( & path. 0 ) ) ) ;
2616
+ target. path = Some ( manifest:: PathValue ( normalize_path_sep (
2617
+ normalize_path ( & path. 0 ) ,
2618
+ context,
2619
+ ) ?) ) ;
2605
2620
}
2606
2621
prepared. push ( target) ;
2607
2622
}
2608
2623
2609
- Some ( prepared)
2624
+ Ok ( Some ( prepared) )
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
2641
+ }
2610
2642
}
0 commit comments