Map config paths onto Packages
authorYehuda Katz <wycats@gmail.com>
Thu, 1 May 2014 00:13:50 +0000 (17:13 -0700)
committerYehuda Katz <wycats@gmail.com>
Thu, 1 May 2014 00:14:14 +0000 (17:14 -0700)
TODO: Move this logic into PathSource

src/cargo/core/manifest.rs
src/cargo/ops/cargo_compile.rs
src/cargo/util/config.rs

index c58866e111e08c25cacac4921c270e2c7eb209c9..9568f9504279a790548652b79fc5175c46547127 100644 (file)
@@ -24,7 +24,7 @@ struct SerializedTarget {
 type SerializedLibTarget = SerializedTarget;
 type SerializedExecTarget = SerializedTarget;
 
-#[deriving(Decodable,Encodable,Eq,Clone)]
+#[deriving(Decodable,Encodable,Eq,Clone,Show)]
 pub struct Manifest {
     pub project: ~Project,
     pub root: ~str,
index 24141931f15ce2fbb205a8eed1394c550b97a488..dab23c4ccbbc30e927772c4439723e69598494bc 100644 (file)
@@ -21,7 +21,12 @@ use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError};
 use std::io;
 use std::io::BufReader;
 use std::io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig};
-use {ToCargoError,CargoResult};
+use std::os;
+use util::config;
+use util::config::{all_configs,ConfigValue};
+use cargo_read_manifest = ops::cargo_read_manifest::read_manifest;
+use core::Package;
+use {CargoError,ToCargoError,CargoResult};
 
 #[deriving(Decodable)]
 struct Options {
@@ -36,7 +41,29 @@ pub fn compile() -> CargoResult<()> {
     let options = try!(flags::<Options>());
     let manifest_bytes = try!(read_manifest(options.manifest_path));
 
-    call_rustc(~BufReader::new(manifest_bytes.as_slice()))
+    let configs = try!(all_configs(os::getcwd()));
+    let config_paths = configs.find(&~"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
+
+    let paths = match config_paths.get_value() {
+        &config::String(_) => return Err(CargoError::new(~"The path was configured as a String instead of a List", 1)),
+        &config::List(ref list) => list
+    };
+
+    println!("Paths: {}: {}", paths.len(), paths);
+
+    let packages: Vec<Package> = paths.iter().filter_map(|path| {
+        let joined = Path::new(path.as_slice()).join("Cargo.toml");
+        let manifest = cargo_read_manifest(joined.as_str().unwrap());
+
+        match manifest {
+            Ok(ref manifest) => Some(Package::from_manifest(manifest)),
+            Err(_) => None
+        }
+    }).collect();
+
+    println!("Packages: {}", packages);
+    Ok(())
+    //call_rustc(~BufReader::new(manifest_bytes.as_slice()))
 }
 
 fn flags<T: FlagConfig + Decodable<FlagDecoder, HammerError>>() -> CargoResult<T> {
index cf72a49c58874adbfadb82378f721884a7b3ccc7..bd572d8322c36e848e1f26b196fa71e3a827fefa 100644 (file)
@@ -13,7 +13,7 @@ pub enum Location {
 }
 
 #[deriving(Eq,TotalEq,Clone,Decodable)]
-enum ConfigValueValue {
+pub enum ConfigValueValue {
     String(~str),
     List(Vec<~str>)
 }
@@ -48,6 +48,16 @@ pub struct ConfigValue {
     path: Vec<~str>
 }
 
+impl ConfigValue {
+    pub fn new() -> ConfigValue {
+        ConfigValue { value: List(vec!()), path: vec!() }
+    }
+
+    pub fn get_value<'a>(&'a self) -> &'a ConfigValueValue {
+        &self.value
+    }
+}
+
 impl<E, S: Encoder<E>> Encodable<S, E> for ConfigValue {
     fn encode(&self, s: &mut S) -> Result<(), E> {
         s.emit_map(2, |s| {