@@ -50,8 +50,17 @@ struct ArchiveFile {
5050enum FileContents {
5151 /// Absolute path to the file on disk to add to the archive.
5252 OnDisk ( PathBuf ) ,
53- /// Contents of a file generated in memory.
54- Generated ( String ) ,
53+ /// Generates a file.
54+ Generated ( GeneratedFile ) ,
55+ }
56+
57+ enum GeneratedFile {
58+ /// Generates `Cargo.toml` by rewriting the original.
59+ Manifest ,
60+ /// Generates `Cargo.lock` in some cases (like if there is a binary).
61+ Lockfile ,
62+ /// Adds a `.cargo-vcs_info.json` file if in a (clean) git repo.
63+ VcsInfo ( String ) ,
5564}
5665
5766pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Option < FileLock > > {
@@ -71,8 +80,6 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
7180 check_metadata ( pkg, config) ?;
7281 }
7382
74- verify_dependencies ( pkg) ?;
75-
7683 if !pkg. manifest ( ) . exclude ( ) . is_empty ( ) && !pkg. manifest ( ) . include ( ) . is_empty ( ) {
7784 config. shell ( ) . warn (
7885 "both package.include and package.exclude are specified; \
@@ -100,6 +107,8 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
100107 return Ok ( None ) ;
101108 }
102109
110+ verify_dependencies ( pkg) ?;
111+
103112 let filename = format ! ( "{}-{}.crate" , pkg. name( ) , pkg. version( ) ) ;
104113 let dir = ws. target_dir ( ) . join ( "package" ) ;
105114 let mut dst = {
@@ -156,11 +165,10 @@ fn build_ar_list(
156165 rel_str : "Cargo.toml.orig" . to_string ( ) ,
157166 contents : FileContents :: OnDisk ( src_file) ,
158167 } ) ;
159- let generated = pkg. to_registry_toml ( ws. config ( ) ) ?;
160168 result. push ( ArchiveFile {
161169 rel_path,
162170 rel_str,
163- contents : FileContents :: Generated ( generated ) ,
171+ contents : FileContents :: Generated ( GeneratedFile :: Manifest ) ,
164172 } ) ;
165173 }
166174 "Cargo.lock" => continue ,
@@ -179,18 +187,17 @@ fn build_ar_list(
179187 }
180188 }
181189 if pkg. include_lockfile ( ) {
182- let new_lock = build_lock ( ws) ?;
183190 result. push ( ArchiveFile {
184191 rel_path : PathBuf :: from ( "Cargo.lock" ) ,
185192 rel_str : "Cargo.lock" . to_string ( ) ,
186- contents : FileContents :: Generated ( new_lock ) ,
193+ contents : FileContents :: Generated ( GeneratedFile :: Lockfile ) ,
187194 } ) ;
188195 }
189196 if let Some ( vcs_info) = vcs_info {
190197 result. push ( ArchiveFile {
191198 rel_path : PathBuf :: from ( VCS_INFO_FILE ) ,
192199 rel_str : VCS_INFO_FILE . to_string ( ) ,
193- contents : FileContents :: Generated ( vcs_info) ,
200+ contents : FileContents :: Generated ( GeneratedFile :: VcsInfo ( vcs_info) ) ,
194201 } ) ;
195202 }
196203 if let Some ( license_file) = & pkg. manifest ( ) . metadata ( ) . license_file {
@@ -530,7 +537,12 @@ fn tar(
530537 format ! ( "could not archive source file `{}`" , disk_path. display( ) )
531538 } ) ?;
532539 }
533- FileContents :: Generated ( contents) => {
540+ FileContents :: Generated ( generated_kind) => {
541+ let contents = match generated_kind {
542+ GeneratedFile :: Manifest => pkg. to_registry_toml ( config) ?,
543+ GeneratedFile :: Lockfile => build_lock ( ws) ?,
544+ GeneratedFile :: VcsInfo ( s) => s,
545+ } ;
534546 header. set_entry_type ( EntryType :: file ( ) ) ;
535547 header. set_mode ( 0o644 ) ;
536548 header. set_mtime (
0 commit comments