Skip to content

Commit

Permalink
Auto merge of #5462 - matklad:install-releases, r=alexcrichton
Browse files Browse the repository at this point in the history
Don't install pre-releases by default

Currently, `cargo install` will try to install a pre-release version, if available (try `cargo install rand`). This happens because we use `VersionReq::any`, if no version is specified, and that matches pre-releases. The fix is to use `*`, which is different from `any`.

This needs to be done in `cargo install`, and not directly in `parse_no_deprecated`, the latter would be wrong, as demonstrated by a new test with patch.
  • Loading branch information
bors committed May 2, 2018
2 parents 5db0d51 + 658343a commit 6cd841f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,11 @@ where
None => None,
};
let vers = vers.as_ref().map(|s| &**s);
let dep = Dependency::parse_no_deprecated(name, vers, source.source_id())?;
let dep = Dependency::parse_no_deprecated(
name,
Some(vers.unwrap_or("*")),
source.source_id(),
)?;
let deps = source.query_vec(&dep)?;
match deps.iter().map(|p| p.package_id()).max() {
Some(pkgid) => {
Expand Down
13 changes: 8 additions & 5 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,20 @@ error: some crates failed to install

#[test]
fn pick_max_version() {
pkg("foo", "0.0.1");
pkg("foo", "0.0.2");
pkg("foo", "0.1.0");
pkg("foo", "0.2.0");
pkg("foo", "0.2.1");
pkg("foo", "0.2.1-pre.1");
pkg("foo", "0.3.0-pre.2");

assert_that(
cargo_process("install").arg("foo"),
execs().with_status(0).with_stderr(&format!(
"\
[UPDATING] registry `[..]`
[DOWNLOADING] foo v0.0.2 (registry [..])
[INSTALLING] foo v0.0.2
[COMPILING] foo v0.0.2
[DOWNLOADING] foo v0.2.1 (registry [..])
[INSTALLING] foo v0.2.1
[COMPILING] foo v0.2.1
[FINISHED] release [optimized] target(s) in [..]
[INSTALLING] {home}[..]bin[..]foo[..]
warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
Expand Down
49 changes: 49 additions & 0 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,3 +1109,52 @@ fn patch_depends_on_another_patch() {
execs().with_status(0).with_stderr("[FINISHED] [..]"),
);
}

#[test]
fn replace_prerelease() {
Package::new("bar", "1.1.0-pre.1").publish();
let p = project("foo")
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo"]
[patch.crates-io]
bar = { path = "./bar" }
"#,
)
.file(
"foo/Cargo.toml",
r#"
[project]
name = "foo"
version = "0.5.0"
authors = []
[dependencies]
bar = "1.1.0-pre.1"
"#,
)
.file(
"foo/src/main.rs",
"
extern crate bar;
fn main() { bar::bar() }
",
)
.file(
"bar/Cargo.toml",
r#"
[project]
name = "bar"
version = "1.1.0-pre.1"
authors = []
[workspace]
"#,
)
.file("bar/src/lib.rs", "pub fn bar() {}")
.build();

assert_that(p.cargo("build"), execs().with_status(0));
}

0 comments on commit 6cd841f

Please sign in to comment.