Skip to content

Commit 79bb2d7

Browse files
committed
Update pkg-spec comment, and add 2 more test cases
1 parent e97cc80 commit 79bb2d7

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
193193
// specialized compile options specific to the identified package.
194194
// See test `path_install_workspace_root_despite_default_members`.
195195
let mut opts = original_opts.clone();
196-
// Unlike install source tracking (for --git, see above), use the spec url from the
197-
// build workspace (hence unconditional `ws.current()` instead of `pkg` to get `package_id()`).
196+
// For cargo install tracking, we retain the source git url in `pkg`, but for the build spec
197+
// we need to unconditionally use `ws.current()` to correctly address the path where we
198+
// locally cloned that repo.
198199
let pkgidspec = PackageIdSpec::from_package_id(ws.current()?.package_id());
199200
opts.spec = Packages::Packages(vec![pkgidspec.to_string()]);
200201

tests/testsuite/install.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,46 @@ fn path_install_workspace_root_despite_default_members() {
14151415
.run();
14161416
}
14171417

1418+
#[cargo_test]
1419+
fn git_install_workspace_root_despite_default_members() {
1420+
let p = git::repo(&paths::root().join("foo"))
1421+
.file(
1422+
"Cargo.toml",
1423+
r#"
1424+
[package]
1425+
name = "ws-root"
1426+
version = "0.1.0"
1427+
authors = []
1428+
1429+
[workspace]
1430+
members = ["ws-member"]
1431+
default-members = ["ws-member"]
1432+
"#,
1433+
)
1434+
.file("src/main.rs", "fn main() {}")
1435+
.file(
1436+
"ws-member/Cargo.toml",
1437+
r#"
1438+
[package]
1439+
name = "ws-member"
1440+
version = "0.1.0"
1441+
authors = []
1442+
"#,
1443+
)
1444+
.file("ws-member/src/main.rs", "fn main() {}")
1445+
.build();
1446+
1447+
cargo_process("install --git")
1448+
.arg(p.url().to_string())
1449+
.arg("ws-root")
1450+
.with_stderr_contains(
1451+
"[INSTALLED] package `ws-root v0.1.0 ([..])` (executable `ws-root[EXE]`)",
1452+
)
1453+
// Particularly avoid "Installed package `ws-root v0.1.0 ([..]])` (executable `ws-member`)":
1454+
.with_stderr_does_not_contain("ws-member")
1455+
.run();
1456+
}
1457+
14181458
#[cargo_test]
14191459
fn dev_dependencies_no_check() {
14201460
Package::new("foo", "1.0.0").publish();
@@ -2323,3 +2363,48 @@ fn self_referential() {
23232363
.run();
23242364
assert_has_installed_exe(cargo_home(), "foo");
23252365
}
2366+
2367+
#[cargo_test]
2368+
fn ambiguous_registry_vs_local_workspace_package() {
2369+
// Correctly install 'foo' from a workspace, even if that workspace
2370+
// (somewhere) also depends on a registry package named 'foo'.
2371+
Package::new("foo", "0.0.1")
2372+
.file("src/lib.rs", "fn hello() {}")
2373+
.publish();
2374+
2375+
let p = project()
2376+
.file("src/main.rs", "fn main() {}")
2377+
.file(
2378+
"Cargo.toml",
2379+
r#"
2380+
[package]
2381+
name = "foo"
2382+
version = "0.1.0"
2383+
authors = []
2384+
edition = "2021"
2385+
2386+
[dependencies]
2387+
foo = "0.0.1"
2388+
"#,
2389+
)
2390+
.build();
2391+
2392+
cargo_process("install --path")
2393+
.arg(p.root())
2394+
.with_stderr(
2395+
"\
2396+
[INSTALLING] foo v0.1.0 ([..])
2397+
[UPDATING] `[..]` index
2398+
[DOWNLOADING] crates ...
2399+
[DOWNLOADED] foo v0.0.1 (registry [..])
2400+
[COMPILING] foo v0.0.1
2401+
[COMPILING] foo v0.1.0 ([..])
2402+
[FINISHED] release [optimized] target(s) in [..]
2403+
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
2404+
[INSTALLED] package `foo v0.1.0 ([..])` (executable `foo[EXE]`)
2405+
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
2406+
",
2407+
)
2408+
.run();
2409+
assert_has_installed_exe(cargo_home(), "foo");
2410+
}

0 commit comments

Comments
 (0)