Skip to content

Commit

Permalink
auto merge of #990 : alexcrichton/cargo/update-blows-up, r=brson
Browse files Browse the repository at this point in the history
This is the same as the fix for #951 (fixed by #965). The relevant code was
erroneously looking at the source id when it should instead look at the entire
package id (name/version/source).
  • Loading branch information
bors committed Dec 4, 2014
2 parents d3917d5 + 493d310 commit 4353abb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,18 @@ impl<'a> PackageRegistry<'a> {
// sure to lock to precisely the given package id.
//
// 2. We have a lock entry for this dependency, but it's from a
// different source than what's listed. In this case we must
// discard the locked version because the listed source must
// have changed.
// different source than what's listed, or the version
// requirement has changed. In this case we must discard the
// locked version because the dependency needs to be
// re-resolved.
//
// 3. We don't have a lock entry for this dependency, in which
// case it was likely an optional dependency which wasn't
// included previously so we just pass it through anyway.
Some(&(_, ref deps)) => {
match deps.iter().find(|d| d.get_name() == dep.get_name()) {
Some(lock) => {
if lock.get_source_id() == dep.get_source_id() {
if dep.matches_id(lock) {
dep.lock_to(lock)
} else {
dep
Expand Down
59 changes: 59 additions & 0 deletions tests/test_cargo_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,62 @@ test!(bad_license_file {
.with_stderr("\
the license file `foo` does not exist"));
})

test!(updating_a_dep {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.a]
path = "a"
"#)
.file("src/main.rs", "fn main() {}")
.file("a/Cargo.toml", r#"
[project]
name = "a"
version = "0.0.1"
authors = []
[dependencies]
bar = "*"
"#)
.file("a/src/lib.rs", "");
p.build();

r::mock_pkg("bar", "0.0.1", &[]);

assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\
{updating} registry `[..]`
{downloading} bar v0.0.1 (registry file://[..])
{compiling} bar v0.0.1 (registry file://[..])
{compiling} a v0.0.1 ({dir})
{compiling} foo v0.0.1 ({dir})
", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice()));

File::create(&p.root().join("a/Cargo.toml")).write_str(r#"
[project]
name = "a"
version = "0.0.1"
authors = []
[dependencies]
bar = "0.1.0"
"#).unwrap();
r::mock_pkg("bar", "0.1.0", &[]);

println!("second");
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\
{updating} registry `[..]`
{downloading} bar v0.1.0 (registry file://[..])
{compiling} bar v0.1.0 (registry file://[..])
{compiling} a v0.0.1 ({dir})
{compiling} foo v0.0.1 ({dir})
", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice()));
})

0 comments on commit 4353abb

Please sign in to comment.