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

Don't require cargo update when bumping versions #5215

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 27 additions & 7 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ fn register_previous_locks<'a>(
resolve: &'a Resolve,
keep: &Fn(&&'a PackageId) -> bool,
) {
let path_pkg = |id: &SourceId| {
if !id.is_path() {
return None;
}
if let Ok(path) = id.url().to_file_path() {
if let Ok(pkg) = ws.load(&path.join("Cargo.toml")) {
return Some(pkg);
}
}
None
};

// Ok so we've been passed in a `keep` function which basically says "if I
// return true then this package wasn't listed for an update on the command
// line". AKA if we run `cargo update -p foo` then `keep(bar)` will return
Expand All @@ -376,10 +388,22 @@ fn register_previous_locks<'a>(
// however, nothing else in the dependency graph depends on `log` and the
// newer version of `serde` requires a new version of `log` it'll get pulled
// in (as we didn't accidentally lock it to an old version).
//
// Additionally here we process all path dependencies listed in the previous
// resolve. They can not only have their dependencies change but also
// the versions of the package change as well. If this ends up happening
// then we want to make sure we don't lock a package id node that doesn't
// actually exist. Note that we don't do transitive visits of all the
// package's dependencies here as that'll be covered below to poison those
// if they changed.
let mut avoid_locking = HashSet::new();
for node in resolve.iter() {
if !keep(&node) {
add_deps(resolve, node, &mut avoid_locking);
} else if let Some(pkg) = path_pkg(node.source_id()) {
if pkg.package_id() != node {
avoid_locking.insert(node);
}
}
}

Expand Down Expand Up @@ -425,13 +449,9 @@ fn register_previous_locks<'a>(

// If this is a path dependency then try to push it onto our
// worklist
if source.is_path() {
if let Ok(path) = source.url().to_file_path() {
if let Ok(pkg) = ws.load(&path.join("Cargo.toml")) {
path_deps.push(pkg);
}
continue;
}
if let Some(pkg) = path_pkg(source) {
path_deps.push(pkg);
continue;
}

// If we match *anything* in the dependency graph then we consider
Expand Down
13 changes: 1 addition & 12 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,18 +1453,7 @@ fn compile_path_dep_then_change_version() {
)
.unwrap();

assert_that(
p.cargo("build"),
execs().with_status(101).with_stderr(
"\
error: no matching version `= 0.0.1` found for package `bar`
location searched: [..]
versions found: 0.0.2
required by package `foo v0.0.1 ([..]/foo)`
consider running `cargo update` to update a path dependency's locked version
",
),
);
assert_that(p.cargo("build"), execs().with_status(0));
}

#[test]
Expand Down
44 changes: 44 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,47 @@ fn everything_real_deep() {
p.uncomment_root_manifest();
assert_that(p.cargo("build"), execs().with_status(0));
}

#[test]
fn change_package_version() {
let p = project("foo")
.file(
"Cargo.toml",
r#"
[package]
name = "a-foo"
version = "0.2.0-alpha"
authors = []

[dependencies]
bar = { path = "bar", version = "0.2.0-alpha" }
"#,
)
.file("src/lib.rs", "")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.2.0-alpha"
authors = []
"#,
)
.file("bar/src/lib.rs", "")
.file(
"Cargo.lock",
r#"
[[package]]
name = "foo"
version = "0.2.0"
dependencies = ["bar 0.2.0"]

[[package]]
name = "bar"
version = "0.2.0"
"#,
)
.build();

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