@@ -93,30 +93,6 @@ struct GitVcsInfo {
93
93
dirty : bool ,
94
94
}
95
95
96
- /// Packages a single package in a workspace, returning the resulting tar file.
97
- ///
98
- /// # Panics
99
- /// Panics if `opts.list` is true. In that case you probably don't want to
100
- /// actually build the package tarball; you should just make and print the list
101
- /// of files. (We don't currently provide a public API for that, but see how
102
- /// [`package`] does it.)
103
- pub fn package_one (
104
- ws : & Workspace < ' _ > ,
105
- pkg : & Package ,
106
- opts : & PackageOpts < ' _ > ,
107
- ) -> CargoResult < FileLock > {
108
- assert ! ( !opts. list) ;
109
-
110
- let ar_files = prepare_archive ( ws, pkg, opts) ?;
111
- let tarball = create_package ( ws, pkg, ar_files, None ) ?;
112
-
113
- if opts. verify {
114
- run_verify ( ws, pkg, & tarball, None , opts) ?;
115
- }
116
-
117
- Ok ( tarball)
118
- }
119
-
120
96
// Builds a tarball and places it in the output directory.
121
97
fn create_package (
122
98
ws : & Workspace < ' _ > ,
@@ -193,6 +169,34 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
193
169
// So we need filter
194
170
pkgs. retain ( |( pkg, _feats) | specs. iter ( ) . any ( |spec| spec. matches ( pkg. package_id ( ) ) ) ) ;
195
171
172
+ Ok ( do_package ( ws, opts, pkgs) ?
173
+ . into_iter ( )
174
+ . map ( |x| x. 2 )
175
+ . collect ( ) )
176
+ }
177
+
178
+ /// Packages an entire workspace.
179
+ ///
180
+ /// Returns the generated package files and the dependencies between them. If
181
+ /// `opts.list` is true, skips generating package files and returns an empty
182
+ /// list.
183
+ pub ( crate ) fn package_with_dep_graph (
184
+ ws : & Workspace < ' _ > ,
185
+ opts : & PackageOpts < ' _ > ,
186
+ pkgs : Vec < ( & Package , CliFeatures ) > ,
187
+ ) -> CargoResult < LocalDependencies < ( CliFeatures , FileLock ) > > {
188
+ let output = do_package ( ws, opts, pkgs) ?;
189
+
190
+ Ok ( local_deps ( output. into_iter ( ) . map (
191
+ |( pkg, opts, tarball) | ( pkg, ( opts. cli_features , tarball) ) ,
192
+ ) ) )
193
+ }
194
+
195
+ fn do_package < ' a > (
196
+ ws : & Workspace < ' _ > ,
197
+ opts : & PackageOpts < ' a > ,
198
+ pkgs : Vec < ( & Package , CliFeatures ) > ,
199
+ ) -> CargoResult < Vec < ( Package , PackageOpts < ' a > , FileLock ) > > {
196
200
if ws
197
201
. lock_root ( )
198
202
. as_path_unlocked ( )
@@ -264,7 +268,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
264
268
}
265
269
}
266
270
267
- Ok ( outputs. into_iter ( ) . map ( |x| x . 2 ) . collect ( ) )
271
+ Ok ( outputs)
268
272
}
269
273
270
274
/// Determine which registry the packages are for.
@@ -308,15 +312,14 @@ fn get_registry(
308
312
}
309
313
310
314
/// Just the part of the dependency graph that's between the packages we're packaging.
311
- /// (Is the package name a good key? Does it uniquely identify packages?)
312
315
#[ derive( Clone , Debug , Default ) ]
313
- struct LocalDependencies {
314
- packages : HashMap < PackageId , ( Package , CliFeatures ) > ,
315
- graph : Graph < PackageId , ( ) > ,
316
+ pub ( crate ) struct LocalDependencies < T > {
317
+ pub packages : HashMap < PackageId , ( Package , T ) > ,
318
+ pub graph : Graph < PackageId , ( ) > ,
316
319
}
317
320
318
- impl LocalDependencies {
319
- fn sort ( & self ) -> Vec < ( Package , CliFeatures ) > {
321
+ impl < T : Clone > LocalDependencies < T > {
322
+ pub fn sort ( & self ) -> Vec < ( Package , T ) > {
320
323
self . graph
321
324
. sort ( )
322
325
. into_iter ( )
@@ -335,9 +338,10 @@ impl LocalDependencies {
335
338
/// ignoring dev dependencies.
336
339
///
337
340
/// We assume that the packages all belong to this workspace.
338
- fn local_deps ( packages : impl Iterator < Item = ( Package , CliFeatures ) > ) -> LocalDependencies {
339
- let packages: HashMap < PackageId , ( Package , CliFeatures ) > =
340
- packages. map ( |pkg| ( pkg. 0 . package_id ( ) , pkg) ) . collect ( ) ;
341
+ fn local_deps < T > ( packages : impl Iterator < Item = ( Package , T ) > ) -> LocalDependencies < T > {
342
+ let packages: HashMap < PackageId , ( Package , T ) > = packages
343
+ . map ( |( pkg, payload) | ( pkg. package_id ( ) , ( pkg, payload) ) )
344
+ . collect ( ) ;
341
345
342
346
// Dependencies have source ids but not package ids. We draw an edge
343
347
// whenever a dependency's source id matches one of our packages. This is
@@ -349,7 +353,7 @@ fn local_deps(packages: impl Iterator<Item = (Package, CliFeatures)>) -> LocalDe
349
353
. collect ( ) ;
350
354
351
355
let mut graph = Graph :: new ( ) ;
352
- for ( pkg, _features ) in packages. values ( ) {
356
+ for ( pkg, _payload ) in packages. values ( ) {
353
357
graph. add ( pkg. package_id ( ) ) ;
354
358
for dep in pkg. dependencies ( ) {
355
359
// Ignore local dev-dependencies because they aren't needed for intra-workspace
0 commit comments