Sources are now an array

This commit is contained in:
Yehuda Katz + Carl Lerche 2014-06-11 15:59:18 -07:00 committed by Tim Carey-Smith
parent c57fef459a
commit 51c9cf0f87
7 changed files with 59 additions and 34 deletions

View File

@ -18,7 +18,8 @@ pub use self::package_id::{
};
pub use self::source::{
Source
Source,
SourceSet
};
pub use self::summary::{

View File

@ -20,7 +20,7 @@ pub struct Package {
// The package's manifest
manifest: Manifest,
// The root of the package
root: Path,
manifest_path: Path,
}
#[deriving(Encodable)]
@ -30,7 +30,7 @@ struct SerializedPackage {
dependencies: Vec<SerializedDependency>,
authors: Vec<String>,
targets: Vec<Target>,
root: String
manifest_path: String
}
impl<E, S: Encoder<E>> Encodable<S, E> for Package {
@ -45,16 +45,16 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Package {
dependencies: summary.get_dependencies().iter().map(|d| SerializedDependency::from_dependency(d)).collect(),
authors: Vec::from_slice(manifest.get_authors()),
targets: Vec::from_slice(manifest.get_targets()),
root: self.root.display().to_str()
manifest_path: self.manifest_path.display().to_str()
}.encode(s)
}
}
impl Package {
pub fn new(manifest: &Manifest, root: &Path) -> Package {
pub fn new(manifest: &Manifest, manifest_path: &Path) -> Package {
Package {
manifest: manifest.clone(),
root: root.clone()
manifest_path: manifest_path.clone()
}
}
@ -90,8 +90,12 @@ impl Package {
self.get_manifest().get_targets()
}
pub fn get_root<'a>(&'a self) -> &'a Path {
&self.root
pub fn get_manifest_path<'a>(&'a self) -> &'a Path {
&self.manifest_path
}
pub fn get_root<'a>(&'a self) -> Path {
self.manifest_path.dir_path()
}
pub fn get_target_dir<'a>(&'a self) -> &'a Path {

View File

@ -36,10 +36,19 @@ pub trait Source {
fn get(&self, packages: &[PackageId]) -> CargoResult<Vec<Package>>;
}
impl Source for Vec<Box<Source>> {
pub struct SourceSet {
sources: Vec<Box<Source>>
}
impl SourceSet {
pub fn new(sources: Vec<Box<Source>>) -> SourceSet {
SourceSet { sources: sources }
}
}
impl Source for SourceSet {
fn update(&self) -> CargoResult<()> {
for source in self.iter() {
for source in self.sources.iter() {
try!(source.update());
}
@ -49,7 +58,7 @@ impl Source for Vec<Box<Source>> {
fn list(&self) -> CargoResult<Vec<Summary>> {
let mut ret = Vec::new();
for source in self.iter() {
for source in self.sources.iter() {
ret.push_all(try!(source.list()).as_slice());
}
@ -57,7 +66,7 @@ impl Source for Vec<Box<Source>> {
}
fn download(&self, packages: &[PackageId]) -> CargoResult<()> {
for source in self.iter() {
for source in self.sources.iter() {
try!(source.download(packages));
}
@ -67,7 +76,7 @@ impl Source for Vec<Box<Source>> {
fn get(&self, packages: &[PackageId]) -> CargoResult<Vec<Package>> {
let mut ret = Vec::new();
for source in self.iter() {
for source in self.sources.iter() {
ret.push_all(try!(source.get(packages)).as_slice());
}

View File

@ -17,7 +17,7 @@
use std::os;
use util::config;
use util::config::{ConfigValue};
use core::{PackageSet,Source};
use core::{Package,PackageSet,Source,SourceSet};
use core::resolver::resolve;
use sources::path::PathSource;
use ops;
@ -28,9 +28,32 @@ pub fn compile(manifest_path: &Path) -> CargoResult<()> {
// TODO: Move this into PathSource
let package = try!(PathSource::read_package(manifest_path));
debug!("loaded package; package={}", package);
let sources = try!(sources_for(&package));
let summaries = try!(sources.list().wrap("unable to list packages from source"));
let resolved = try!(resolve(package.get_dependencies(), &summaries).wrap("unable to resolve dependencies"));
try!(sources.download(resolved.as_slice()).wrap("unable to download packages"));
let packages = try!(sources.get(resolved.as_slice()).wrap("unable to get packages from source"));
log!(5, "fetch packages from source; packages={}; ids={}", packages, resolved);
let package_set = PackageSet::new(packages.as_slice());
try!(ops::compile_packages(&package, &package_set));
Ok(())
}
fn sources_for(package: &Package) -> CargoResult<SourceSet> {
let sources = try!(sources_from_config([package.get_manifest_path().dir_path()]));
Ok(SourceSet::new(sources))
}
fn sources_from_config(additional: &[Path]) -> CargoResult<Vec<Box<Source>>> {
let configs = try!(config::all_configs(os::getcwd()));
debug!("loaded config; configs={}", configs);
@ -42,21 +65,7 @@ pub fn compile(manifest_path: &Path) -> CargoResult<()> {
&config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect()
};
paths.push(Path::new(manifest_path).dir_path());
paths.push_all(additional);
let source = PathSource::new(paths);
let summaries = try!(source.list().wrap("unable to list packages from source"));
let resolved = try!(resolve(package.get_dependencies(), &summaries).wrap("unable to resolve dependencies"));
try!(source.download(resolved.as_slice()).wrap("unable to download packages"));
let packages = try!(source.get(resolved.as_slice()).wrap("unable to get packages from source"));
log!(5, "fetch packages from source; packages={}; ids={}", packages, resolved);
let package_set = PackageSet::new(packages.as_slice());
try!(ops::compile_packages(&package, &package_set));
Ok(())
Ok(vec!(box PathSource::new(paths) as Box<Source>))
}

View File

@ -14,5 +14,5 @@ pub fn read_package(path: &Path, namespace: &Url) -> CargoResult<Package> {
let data = try!(file.read_to_end().map_err(io_error));
let manifest = try!(read_manifest(data.as_slice(), namespace));
Ok(Package::new(&manifest, &path.dir_path()))
Ok(Package::new(&manifest, path))
}

View File

@ -39,7 +39,7 @@ fn compile_pkg(pkg: &Package, dest: &Path, deps_dir: &Path, primary: bool) -> Ca
for target in pkg.get_targets().iter() {
// Only compile lib targets for dependencies
if primary || target.is_lib() {
try!(rustc(pkg.get_root(), target, dest, deps_dir, primary))
try!(rustc(&pkg.get_root(), target, dest, deps_dir, primary))
}
}
@ -52,6 +52,8 @@ fn mk_target(target: &Path) -> CargoResult<()> {
}
fn rustc(root: &Path, target: &Target, dest: &Path, deps: &Path, verbose: bool) -> CargoResult<()> {
log!(5, "root={}; target={}; dest={}; deps={}; verbose={}", root.display(), target, dest.display(), deps.display(), verbose);
let rustc = prepare_rustc(root, target, dest, deps);
try!((if verbose {

View File

@ -20,7 +20,7 @@ fn basic_bin_manifest(name: &str) -> String {
"#, name, name)
}
test!(cargo_compile {
test!(cargo_compile_simple {
let p = project("foo")
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
.file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice());