Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try installing exact versions before updating #8022

Merged
merged 20 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ percent-encoding = "2.0"
remove_dir_all = "0.5.2"
rustfix = "0.5.0"
same-file = "1"
semver = { version = "0.9.0", features = ["serde"] }
semver = { git = "https://github.com/illicitonion/semver.git", rev = "f1f912703f67ed63b751c525839731a90239bdcf", features = ["serde"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably want an upstream release of this (including dtolnay/semver#205) before merging this PR, but figured I'd see if there was appetite for it first.

serde = { version = "1.0.82", features = ["derive"] }
serde_ignored = "0.1.0"
serde_json = { version = "1.0.30", features = ["raw_value"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ fn meta_test_deep_pretty_print_registry() {
"vec![pkg!((\"foo\", \"1.0.1\") => [dep_req(\"bar\", \"^1\"),]),\
pkg!((\"foo\", \"1.0.0\") => [dep_req(\"bar\", \"^2\"),]),\
pkg!((\"foo\", \"2.0.0\") => [dep(\"bar\"),]),\
pkg!((\"bar\", \"1.0.0\") => [dep_req(\"baz\", \"= 1.0.2\"),dep_req(\"other\", \"^1\"),]),\
pkg!((\"bar\", \"2.0.0\") => [dep_req(\"baz\", \"= 1.0.1\"),]),\
pkg!((\"bar\", \"1.0.0\") => [dep_req(\"baz\", \"=1.0.2\"),dep_req(\"other\", \"^1\"),]),\
pkg!((\"bar\", \"2.0.0\") => [dep_req(\"baz\", \"=1.0.1\"),]),\
pkg!((\"baz\", \"1.0.2\") => [dep_req(\"other\", \"^2\"),]),\
pkg!((\"baz\", \"1.0.1\")),\
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", DepKind::Build, false),]),\
Expand Down
10 changes: 7 additions & 3 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn install_one(
krate,
vers,
config,
true,
NeedsUpdate::True,
&mut |git| git.read_packages(),
)?
} else if source_id.is_path() {
Expand Down Expand Up @@ -180,7 +180,7 @@ fn install_one(
}
}
src.update()?;
select_pkg(src, krate, vers, config, false, &mut |path| {
select_pkg(src, krate, vers, config, NeedsUpdate::False, &mut |path| {
path.read_packages()
})?
} else {
Expand All @@ -189,7 +189,11 @@ fn install_one(
krate,
vers,
config,
is_first_install,
if is_first_install {
NeedsUpdate::TryWithoutFirst
} else {
NeedsUpdate::False
},
illicitonion marked this conversation as resolved.
Show resolved Hide resolved
&mut |_| {
bail!(
"must specify a crate to install from \
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn uninstall_cwd(root: &Filesystem, bins: &[String], config: &Config) -> CargoRe
let tracker = InstallTracker::load(config, root)?;
let source_id = SourceId::for_path(config.cwd())?;
let src = path_source(source_id, config)?;
let pkg = select_pkg(src, None, None, config, true, &mut |path| {
let pkg = select_pkg(src, None, None, config, NeedsUpdate::True, &mut |path| {
path.read_packages()
})?;
let pkgid = pkg.package_id();
Expand Down
28 changes: 24 additions & 4 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,20 @@ pub fn path_source(source_id: SourceId, config: &Config) -> CargoResult<PathSour
Ok(PathSource::new(&path, source_id, config))
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum NeedsUpdate {
True,
False,
TryWithoutFirst,
}

/// Gets a Package based on command-line requirements.
pub fn select_pkg<'a, T>(
mut source: T,
name: Option<&str>,
vers: Option<&str>,
config: &Config,
needs_update: bool,
needs_update: NeedsUpdate,
list_all: &mut dyn FnMut(&mut T) -> CargoResult<Vec<Package>>,
) -> CargoResult<Package>
where
Expand All @@ -542,7 +549,7 @@ where
// with other global Cargos
let _lock = config.acquire_package_cache_lock()?;

if needs_update {
if let NeedsUpdate::True = needs_update {
source.update()?;
illicitonion marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -603,8 +610,21 @@ where
vers
};
let dep = Dependency::parse_no_deprecated(name, vers_spec, source.source_id())?;
let deps = source.query_vec(&dep)?;
match deps.iter().map(|p| p.package_id()).max() {
let deps = (|| {
if let Some(vers_spec) = vers_spec {
if semver::VersionReq::parse(vers_spec).unwrap().is_exact() {
illicitonion marked this conversation as resolved.
Show resolved Hide resolved
let deps = source.query_vec(&dep)?;
if deps.len() == 1 {
return Ok(deps);
}
}
}
if needs_update != NeedsUpdate::False {
source.update()?;
}
source.query_vec(&dep)
})();
match deps?.iter().map(|p| p.package_id()).max() {
Some(pkgid) => {
let pkg = Box::new(&mut source).download_now(pkgid, config)?;
Ok(pkg)
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ fn incompatible_dependencies() {
error: failed to select a version for `bad`.
... required by package `qux v0.1.0`
... which is depended on by `foo v0.0.1 ([..])`
versions that meet the requirements `>= 1.0.1` are: 1.0.2, 1.0.1
versions that meet the requirements `>=1.0.1` are: 1.0.2, 1.0.1

all possible versions conflict with previously selected packages.

Expand Down Expand Up @@ -1038,7 +1038,7 @@ fn incompatible_dependencies_with_multi_semver() {
"\
error: failed to select a version for `bad`.
... required by package `foo v0.0.1 ([..])`
versions that meet the requirements `>= 1.0.1, <= 2.0.0` are: 2.0.0, 1.0.1
versions that meet the requirements `>=1.0.1, <=2.0.0` are: 2.0.0, 1.0.1

all possible versions conflict with previously selected packages.

Expand Down
3 changes: 1 addition & 2 deletions tests/testsuite/install_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ fn ambiguous_version_no_longer_allowed() {
cargo_process("install foo --version=1.0")
.with_stderr(
"\
[UPDATING] `[..]` index
[ERROR] the `--vers` provided, `1.0`, is not a valid semver version: cannot parse '1.0' as a semver
error: the `--vers` provided, `1.0`, is not a valid semver version: cannot parse '1.0' as a semver

if you want to specify semver range, add an explicit qualifier, like ^1.0
",
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn wrong_version() {
.with_status(101)
.with_stderr_contains(
"\
error: failed to select a version for the requirement `foo = \">= 1.0.0\"`
error: failed to select a version for the requirement `foo = \">=1.0.0\"`
candidate versions found which didn't match: 0.0.2, 0.0.1
location searched: `[..]` index (which is replacing registry `[..]`)
required by package `foo v0.0.1 ([..])`
Expand All @@ -240,7 +240,7 @@ required by package `foo v0.0.1 ([..])`
.with_status(101)
.with_stderr_contains(
"\
error: failed to select a version for the requirement `foo = \">= 1.0.0\"`
error: failed to select a version for the requirement `foo = \">=1.0.0\"`
candidate versions found which didn't match: 0.0.4, 0.0.3, 0.0.2, ...
location searched: `[..]` index (which is replacing registry `[..]`)
required by package `foo v0.0.1 ([..])`
Expand Down Expand Up @@ -540,7 +540,7 @@ fn relying_on_a_yank_is_bad() {
.with_status(101)
.with_stderr_contains(
"\
error: failed to select a version for the requirement `baz = \"= 0.0.2\"`
error: failed to select a version for the requirement `baz = \"=0.0.2\"`
candidate versions found which didn't match: 0.0.1
location searched: `[..]` index (which is replacing registry `[..]`)
required by package `bar v0.0.1`
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn override_wrong_name() {
Caused by:
no matching package for override `[..]baz:0.1.0` found
location searched: file://[..]
version required: = 0.1.0
version required: =0.1.0
",
)
.run();
Expand Down