Skip to content

Commit

Permalink
Auto merge of #12868 - hi-rustin:rustin-patch-install, r=weihanglo
Browse files Browse the repository at this point in the history
Remove duplicate binaries during install
  • Loading branch information
bors committed Oct 27, 2023
2 parents f327dbd + 731ae05 commit fcc3786
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cargo::util::IntoUrl;
use cargo::util::ToSemver;
use cargo::util::VersionReqExt;
use cargo::CargoResult;
use itertools::Itertools;
use semver::VersionReq;

use cargo_util::paths;
Expand Down Expand Up @@ -119,6 +120,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
.get_many::<CrateVersion>("crate")
.unwrap_or_default()
.cloned()
.dedup_by(|x, y| x == y)
.map(|(krate, local_version)| resolve_crate(krate, local_version, version))
.collect::<crate::CargoResult<Vec<_>>>()?;

Expand Down
22 changes: 22 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ fn simple() {
assert_has_not_installed_exe(cargo_home(), "foo");
}

#[cargo_test]
fn install_the_same_version_twice() {
pkg("foo", "0.0.1");

cargo_process("install foo foo")
.with_stderr(
"\
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.0.1 (registry [..])
[INSTALLING] foo v0.0.1
[COMPILING] foo v0.0.1
[FINISHED] release [optimized] target(s) in [..]
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.1` (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");
}

#[cargo_test]
fn toolchain() {
pkg("foo", "0.0.1");
Expand Down

0 comments on commit fcc3786

Please sign in to comment.