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