@@ -29,6 +29,7 @@ pub struct PackageOpts<'cfg> {
2929 pub allow_dirty : bool ,
3030 pub verify : bool ,
3131 pub jobs : Option < u32 > ,
32+ pub to_package : ops:: Packages ,
3233 pub targets : Vec < String > ,
3334 pub cli_features : CliFeatures ,
3435}
@@ -61,16 +62,12 @@ enum GeneratedFile {
6162 VcsInfo ( String ) ,
6263}
6364
64- pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Option < FileLock > > {
65- if ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
66- // Make sure the Cargo.lock is up-to-date and valid.
67- let _ = ops:: resolve_ws ( ws) ?;
68- // If Cargo.lock does not exist, it will be generated by `build_lock`
69- // below, and will be validated during the verification step.
70- }
71- let pkg = ws. current ( ) ?;
65+ pub fn package_one (
66+ ws : & Workspace < ' _ > ,
67+ pkg : & Package ,
68+ opts : & PackageOpts < ' _ > ,
69+ ) -> CargoResult < Option < FileLock > > {
7270 let config = ws. config ( ) ;
73-
7471 let mut src = PathSource :: new ( pkg. root ( ) , pkg. package_id ( ) . source_id ( ) , config) ;
7572 src. update ( ) ?;
7673
@@ -96,12 +93,13 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
9693 None
9794 } ;
9895
99- let ar_files = build_ar_list ( ws, pkg, src_files, vcs_info) ?;
96+ let ar_files = build_ar_list ( & ws, pkg, src_files, vcs_info) ?;
10097
10198 if opts. list {
10299 for ar_file in ar_files {
103100 drop_println ! ( config, "{}" , ar_file. rel_str) ;
104101 }
102+
105103 return Ok ( None ) ;
106104 }
107105
@@ -125,20 +123,65 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
125123 . shell ( )
126124 . status ( "Packaging" , pkg. package_id ( ) . to_string ( ) ) ?;
127125 dst. file ( ) . set_len ( 0 ) ?;
128- tar ( ws , ar_files, dst. file ( ) , & filename)
126+ tar ( & ws , pkg , ar_files, dst. file ( ) , & filename)
129127 . with_context ( || "failed to prepare local package for uploading" ) ?;
130128 if opts. verify {
131129 dst. seek ( SeekFrom :: Start ( 0 ) ) ?;
132- run_verify ( ws , & dst, opts) . with_context ( || "failed to verify package tarball" ) ?
130+ run_verify ( & ws , pkg , & dst, opts) . with_context ( || "failed to verify package tarball" ) ?
133131 }
132+
134133 dst. seek ( SeekFrom :: Start ( 0 ) ) ?;
135- {
136- let src_path = dst. path ( ) ;
137- let dst_path = dst. parent ( ) . join ( & filename) ;
138- fs:: rename ( & src_path, & dst_path)
139- . with_context ( || "failed to move temporary tarball into final location" ) ?;
134+ let src_path = dst. path ( ) ;
135+ let dst_path = dst. parent ( ) . join ( & filename) ;
136+ fs:: rename ( & src_path, & dst_path)
137+ . with_context ( || "failed to move temporary tarball into final location" ) ?;
138+
139+ return Ok ( Some ( dst) ) ;
140+ }
141+
142+ pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Option < Vec < FileLock > > > {
143+ let pkgs = ws. members_with_features (
144+ & opts. to_package . to_package_id_specs ( ws) ?,
145+ & opts. cli_features ,
146+ ) ?;
147+
148+ let mut dsts = Vec :: with_capacity ( pkgs. len ( ) ) ;
149+
150+ if ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
151+ // Make sure the Cargo.lock is up-to-date and valid.
152+ let _ = ops:: resolve_ws ( & ws) ?;
153+ // If Cargo.lock does not exist, it will be generated by `build_lock`
154+ // below, and will be validated during the verification step.
155+ }
156+
157+ for ( pkg, cli_features) in pkgs {
158+ let result = package_one (
159+ ws,
160+ pkg,
161+ & PackageOpts {
162+ config : opts. config ,
163+ list : opts. list ,
164+ check_metadata : opts. check_metadata ,
165+ allow_dirty : opts. allow_dirty ,
166+ verify : opts. verify ,
167+ jobs : opts. jobs ,
168+ to_package : ops:: Packages :: Default ,
169+ targets : opts. targets . clone ( ) ,
170+ cli_features : cli_features,
171+ } ,
172+ ) ?;
173+
174+ if !opts. list {
175+ dsts. push ( result. unwrap ( ) ) ;
176+ }
177+ }
178+
179+ if opts. list {
180+ // We're just listing, so there's no file output
181+ Ok ( None )
182+ } else {
183+ Ok ( Some ( dsts) )
140184 }
141- Ok ( Some ( dst) )
142185}
143186
144187/// Builds list of files to archive.
@@ -265,12 +308,11 @@ fn build_ar_list(
265308}
266309
267310/// Construct `Cargo.lock` for the package to be published.
268- fn build_lock ( ws : & Workspace < ' _ > ) -> CargoResult < String > {
311+ fn build_lock ( ws : & Workspace < ' _ > , orig_pkg : & Package ) -> CargoResult < String > {
269312 let config = ws. config ( ) ;
270313 let orig_resolve = ops:: load_pkg_lockfile ( ws) ?;
271314
272315 // Convert Package -> TomlManifest -> Manifest -> Package
273- let orig_pkg = ws. current ( ) ?;
274316 let toml_manifest = Rc :: new (
275317 orig_pkg
276318 . manifest ( )
@@ -473,6 +515,7 @@ fn check_repo_state(
473515
474516fn tar (
475517 ws : & Workspace < ' _ > ,
518+ pkg : & Package ,
476519 ar_files : Vec < ArchiveFile > ,
477520 dst : & File ,
478521 filename : & str ,
@@ -485,7 +528,6 @@ fn tar(
485528
486529 // Put all package files into a compressed archive.
487530 let mut ar = Builder :: new ( encoder) ;
488- let pkg = ws. current ( ) ?;
489531 let config = ws. config ( ) ;
490532
491533 let base_name = format ! ( "{}-{}" , pkg. name( ) , pkg. version( ) ) ;
@@ -519,7 +561,7 @@ fn tar(
519561 FileContents :: Generated ( generated_kind) => {
520562 let contents = match generated_kind {
521563 GeneratedFile :: Manifest => pkg. to_registry_toml ( ws) ?,
522- GeneratedFile :: Lockfile => build_lock ( ws) ?,
564+ GeneratedFile :: Lockfile => build_lock ( ws, pkg ) ?,
523565 GeneratedFile :: VcsInfo ( s) => s,
524566 } ;
525567 header. set_entry_type ( EntryType :: file ( ) ) ;
@@ -647,9 +689,13 @@ fn check_yanked(config: &Config, pkg_set: &PackageSet<'_>, resolve: &Resolve) ->
647689 Ok ( ( ) )
648690}
649691
650- fn run_verify ( ws : & Workspace < ' _ > , tar : & FileLock , opts : & PackageOpts < ' _ > ) -> CargoResult < ( ) > {
692+ fn run_verify (
693+ ws : & Workspace < ' _ > ,
694+ pkg : & Package ,
695+ tar : & FileLock ,
696+ opts : & PackageOpts < ' _ > ,
697+ ) -> CargoResult < ( ) > {
651698 let config = ws. config ( ) ;
652- let pkg = ws. current ( ) ?;
653699
654700 config. shell ( ) . status ( "Verifying" , pkg) ?;
655701
0 commit comments