Skip to content

Commit

Permalink
Build by PackageIdSpec, not name, to avoid ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
tedinski committed Apr 21, 2023
1 parent de80432 commit fa63fd6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::sync::Arc;
use std::{env, fs};

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

let (ws, rustc, target) = make_ws_rustc_target(config, &opts, &source_id, pkg.clone())?;
// If we're installing in --locked mode and there's no `Cargo.lock` published
Expand Down
36 changes: 36 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,3 +2287,39 @@ fn sparse_install() {
"#,
);
}

#[cargo_test]
fn self_referential() {
// Some packages build-dep on prior versions of themselves.
Package::new("foo", "0.0.1")
.file("src/lib.rs", "fn hello() {}")
.file("src/main.rs", "fn main() {}")
.file("build.rs", "fn main() {}")
.publish();
Package::new("foo", "0.0.2")
.file("src/lib.rs", "fn hello() {}")
.file("src/main.rs", "fn main() {}")
.file("build.rs", "fn main() {}")
.build_dep("foo", "0.0.1")
.publish();

cargo_process("install foo")
.with_stderr(
"\
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.2 (registry [..])
[INSTALLING] foo v0.0.2
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry [..])
[COMPILING] foo v0.0.1
[COMPILING] foo v0.0.2
[FINISHED] release [optimized] target(s) in [..]
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.2` (executable `foo[EXE]`)
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
",
)
.run();
assert_has_installed_exe(cargo_home(), "foo");
}

0 comments on commit fa63fd6

Please sign in to comment.