@@ -220,7 +220,7 @@ fn sync(
220
220
let pathsource = PathSource :: new ( src, id. source_id ( ) , gctx) ;
221
221
let paths = pathsource. list_files ( pkg) ?;
222
222
let mut map = BTreeMap :: new ( ) ;
223
- cp_sources ( pkg, src, & paths, & dst, & mut map, & mut tmp_buf)
223
+ cp_sources ( pkg, src, & paths, & dst, & mut map, & mut tmp_buf, gctx )
224
224
. with_context ( || format ! ( "failed to copy over vendored sources for: {}" , id) ) ?;
225
225
226
226
// Finally, emit the metadata about this package
@@ -316,6 +316,7 @@ fn cp_sources(
316
316
dst : & Path ,
317
317
cksums : & mut BTreeMap < String , String > ,
318
318
tmp_buf : & mut [ u8 ] ,
319
+ gctx : & GlobalContext ,
319
320
) -> CargoResult < ( ) > {
320
321
for p in paths {
321
322
let relative = p. strip_prefix ( & src) . unwrap ( ) ;
@@ -359,7 +360,12 @@ fn cp_sources(
359
360
let cksum = if dst. file_name ( ) == Some ( OsStr :: new ( "Cargo.toml" ) )
360
361
&& pkg. package_id ( ) . source_id ( ) . is_git ( )
361
362
{
362
- let contents = pkg. manifest ( ) . to_resolved_contents ( ) ?;
363
+ let packaged_files = paths
364
+ . iter ( )
365
+ . map ( |p| p. strip_prefix ( src) . unwrap ( ) . to_owned ( ) )
366
+ . collect :: < Vec < _ > > ( ) ;
367
+ let vendored_pkg = prepare_for_vendor ( pkg, & packaged_files, gctx) ?;
368
+ let contents = vendored_pkg. manifest ( ) . to_resolved_contents ( ) ?;
363
369
copy_and_checksum (
364
370
& dst,
365
371
& mut dst_opts,
@@ -391,6 +397,111 @@ fn cp_sources(
391
397
Ok ( ( ) )
392
398
}
393
399
400
+ /// HACK: Perform the bare minimum of `prepare_for_publish` needed for #14348.
401
+ ///
402
+ /// There are parts of `prepare_for_publish` that could be directly useful (e.g. stripping
403
+ /// `[workspace]`) while other parts that require other filesystem operations (moving the README
404
+ /// file) and ideally we'd reuse `cargo package` code to take care of all of this for us.
405
+ fn prepare_for_vendor (
406
+ me : & Package ,
407
+ packaged_files : & [ PathBuf ] ,
408
+ gctx : & GlobalContext ,
409
+ ) -> CargoResult < Package > {
410
+ let contents = me. manifest ( ) . contents ( ) ;
411
+ let document = me. manifest ( ) . document ( ) ;
412
+ let original_toml =
413
+ prepare_toml_for_vendor ( me. manifest ( ) . resolved_toml ( ) . clone ( ) , packaged_files, gctx) ?;
414
+ let normalized_toml = original_toml. clone ( ) ;
415
+ let features = me. manifest ( ) . unstable_features ( ) . clone ( ) ;
416
+ let workspace_config = me. manifest ( ) . workspace_config ( ) . clone ( ) ;
417
+ let source_id = me. package_id ( ) . source_id ( ) ;
418
+ let mut warnings = Default :: default ( ) ;
419
+ let mut errors = Default :: default ( ) ;
420
+ let manifest = crate :: util:: toml:: to_real_manifest (
421
+ contents. to_owned ( ) ,
422
+ document. clone ( ) ,
423
+ original_toml,
424
+ normalized_toml,
425
+ features,
426
+ workspace_config,
427
+ source_id,
428
+ me. manifest_path ( ) ,
429
+ gctx,
430
+ & mut warnings,
431
+ & mut errors,
432
+ ) ?;
433
+ let new_pkg = Package :: new ( manifest, me. manifest_path ( ) ) ;
434
+ Ok ( new_pkg)
435
+ }
436
+
437
+ fn prepare_toml_for_vendor (
438
+ mut me : cargo_util_schemas:: manifest:: TomlManifest ,
439
+ packaged_files : & [ PathBuf ] ,
440
+ gctx : & GlobalContext ,
441
+ ) -> CargoResult < cargo_util_schemas:: manifest:: TomlManifest > {
442
+ let package = me
443
+ . package
444
+ . as_mut ( )
445
+ . expect ( "venedored manifests must have packages" ) ;
446
+ if let Some ( cargo_util_schemas:: manifest:: StringOrBool :: String ( path) ) = & package. build {
447
+ let path = paths:: normalize_path ( Path :: new ( path) ) ;
448
+ let included = packaged_files. contains ( & path) ;
449
+ let build = if included {
450
+ let path = path
451
+ . into_os_string ( )
452
+ . into_string ( )
453
+ . map_err ( |_err| anyhow:: format_err!( "non-UTF8 `package.build`" ) ) ?;
454
+ let path = crate :: util:: toml:: normalize_path_string_sep ( path) ;
455
+ cargo_util_schemas:: manifest:: StringOrBool :: String ( path)
456
+ } else {
457
+ gctx. shell ( ) . warn ( format ! (
458
+ "ignoring `package.build` as `{}` is not included in the published package" ,
459
+ path. display( )
460
+ ) ) ?;
461
+ cargo_util_schemas:: manifest:: StringOrBool :: Bool ( false )
462
+ } ;
463
+ package. build = Some ( build) ;
464
+ }
465
+
466
+ let lib = if let Some ( target) = & me. lib {
467
+ crate :: util:: toml:: prepare_target_for_publish ( target, packaged_files, "library" , gctx) ?
468
+ } else {
469
+ None
470
+ } ;
471
+ let bin = crate :: util:: toml:: prepare_targets_for_publish (
472
+ me. bin . as_ref ( ) ,
473
+ packaged_files,
474
+ "binary" ,
475
+ gctx,
476
+ ) ?;
477
+ let example = crate :: util:: toml:: prepare_targets_for_publish (
478
+ me. example . as_ref ( ) ,
479
+ packaged_files,
480
+ "example" ,
481
+ gctx,
482
+ ) ?;
483
+ let test = crate :: util:: toml:: prepare_targets_for_publish (
484
+ me. test . as_ref ( ) ,
485
+ packaged_files,
486
+ "test" ,
487
+ gctx,
488
+ ) ?;
489
+ let bench = crate :: util:: toml:: prepare_targets_for_publish (
490
+ me. bench . as_ref ( ) ,
491
+ packaged_files,
492
+ "benchmark" ,
493
+ gctx,
494
+ ) ?;
495
+
496
+ me. lib = lib;
497
+ me. bin = bin;
498
+ me. example = example;
499
+ me. test = test;
500
+ me. bench = bench;
501
+
502
+ Ok ( me)
503
+ }
504
+
394
505
fn copy_and_checksum < T : Read > (
395
506
dst_path : & Path ,
396
507
dst_opts : & mut OpenOptions ,
0 commit comments