Start pulling out the configured paths

This commit is contained in:
Carlhuda 2014-04-18 18:07:51 -07:00
parent 62bff631e9
commit 6b44764893
5 changed files with 25 additions and 10 deletions

View file

@ -12,7 +12,6 @@ pub struct NameVer {
impl NameVer {
pub fn new(name: &str, version: &str) -> NameVer {
println!("version: {}", version);
NameVer { name: name.to_owned(), version: semver::parse(version.to_owned()).unwrap() }
}

View file

@ -19,9 +19,11 @@ use std::vec::Vec;
use serialize::{Decodable};
use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError};
use std::io;
use std::os;
use std::io::BufReader;
use std::io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig};
use {ToCargoError,CargoResult};
use util::config::{get_config,all_configs};
#[deriving(Decodable)]
struct Options {
@ -34,7 +36,7 @@ impl FlagConfig for Options {
pub fn compile() -> CargoResult<()> {
let options = try!(flags::<Options>());
let manifest_bytes = try!(read_manifest(options.manifest_path).to_cargo_error(~"Could not read manifest", 1));
let manifest_bytes = try!(read_manifest(options.manifest_path));
call_rustc(~BufReader::new(manifest_bytes.as_slice()))
}
@ -66,6 +68,8 @@ fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoRe
}
fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: |&mut ProcessConfig|) -> CargoResult<Process> {
let paths = get_config(os::getcwd(), "source-paths");
let mut config = ProcessConfig::new();
config.program = program;
config.args = args;
@ -73,7 +77,7 @@ fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator:
println!("Executing {} {}", program, args);
let mut process = try!(Process::configure(config).to_cargo_error(~"Could not configure process", 1));
let mut process = try!(Process::configure(config).to_cargo_error(|e: io::IoError| format!("Could not configure process: {}", e), 1));
input.map(|mut reader| io::util::copy(&mut reader, process.stdin.get_mut_ref()));

View file

@ -1,4 +1,3 @@
pub mod path_source;
pub mod cargo_compile;
pub mod cargo_read_manifest;
pub mod cargo_rustc;

View file

@ -1 +0,0 @@
struct PathSourceOp;

View file

@ -1,7 +1,7 @@
extern crate collections;
extern crate toml;
use super::super::{CargoResult,ToCargoError};
use super::super::{CargoResult,ToCargoError,CargoError};
use std::{io,fmt};
#[deriving(Eq,TotalEq,Clone,Encodable,Decodable)]
@ -10,9 +10,15 @@ pub enum Location {
Global
}
#[deriving(Eq,TotalEq,Clone,Encodable,Decodable,Show)]
enum ConfigValueValue {
String(~str),
List(~[~str])
}
#[deriving(Eq,TotalEq,Clone,Encodable,Decodable)]
pub struct ConfigValue {
value: ~str,
value: ConfigValueValue,
path: ~str
}
@ -82,8 +88,15 @@ fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> {
let path = try!(file.path().as_str().to_cargo_error(~"", 1)).to_owned();
let mut buf = io::BufferedReader::new(file);
let root = try!(toml::parse_from_buffer(&mut buf).to_cargo_error(~"", 1));
let val = try!(try!(root.lookup(key).to_cargo_error(~"", 1)).get_str().to_cargo_error(~"", 1));
Ok(ConfigValue{ value: val.to_owned(), path: path })
let val = try!(root.lookup(key).to_cargo_error(~"", 1));
let v = match val {
&toml::String(ref val) => String(val.to_owned()),
&toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()),
_ => return Err(CargoError::new(~"", 1))
};
Ok(ConfigValue{ value: v, path: path })
}
fn extract_all_configs(file: io::fs::File) -> CargoResult<collections::HashMap<~str, ConfigValue>> {
@ -96,7 +109,8 @@ fn extract_all_configs(file: io::fs::File) -> CargoResult<collections::HashMap<~
for (key, value) in table.iter() {
match value {
&toml::String(ref val) => { map.insert(key.to_owned(), ConfigValue { value: val.to_owned(), path: path.clone() }); }
&toml::String(ref val) => { map.insert(key.to_owned(), ConfigValue { value: String(val.to_owned()), path: path.clone() }); }
&toml::Array(ref val) => { map.insert(key.to_owned(), ConfigValue { value: List(val.iter().map(|s: &toml::Value| s.to_str()).collect()), path: path.clone() }); }
_ => ()
}
}