Skip to content

Commit 6cd841f

Browse files
committed
Auto merge of #5462 - matklad:install-releases, r=alexcrichton
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.
2 parents 5db0d51 + 658343a commit 6cd841f

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ where
475475
None => None,
476476
};
477477
let vers = vers.as_ref().map(|s| &**s);
478-
let dep = Dependency::parse_no_deprecated(name, vers, source.source_id())?;
478+
let dep = Dependency::parse_no_deprecated(
479+
name,
480+
Some(vers.unwrap_or("*")),
481+
source.source_id(),
482+
)?;
479483
let deps = source.query_vec(&dep)?;
480484
match deps.iter().map(|p| p.package_id()).max() {
481485
Some(pkgid) => {

tests/testsuite/install.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,20 @@ error: some crates failed to install
113113

114114
#[test]
115115
fn pick_max_version() {
116-
pkg("foo", "0.0.1");
117-
pkg("foo", "0.0.2");
116+
pkg("foo", "0.1.0");
117+
pkg("foo", "0.2.0");
118+
pkg("foo", "0.2.1");
119+
pkg("foo", "0.2.1-pre.1");
120+
pkg("foo", "0.3.0-pre.2");
118121

119122
assert_that(
120123
cargo_process("install").arg("foo"),
121124
execs().with_status(0).with_stderr(&format!(
122125
"\
123126
[UPDATING] registry `[..]`
124-
[DOWNLOADING] foo v0.0.2 (registry [..])
125-
[INSTALLING] foo v0.0.2
126-
[COMPILING] foo v0.0.2
127+
[DOWNLOADING] foo v0.2.1 (registry [..])
128+
[INSTALLING] foo v0.2.1
129+
[COMPILING] foo v0.2.1
127130
[FINISHED] release [optimized] target(s) in [..]
128131
[INSTALLING] {home}[..]bin[..]foo[..]
129132
warning: be sure to add `[..]` to your PATH to be able to run the installed binaries

tests/testsuite/patch.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,3 +1109,52 @@ fn patch_depends_on_another_patch() {
11091109
execs().with_status(0).with_stderr("[FINISHED] [..]"),
11101110
);
11111111
}
1112+
1113+
#[test]
1114+
fn replace_prerelease() {
1115+
Package::new("bar", "1.1.0-pre.1").publish();
1116+
let p = project("foo")
1117+
.file(
1118+
"Cargo.toml",
1119+
r#"
1120+
[workspace]
1121+
members = ["foo"]
1122+
1123+
[patch.crates-io]
1124+
bar = { path = "./bar" }
1125+
"#,
1126+
)
1127+
.file(
1128+
"foo/Cargo.toml",
1129+
r#"
1130+
[project]
1131+
name = "foo"
1132+
version = "0.5.0"
1133+
authors = []
1134+
1135+
[dependencies]
1136+
bar = "1.1.0-pre.1"
1137+
"#,
1138+
)
1139+
.file(
1140+
"foo/src/main.rs",
1141+
"
1142+
extern crate bar;
1143+
fn main() { bar::bar() }
1144+
",
1145+
)
1146+
.file(
1147+
"bar/Cargo.toml",
1148+
r#"
1149+
[project]
1150+
name = "bar"
1151+
version = "1.1.0-pre.1"
1152+
authors = []
1153+
[workspace]
1154+
"#,
1155+
)
1156+
.file("bar/src/lib.rs", "pub fn bar() {}")
1157+
.build();
1158+
1159+
assert_that(p.cargo("build"), execs().with_status(0));
1160+
}

0 commit comments

Comments
 (0)