@@ -50,8 +50,17 @@ struct ArchiveFile {
50
50
enum FileContents {
51
51
/// Absolute path to the file on disk to add to the archive.
52
52
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 ) ,
55
64
}
56
65
57
66
pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Option < FileLock > > {
@@ -71,8 +80,6 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
71
80
check_metadata ( pkg, config) ?;
72
81
}
73
82
74
- verify_dependencies ( pkg) ?;
75
-
76
83
if !pkg. manifest ( ) . exclude ( ) . is_empty ( ) && !pkg. manifest ( ) . include ( ) . is_empty ( ) {
77
84
config. shell ( ) . warn (
78
85
"both package.include and package.exclude are specified; \
@@ -100,6 +107,8 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
100
107
return Ok ( None ) ;
101
108
}
102
109
110
+ verify_dependencies ( pkg) ?;
111
+
103
112
let filename = format ! ( "{}-{}.crate" , pkg. name( ) , pkg. version( ) ) ;
104
113
let dir = ws. target_dir ( ) . join ( "package" ) ;
105
114
let mut dst = {
@@ -156,11 +165,10 @@ fn build_ar_list(
156
165
rel_str : "Cargo.toml.orig" . to_string ( ) ,
157
166
contents : FileContents :: OnDisk ( src_file) ,
158
167
} ) ;
159
- let generated = pkg. to_registry_toml ( ws. config ( ) ) ?;
160
168
result. push ( ArchiveFile {
161
169
rel_path,
162
170
rel_str,
163
- contents : FileContents :: Generated ( generated ) ,
171
+ contents : FileContents :: Generated ( GeneratedFile :: Manifest ) ,
164
172
} ) ;
165
173
}
166
174
"Cargo.lock" => continue ,
@@ -179,18 +187,17 @@ fn build_ar_list(
179
187
}
180
188
}
181
189
if pkg. include_lockfile ( ) {
182
- let new_lock = build_lock ( ws) ?;
183
190
result. push ( ArchiveFile {
184
191
rel_path : PathBuf :: from ( "Cargo.lock" ) ,
185
192
rel_str : "Cargo.lock" . to_string ( ) ,
186
- contents : FileContents :: Generated ( new_lock ) ,
193
+ contents : FileContents :: Generated ( GeneratedFile :: Lockfile ) ,
187
194
} ) ;
188
195
}
189
196
if let Some ( vcs_info) = vcs_info {
190
197
result. push ( ArchiveFile {
191
198
rel_path : PathBuf :: from ( VCS_INFO_FILE ) ,
192
199
rel_str : VCS_INFO_FILE . to_string ( ) ,
193
- contents : FileContents :: Generated ( vcs_info) ,
200
+ contents : FileContents :: Generated ( GeneratedFile :: VcsInfo ( vcs_info) ) ,
194
201
} ) ;
195
202
}
196
203
if let Some ( license_file) = & pkg. manifest ( ) . metadata ( ) . license_file {
@@ -530,7 +537,12 @@ fn tar(
530
537
format ! ( "could not archive source file `{}`" , disk_path. display( ) )
531
538
} ) ?;
532
539
}
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
+ } ;
534
546
header. set_entry_type ( EntryType :: file ( ) ) ;
535
547
header. set_mode ( 0o644 ) ;
536
548
header. set_mtime (
0 commit comments