auto merge of #1019 : alexcrichton/cargo/issue-991, r=brson

It turns out that the registry was being queried with git dependencies as well,
so this commit alters the core registry not query sources with dependencies that
did not originate from the source.

Closes #991
This commit is contained in:
bors 2014-12-08 21:19:01 +00:00
commit 0f6667ca06
4 changed files with 62 additions and 5 deletions

View File

@ -89,7 +89,7 @@ impl<'a> PackageRegistry<'a> {
// source
let mut ret = Vec::new();
for source in self.sources.sources_mut() {
for (_, source) in self.sources.sources_mut() {
try!(source.download(package_ids));
let packages = try!(source.get(package_ids));
@ -283,8 +283,10 @@ impl<'a> Registry for PackageRegistry<'a> {
// Ensure the requested source_id is loaded
try!(self.ensure_loaded(dep.get_source_id()));
let mut ret = Vec::new();
for src in self.sources.sources_mut() {
ret.extend(try!(src.query(dep)).into_iter());
for (id, src) in self.sources.sources_mut() {
if id == dep.get_source_id() {
ret.extend(try!(src.query(dep)).into_iter());
}
}
ret
} else {

View File

@ -327,7 +327,7 @@ pub struct SourceMap<'src> {
pub type Sources<'a, 'src> = Values<'a, SourceId, Box<Source+'src>>;
pub type SourcesMut<'a, 'src> = iter::Map<'static, (&'a SourceId,
&'a mut Box<Source+'src>),
&'a mut (Source+'src),
(&'a SourceId, &'a mut (Source+'src)),
MutEntries<'a, SourceId, Box<Source+'src>>>;
impl<'src> SourceMap<'src> {
@ -374,7 +374,7 @@ impl<'src> SourceMap<'src> {
}
pub fn sources_mut<'a>(&'a mut self) -> SourcesMut<'a, 'src> {
self.map.iter_mut().map(|(_, v)| &mut **v)
self.map.iter_mut().map(|(k, v)| (k, &mut **v))
}
}

View File

@ -1,7 +1,10 @@
use std::io::{mod, fs, File};
use url::Url;
use git2;
use support::path2url;
pub struct RepoBuilder {
repo: git2::Repository,
files: Vec<Path>,
@ -47,4 +50,6 @@ impl RepoBuilder {
self.repo.commit(Some("HEAD"), &sig, &sig,
"Initial commit", &tree, &[]).unwrap();
}
pub fn url(&self) -> Url { path2url(self.repo.path().dir_path()) }
}

View File

@ -5,6 +5,7 @@ use support::{project, execs, cargo_dir};
use support::{UPDATING, DOWNLOADING, COMPILING, PACKAGING, VERIFYING};
use support::paths::{mod, PathExt};
use support::registry as r;
use support::git;
use hamcrest::assert_that;
@ -558,3 +559,52 @@ test!(updating_a_dep {
", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice()));
})
test!(git_and_registry_dep {
let b = git::repo(&paths::root().join("b"))
.file("Cargo.toml", r#"
[project]
name = "b"
version = "0.0.1"
authors = []
[dependencies]
a = "0.0.1"
"#)
.file("src/lib.rs", "");
b.build();
let p = project("foo")
.file("Cargo.toml", format!(r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
a = "0.0.1"
[dependencies.b]
git = '{}'
"#, b.url()))
.file("src/main.rs", "fn main() {}");
p.build();
r::mock_pkg("a", "0.0.1", &[]);
p.root().move_into_the_past().unwrap();
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\
{updating} [..]
{updating} [..]
{downloading} a v0.0.1 (registry file://[..])
{compiling} a v0.0.1 (registry [..])
{compiling} b v0.0.1 ([..])
{compiling} foo v0.0.1 ({dir})
", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice()));
p.root().move_into_the_past().unwrap();
println!("second");
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(""));
})