};
pub use self::source::{
- Source
+ Source,
+ SourceSet
};
pub use self::summary::{
// The package's manifest
manifest: Manifest,
// The root of the package
- root: Path,
+ manifest_path: Path,
}
#[deriving(Encodable)]
dependencies: Vec<SerializedDependency>,
authors: Vec<String>,
targets: Vec<Target>,
- root: String
+ manifest_path: String
}
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()
}
}
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 {
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());
}
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());
}
}
fn download(&self, packages: &[PackageId]) -> CargoResult<()> {
- for source in self.iter() {
+ for source in self.sources.iter() {
try!(source.download(packages));
}
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());
}
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;
// TODO: Move this into PathSource
let package = try!(PathSource::read_package(manifest_path));
-
debug!("loaded package; package={}", package);
- let configs = try!(config::all_configs(os::getcwd()));
-
- debug!("loaded config; configs={}", configs);
-
- let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
-
- let mut paths: Vec<Path> = match config_paths.get_value() {
- &config::String(_) => return Err(other_error("The path was configured as a String instead of a List")),
- &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect()
- };
+ let sources = try!(sources_for(&package));
- paths.push(Path::new(manifest_path).dir_path());
-
- let source = PathSource::new(paths);
- let summaries = try!(source.list().wrap("unable to list packages from source"));
+ 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!(source.download(resolved.as_slice()).wrap("unable to download packages"));
+ try!(sources.download(resolved.as_slice()).wrap("unable to download packages"));
- let packages = try!(source.get(resolved.as_slice()).wrap("unable to get packages from source"));
+ 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);
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);
+
+ let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
+
+ let mut paths: Vec<Path> = match config_paths.get_value() {
+ &config::String(_) => return Err(other_error("The path was configured as a String instead of a List")),
+ &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect()
+ };
+
+ paths.push_all(additional);
+
+ Ok(vec!(box PathSource::new(paths) as Box<Source>))
+}
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))
}
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))
}
}
}
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 {
"#, 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());