@@ -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 < ' _ > ,
@@ -179,6 +155,29 @@ fn create_package(
179
155
/// Returns the generated package files. If `opts.list` is true, skips
180
156
/// generating package files and returns an empty list.
181
157
pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Vec < FileLock > > {
158
+ Ok ( do_package ( ws, opts) ?. into_iter ( ) . map ( |x| x. 2 ) . collect ( ) )
159
+ }
160
+
161
+ /// Packages an entire workspace.
162
+ ///
163
+ /// Returns the generated package files and the dependencies between them. If
164
+ /// `opts.list` is true, skips generating package files and returns an empty
165
+ /// list.
166
+ pub ( crate ) fn package_with_dep_graph (
167
+ ws : & Workspace < ' _ > ,
168
+ opts : & PackageOpts < ' _ > ,
169
+ ) -> CargoResult < LocalDependencies < ( CliFeatures , FileLock ) > > {
170
+ let output = do_package ( ws, opts) ?;
171
+
172
+ Ok ( local_deps ( output. into_iter ( ) . map (
173
+ |( pkg, opts, tarball) | ( pkg, ( opts. cli_features , tarball) ) ,
174
+ ) ) )
175
+ }
176
+
177
+ fn do_package < ' a > (
178
+ ws : & Workspace < ' _ > ,
179
+ opts : & PackageOpts < ' a > ,
180
+ ) -> CargoResult < Vec < ( Package , PackageOpts < ' a > , FileLock ) > > {
182
181
let specs = & opts. to_package . to_package_id_specs ( ws) ?;
183
182
// If -p is used, we should check spec is matched with the members (See #13719)
184
183
if let ops:: Packages :: Packages ( _) = opts. to_package {
@@ -264,7 +263,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
264
263
}
265
264
}
266
265
267
- Ok ( outputs. into_iter ( ) . map ( |x| x . 2 ) . collect ( ) )
266
+ Ok ( outputs)
268
267
}
269
268
270
269
/// Determine which registry the packages are for.
@@ -308,15 +307,14 @@ fn get_registry(
308
307
}
309
308
310
309
/// 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
310
#[ derive( Clone , Debug , Default ) ]
313
- struct LocalDependencies {
314
- packages : HashMap < PackageId , ( Package , CliFeatures ) > ,
315
- graph : Graph < PackageId , ( ) > ,
311
+ pub ( crate ) struct LocalDependencies < T > {
312
+ pub packages : HashMap < PackageId , ( Package , T ) > ,
313
+ pub graph : Graph < PackageId , ( ) > ,
316
314
}
317
315
318
- impl LocalDependencies {
319
- fn sort ( & self ) -> Vec < ( Package , CliFeatures ) > {
316
+ impl < T : Clone > LocalDependencies < T > {
317
+ pub fn sort ( & self ) -> Vec < ( Package , T ) > {
320
318
self . graph
321
319
. sort ( )
322
320
. into_iter ( )
@@ -335,9 +333,10 @@ impl LocalDependencies {
335
333
/// ignoring dev dependencies.
336
334
///
337
335
/// 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 ( ) ;
336
+ fn local_deps < T > ( packages : impl Iterator < Item = ( Package , T ) > ) -> LocalDependencies < T > {
337
+ let packages: HashMap < PackageId , ( Package , T ) > = packages
338
+ . map ( |( pkg, payload) | ( pkg. package_id ( ) , ( pkg, payload) ) )
339
+ . collect ( ) ;
341
340
342
341
// Dependencies have source ids but not package ids. We draw an edge
343
342
// whenever a dependency's source id matches one of our packages. This is
@@ -349,7 +348,7 @@ fn local_deps(packages: impl Iterator<Item = (Package, CliFeatures)>) -> LocalDe
349
348
. collect ( ) ;
350
349
351
350
let mut graph = Graph :: new ( ) ;
352
- for ( pkg, _features ) in packages. values ( ) {
351
+ for ( pkg, _payload ) in packages. values ( ) {
353
352
graph. add ( pkg. package_id ( ) ) ;
354
353
for dep in pkg. dependencies ( ) {
355
354
// Ignore local dev-dependencies because they aren't needed for intra-workspace
0 commit comments