Skip to content

Commit a32f073

Browse files
authored
fix(package): Skip registry check if its not needed (#15629)
### What does this PR try to resolve? As of #13947, `-Zpackage-workspace` made `cargo package` require extra arguments when it didn't need it before. When a packaging operation will resolve dependencies, we need to know what registry packages would be published to in order to correctly generate the overlay to generate the right lockfile. We skipped this if there were no dependencies, so no overlay was going to be used, to reduce the impact of this. This change goes a step further and only runs the check if the resolver will run. This should mean that `-Zpackage-workspace` should now only error when `cargo package` would have failed before. ### How to test and review this PR? To verify this, the existing failure tests were forked, removing `-Zpackage-workspace`, and then `--exclude-lockfile`, `--no-verify`, and `--exclude-lockfile --no-verify` variants were added to characterize when the check is behavior-neutral vs not needed and that the behavior is now the same.
2 parents 21601a2 + 094ef50 commit a32f073

File tree

2 files changed

+437
-6
lines changed

2 files changed

+437
-6
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,18 @@ fn do_package<'a>(
240240
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
241241

242242
let mut local_reg = if ws.gctx().cli_unstable().package_workspace {
243-
// The publish registry doesn't matter unless there are local dependencies,
243+
// The publish registry doesn't matter unless there are local dependencies that will be
244+
// resolved,
244245
// so only try to get one if we need it. If they explicitly passed a
245246
// registry on the CLI, we check it no matter what.
246-
let sid = if deps.has_no_dependencies() && opts.reg_or_index.is_none() {
247-
None
248-
} else {
247+
let sid = if (deps.has_dependencies() && (opts.include_lockfile || opts.verify))
248+
|| opts.reg_or_index.is_some()
249+
{
249250
let sid = get_registry(ws.gctx(), &just_pkgs, opts.reg_or_index.clone())?;
250251
debug!("packaging for registry {}", sid);
251252
Some(sid)
253+
} else {
254+
None
252255
};
253256
let reg_dir = ws.build_dir().join("package").join("tmp-registry");
254257
sid.map(|sid| TmpRegistry::new(ws.gctx(), reg_dir, sid))
@@ -377,10 +380,10 @@ impl<T: Clone> LocalDependencies<T> {
377380
.collect()
378381
}
379382

380-
pub fn has_no_dependencies(&self) -> bool {
383+
pub fn has_dependencies(&self) -> bool {
381384
self.graph
382385
.iter()
383-
.all(|node| self.graph.edges(node).next().is_none())
386+
.any(|node| self.graph.edges(node).next().is_some())
384387
}
385388
}
386389

0 commit comments

Comments
 (0)