@@ -13,7 +13,7 @@ use crate::core::resolver::CliFeatures;
13
13
use crate :: core:: resolver:: HasDevUnits ;
14
14
use crate :: core:: { Feature , PackageIdSpecQuery , Shell , Verbosity , Workspace } ;
15
15
use crate :: core:: { Package , PackageId , PackageSet , Resolve , SourceId } ;
16
- use crate :: ops:: registry:: { infer_registry, RegistryOrIndex } ;
16
+ use crate :: ops:: registry:: infer_registry;
17
17
use crate :: sources:: registry:: index:: { IndexPackage , RegistryDependency } ;
18
18
use crate :: sources:: { PathSource , CRATES_IO_REGISTRY } ;
19
19
use crate :: util:: cache_lock:: CacheLockMode ;
@@ -33,6 +33,8 @@ use tar::{Archive, Builder, EntryType, Header, HeaderMode};
33
33
use tracing:: debug;
34
34
use unicase:: Ascii as UncasedAscii ;
35
35
36
+ use super :: RegistryOrIndex ;
37
+
36
38
#[ derive( Clone ) ]
37
39
pub struct PackageOpts < ' gctx > {
38
40
pub gctx : & ' gctx GlobalContext ,
@@ -173,6 +175,46 @@ fn create_package(
173
175
return Ok ( dst) ;
174
176
}
175
177
178
+ /// Determine which registry the packages are for.
179
+ ///
180
+ /// The registry only affects the built packages if there are dependencies within the
181
+ /// packages that we're packaging: if we're packaging foo-bin and foo-lib, and foo-bin
182
+ /// depends on foo-lib, then the foo-lib entry in foo-bin's lockfile will depend on the
183
+ /// registry that we're building packages for.
184
+ fn get_registry (
185
+ gctx : & GlobalContext ,
186
+ pkgs : & [ & Package ] ,
187
+ reg_or_index : Option < RegistryOrIndex > ,
188
+ ) -> CargoResult < SourceId > {
189
+ let reg_or_index = match reg_or_index. clone ( ) {
190
+ Some ( r) => Some ( r) ,
191
+ None => infer_registry ( pkgs) ?,
192
+ } ;
193
+
194
+ // Validate the registry against the packages' allow-lists.
195
+ let reg = reg_or_index
196
+ . clone ( )
197
+ . unwrap_or_else ( || RegistryOrIndex :: Registry ( CRATES_IO_REGISTRY . to_owned ( ) ) ) ;
198
+ if let RegistryOrIndex :: Registry ( reg_name) = reg {
199
+ for pkg in pkgs {
200
+ if let Some ( allowed) = pkg. publish ( ) . as_ref ( ) {
201
+ // If allowed is empty (i.e. package.publish is false), we let it slide.
202
+ // This allows packaging unpublishable packages (although packaging might
203
+ // fail later if the unpublishable package is a dependency of something else).
204
+ if !allowed. is_empty ( ) && !allowed. iter ( ) . any ( |a| a == & reg_name) {
205
+ bail ! (
206
+ "`{}` cannot be packaged.\n \
207
+ The registry `{}` is not listed in the `package.publish` value in Cargo.toml.",
208
+ pkg. name( ) ,
209
+ reg_name
210
+ ) ;
211
+ }
212
+ }
213
+ }
214
+ }
215
+ Ok ( ops:: registry:: get_source_id ( gctx, reg_or_index. as_ref ( ) ) ?. replacement )
216
+ }
217
+
176
218
/// Packages an entire workspace.
177
219
///
178
220
/// Returns the generated package files. If `opts.list` is true, skips
@@ -243,7 +285,9 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
243
285
} else {
244
286
let tarball = create_package ( ws, & pkg, ar_files, local_reg. as_ref ( ) ) ?;
245
287
if let Some ( local_reg) = local_reg. as_mut ( ) {
246
- local_reg. add_package ( ws, & pkg, & tarball) ?;
288
+ if pkg. publish ( ) != & Some ( Vec :: new ( ) ) {
289
+ local_reg. add_package ( ws, & pkg, & tarball) ?;
290
+ }
247
291
}
248
292
outputs. push ( ( pkg, opts, tarball) ) ;
249
293
}
@@ -261,43 +305,6 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
261
305
Ok ( outputs. into_iter ( ) . map ( |x| x. 2 ) . collect ( ) )
262
306
}
263
307
264
- /// Determine which registry the packages are for.
265
- ///
266
- /// The registry only affects the built packages if there are dependencies within the
267
- /// packages that we're packaging: if we're packaging foo-bin and foo-lib, and foo-bin
268
- /// depends on foo-lib, then the foo-lib entry in foo-bin's lockfile will depend on the
269
- /// registry that we're building packages for.
270
- fn get_registry (
271
- gctx : & GlobalContext ,
272
- pkgs : & [ & Package ] ,
273
- reg_or_index : Option < RegistryOrIndex > ,
274
- ) -> CargoResult < SourceId > {
275
- let reg_or_index = match reg_or_index. clone ( ) {
276
- Some ( r) => Some ( r) ,
277
- None => infer_registry ( pkgs) ?,
278
- } ;
279
-
280
- // Validate the registry against the packages' allow-lists.
281
- let reg = reg_or_index
282
- . clone ( )
283
- . unwrap_or_else ( || RegistryOrIndex :: Registry ( CRATES_IO_REGISTRY . to_owned ( ) ) ) ;
284
- if let RegistryOrIndex :: Registry ( reg_name) = reg {
285
- for pkg in pkgs {
286
- if let Some ( allowed) = pkg. publish ( ) . as_ref ( ) {
287
- if !allowed. iter ( ) . any ( |a| a == & reg_name) {
288
- bail ! (
289
- "`{}` cannot be packaged.\n \
290
- The registry `{}` is not listed in the `package.publish` value in Cargo.toml.",
291
- pkg. name( ) ,
292
- reg_name
293
- ) ;
294
- }
295
- }
296
- }
297
- }
298
- Ok ( ops:: registry:: get_source_id ( gctx, reg_or_index. as_ref ( ) ) ?. replacement )
299
- }
300
-
301
308
/// Just the part of the dependency graph that's between the packages we're packaging.
302
309
/// (Is the package name a good key? Does it uniquely identify packages?)
303
310
#[ derive( Clone , Debug , Default ) ]
0 commit comments