Skip to content

Commit e444425

Browse files
authored
fix(publish): Allow dry-run of a non-bumped workspace (#14847)
### What does this PR try to resolve? A dry-run release process won't be bumping the versions, making it so it can't do a dry-run publish because the local/remote registries will collide. This switches it to give the local registry precedence over the remote registry to make the dry-run release process work. Fixes #14789 ### How should we test and review this PR? ### Additional information
2 parents 81848c3 + ad23d73 commit e444425

File tree

3 files changed

+42
-55
lines changed

3 files changed

+42
-55
lines changed

src/cargo/sources/overlay.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,16 @@ impl<'gctx> Source for DependencyConfusionThreatOverlaySource<'gctx> {
6363
};
6464
ready!(self.local.query(&local_dep, kind, &mut local_callback))?;
6565

66-
let mut package_collision = None;
6766
let mut remote_callback = |index: IndexSummary| {
6867
if local_packages.contains(index.as_summary()) {
69-
package_collision = Some(index.as_summary().clone());
68+
tracing::debug!(?local_source, ?remote_source, ?index, "package collision");
69+
} else {
70+
f(index)
7071
}
71-
f(index)
7272
};
7373
ready!(self.remote.query(dep, kind, &mut remote_callback))?;
7474

75-
if let Some(collision) = package_collision {
76-
std::task::Poll::Ready(Err(anyhow::anyhow!(
77-
"found a package in the remote registry and the local overlay: {}@{}",
78-
collision.name(),
79-
collision.version()
80-
)))
81-
} else {
82-
std::task::Poll::Ready(Ok(()))
83-
}
75+
std::task::Poll::Ready(Ok(()))
8476
}
8577

8678
fn invalidate_cache(&mut self) {

tests/testsuite/package.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -6056,20 +6056,21 @@ fn workspace_with_local_dep_already_published_nightly() {
60566056
p.cargo("package -Zpackage-workspace")
60576057
.masquerade_as_nightly_cargo(&["package-workspace"])
60586058
.replace_crates_io(reg.index_url())
6059-
.with_status(101)
60606059
.with_stderr_data(
60616060
str![[r#"
60626061
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
60636062
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
60646063
[UPDATING] crates.io index
6065-
[ERROR] failed to prepare local package for uploading
6066-
6067-
Caused by:
6068-
failed to get `dep` as a dependency of package `main v0.0.1 ([ROOT]/foo/main)`
6069-
6070-
Caused by:
6071-
found a package in the remote registry and the local overlay: [email protected]
60726064
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6065+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6066+
[VERIFYING] dep v0.1.0 ([ROOT]/foo/dep)
6067+
[COMPILING] dep v0.1.0 ([ROOT]/foo/target/package/dep-0.1.0)
6068+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6069+
[VERIFYING] main v0.0.1 ([ROOT]/foo/main)
6070+
[UNPACKING] dep v0.1.0 (registry `[ROOT]/foo/target/package/tmp-registry`)
6071+
[COMPILING] dep v0.1.0
6072+
[COMPILING] main v0.0.1 ([ROOT]/foo/target/package/main-0.0.1)
6073+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
60736074
60746075
"#]]
60756076
.unordered(),

tests/testsuite/registry_overlay.rs

+29-35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use cargo_test_support::prelude::*;
44
use cargo_test_support::project;
55
use cargo_test_support::registry::{Package, RegistryBuilder, TestRegistry};
6+
use cargo_test_support::str;
67

78
fn setup() -> (TestRegistry, String) {
89
let alt = RegistryBuilder::new().alternative().build();
@@ -77,17 +78,16 @@ fn registry_version_wins() {
7778

7879
p.cargo("check")
7980
.overlay_registry(&reg.index_url(), &alt_path)
80-
.with_stderr_data(
81-
"\
82-
[UPDATING] [..]
81+
.with_stderr_data(str![[r#"
82+
[UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
8383
[LOCKING] 1 package to latest compatible version
8484
[DOWNLOADING] crates ...
85-
[DOWNLOADED] baz v0.1.1 (registry [..])
85+
[DOWNLOADED] baz v0.1.1 (registry `sparse+http://127.0.0.1:[..]/index/`)
8686
[CHECKING] baz v0.1.1
8787
[CHECKING] foo v0.0.1 ([ROOT]/foo)
8888
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
89-
",
90-
)
89+
90+
"#]])
9191
.run();
9292
}
9393

@@ -120,21 +120,20 @@ fn overlay_version_wins() {
120120

121121
p.cargo("check")
122122
.overlay_registry(&reg.index_url(), &alt_path)
123-
.with_stderr_data(
124-
"\
125-
[UPDATING] [..]
123+
.with_stderr_data(str![[r#"
124+
[UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
126125
[LOCKING] 1 package to latest compatible version
127-
[UNPACKING] baz v0.1.1 (registry [..])
126+
[UNPACKING] baz v0.1.1 (registry `[ROOT]/alternative-registry`)
128127
[CHECKING] baz v0.1.1
129128
[CHECKING] foo v0.0.1 ([ROOT]/foo)
130129
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
131-
",
132-
)
130+
131+
"#]])
133132
.run();
134133
}
135134

136135
#[cargo_test]
137-
fn version_collision() {
136+
fn version_precedence() {
138137
let (reg, alt_path) = setup();
139138
let p = project()
140139
.file(
@@ -162,19 +161,15 @@ fn version_collision() {
162161

163162
p.cargo("check")
164163
.overlay_registry(&reg.index_url(), &alt_path)
165-
.with_status(101)
166-
.with_stderr_data(
167-
"\
168-
[UPDATING] [..]
169-
[ERROR] failed to get `baz` [..]
170-
171-
Caused by:
172-
failed to query replaced source registry `crates-io`
173-
174-
Caused by:
175-
found a package in the remote registry and the local overlay: [email protected]
176-
",
177-
)
164+
.with_stderr_data(str![[r#"
165+
[UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
166+
[LOCKING] 1 package to latest compatible version
167+
[UNPACKING] baz v0.1.1 (registry `[ROOT]/alternative-registry`)
168+
[CHECKING] baz v0.1.1
169+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
170+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
171+
172+
"#]])
178173
.run();
179174
}
180175

@@ -248,22 +243,21 @@ fn registry_dep_depends_on_new_local_package() {
248243

249244
p.cargo("check")
250245
.overlay_registry(&reg.index_url(), &alt_path)
251-
.with_stderr_data(
252-
"\
253-
[UPDATING] [..]
246+
.with_stderr_data(str![[r#"
247+
[UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
254248
[LOCKING] 3 packages to latest compatible versions
255249
[ADDING] workspace-package v0.0.1 (available: v0.1.1)
256250
[DOWNLOADING] crates ...
257-
[UNPACKING] [..]
258-
[DOWNLOADED] [..]
259-
[DOWNLOADED] [..]
251+
[UNPACKING] workspace-package v0.1.1 (registry `[ROOT]/alternative-registry`)
252+
[DOWNLOADED] registry-package v0.1.0 (registry `sparse+http://127.0.0.1:[..]/index/`)
253+
[DOWNLOADED] workspace-package v0.0.1 (registry `sparse+http://127.0.0.1:[..]/index/`)
260254
[CHECKING] workspace-package v0.1.1
261255
[CHECKING] workspace-package v0.0.1
262256
[CHECKING] registry-package v0.1.0
263-
[CHECKING] foo v0.0.1 [..]
257+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
264258
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
265-
",
266-
)
259+
260+
"#]])
267261
.run();
268262
}
269263

0 commit comments

Comments
 (0)