Sources are now an array
authorYehuda Katz + Carl Lerche <engineering@tilde.io>
Wed, 11 Jun 2014 22:59:18 +0000 (15:59 -0700)
committerTim Carey-Smith <tim@spork.in>
Wed, 11 Jun 2014 22:59:18 +0000 (15:59 -0700)
src/cargo/core/mod.rs
src/cargo/core/package.rs
src/cargo/core/source.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_read_manifest.rs
src/cargo/ops/cargo_rustc.rs
tests/test_cargo_compile.rs

index 6fe7ff9c9f86d3de0380ab9928b9c19f7bb73136..781d200871ceff1d0335c2012359179b43efa7c2 100644 (file)
@@ -18,7 +18,8 @@ pub use self::package_id::{
 };
 
 pub use self::source::{
-    Source
+    Source,
+    SourceSet
 };
 
 pub use self::summary::{
index ff83846a74f25bc44de8d720b3d9efefbfae4af2..6c9ef6a7ef0e72c09f9e1933a2b0f0f3a1ac45fe 100644 (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 {
index c77caa30cc9d0a72e6746dc8518811beea1c3096..63ee91e525c77b62343233bb51b1d82a857adf4d 100644 (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());
         }
 
index d68543a1201124fe48b8bcad1fffe059138a7ae6..e43200a16a4c4cda6d8185f90278f20112960ace 100644 (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,29 +28,16 @@ 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 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);
 
@@ -60,3 +47,25 @@ pub fn compile(manifest_path: &Path) -> CargoResult<()> {
 
     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>))
+}
index 97ea1755d057a965988965d57b73a28be549da83..1d0f8c4c42f969638619c39aebe9757b07499c5e 100644 (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))
 }
index 6e2925cbd7101bbd5e1a85248aaae19bd0c3a2ee..957302f7d7490aaecaef0ab3fc74059cbf433ad6 100644 (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 {
index deeb20fbc38b0d07e084fc2fc62dc3feb2993338..1fad32a04727176498cff9bc0d378607c67fff89 100644 (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());