@@ -106,9 +106,13 @@ enum FileContents {
106106
107107enum GeneratedFile {
108108 /// Generates `Cargo.toml` by rewriting the original.
109- Manifest ,
110- /// Generates `Cargo.lock` in some cases (like if there is a binary).
111- Lockfile ,
109+ ///
110+ /// Associated path is the original manifest path.
111+ Manifest ( PathBuf ) ,
112+ /// Generates `Cargo.lock`.
113+ ///
114+ /// Associated path is the path to the original lock file, if existing.
115+ Lockfile ( Option < PathBuf > ) ,
112116 /// Adds a `.cargo_vcs_info.json` file if in a git repo.
113117 VcsInfo ( vcs:: VcsInfo ) ,
114118}
@@ -481,7 +485,9 @@ fn build_ar_list(
481485 . push ( ArchiveFile {
482486 rel_path : PathBuf :: from ( "Cargo.toml" ) ,
483487 rel_str : "Cargo.toml" . to_string ( ) ,
484- contents : FileContents :: Generated ( GeneratedFile :: Manifest ) ,
488+ contents : FileContents :: Generated ( GeneratedFile :: Manifest (
489+ pkg. manifest_path ( ) . to_owned ( ) ,
490+ ) ) ,
485491 } ) ;
486492 } else {
487493 ws. gctx ( ) . shell ( ) . warn ( & format ! (
@@ -491,14 +497,16 @@ fn build_ar_list(
491497 }
492498
493499 if include_lockfile {
500+ let lockfile_path = ws. lock_root ( ) . as_path_unlocked ( ) . join ( LOCKFILE_NAME ) ;
501+ let lockfile_path = lockfile_path. exists ( ) . then_some ( lockfile_path) ;
494502 let rel_str = "Cargo.lock" ;
495503 result
496504 . entry ( UncasedAscii :: new ( rel_str) )
497505 . or_insert_with ( Vec :: new)
498506 . push ( ArchiveFile {
499507 rel_path : PathBuf :: from ( rel_str) ,
500508 rel_str : rel_str. to_string ( ) ,
501- contents : FileContents :: Generated ( GeneratedFile :: Lockfile ) ,
509+ contents : FileContents :: Generated ( GeneratedFile :: Lockfile ( lockfile_path ) ) ,
502510 } ) ;
503511 }
504512
@@ -817,8 +825,10 @@ fn tar(
817825 }
818826 FileContents :: Generated ( generated_kind) => {
819827 let contents = match generated_kind {
820- GeneratedFile :: Manifest => publish_pkg. manifest ( ) . to_normalized_contents ( ) ?,
821- GeneratedFile :: Lockfile => build_lock ( ws, & publish_pkg, local_reg) ?,
828+ GeneratedFile :: Manifest ( _) => {
829+ publish_pkg. manifest ( ) . to_normalized_contents ( ) ?
830+ }
831+ GeneratedFile :: Lockfile ( _) => build_lock ( ws, & publish_pkg, local_reg) ?,
822832 GeneratedFile :: VcsInfo ( ref s) => serde_json:: to_string_pretty ( s) ?,
823833 } ;
824834 header. set_entry_type ( EntryType :: file ( ) ) ;
0 commit comments