Skip to content

Commit 31d679e

Browse files
committed
Build by PackageIdSpec, not name, to avoid ambiguity
1 parent c455de9 commit 31d679e

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::sync::Arc;
44
use std::{env, fs};
55

66
use crate::core::compiler::{CompileKind, DefaultExecutor, Executor, UnitOutput};
7-
use crate::core::{Dependency, Edition, Package, PackageId, Source, SourceId, Target, Workspace};
7+
use crate::core::{
8+
Dependency, Edition, Package, PackageId, PackageIdSpec, Source, SourceId, Target, Workspace,
9+
};
810
use crate::ops::{common_for_install_and_uninstall::*, FilterRule};
911
use crate::ops::{CompileFilter, Packages};
1012
use crate::sources::{GitSource, PathSource, SourceConfigMap};
@@ -173,7 +175,8 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
173175
// specialized compile options specific to the identified package.
174176
// See test `path_install_workspace_root_despite_default_members`.
175177
let mut opts = original_opts.clone();
176-
opts.spec = Packages::Packages(vec![pkg.name().to_string()]);
178+
let pkgidspec = PackageIdSpec::from_package_id(pkg.package_id());
179+
opts.spec = Packages::Packages(vec![pkgidspec.to_string()]);
177180

178181
let (ws, rustc, target) = make_ws_rustc_target(config, &opts, &source_id, pkg.clone())?;
179182
// If we're installing in --locked mode and there's no `Cargo.lock` published

tests/testsuite/install.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,3 +2287,39 @@ fn sparse_install() {
22872287
"#,
22882288
);
22892289
}
2290+
2291+
#[cargo_test]
2292+
fn self_referential() {
2293+
// Some packages build-dep on prior versions of themselves.
2294+
Package::new("foo", "0.0.1")
2295+
.file("src/lib.rs", "fn hello() {}")
2296+
.file("src/main.rs", "fn main() {}")
2297+
.file("build.rs", "fn main() {}")
2298+
.publish();
2299+
Package::new("foo", "0.0.2")
2300+
.file("src/lib.rs", "fn hello() {}")
2301+
.file("src/main.rs", "fn main() {}")
2302+
.file("build.rs", "fn main() {}")
2303+
.build_dep("foo", "0.0.1")
2304+
.publish();
2305+
2306+
cargo_process("install foo")
2307+
.with_stderr(
2308+
"\
2309+
[UPDATING] `[..]` index
2310+
[DOWNLOADING] crates ...
2311+
[DOWNLOADED] foo v0.0.2 (registry [..])
2312+
[INSTALLING] foo v0.0.2
2313+
[DOWNLOADING] crates ...
2314+
[DOWNLOADED] foo v0.0.1 (registry [..])
2315+
[COMPILING] foo v0.0.1
2316+
[COMPILING] foo v0.0.2
2317+
[FINISHED] release [optimized] target(s) in [..]
2318+
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
2319+
[INSTALLED] package `foo v0.0.2` (executable `foo[EXE]`)
2320+
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
2321+
",
2322+
)
2323+
.run();
2324+
assert_has_installed_exe(cargo_home(), "foo");
2325+
}

0 commit comments

Comments
 (0)