Have cargo-compile automatically find the root

TODO: Deal with Paths vs. Strings (which come from serialized forms like
flags and manifests)
This commit is contained in:
Yehuda Katz 2014-05-07 16:46:43 -07:00
parent d28ce72351
commit 0bec82d6ea

View file

@ -7,12 +7,14 @@ extern crate serialize;
use cargo::ops::cargo_compile::compile;
use cargo::core::errors::{CLIResult,CLIError,ToResult};
use cargo::util::important_paths::find_project;
use hammer::{FlagDecoder,FlagConfig,HammerError};
use serialize::Decodable;
use std::os;
#[deriving(Eq,Clone,Decodable,Encodable)]
pub struct Options {
manifest_path: ~str
manifest_path: Option<~str>
}
impl FlagConfig for Options {}
@ -23,7 +25,17 @@ fn flags<T: FlagConfig + Decodable<FlagDecoder, HammerError>>() -> CLIResult<T>
}
fn execute() -> CLIResult<()> {
compile(try!(flags::<Options>()).manifest_path.as_slice()).to_result(|err|
let options = try!(flags::<Options>());
let root = match options.manifest_path {
Some(path) => Path::new(path),
None => try!(find_project(os::getcwd(), "Cargo.toml".to_owned())
.map(|path| path.join("Cargo.toml"))
.to_result(|err|
CLIError::new("Could not find Cargo.toml in this directory or any parent directory", Some(err.to_str()), 1)))
};
compile(root.as_str().unwrap().as_slice()).to_result(|err|
CLIError::new(format!("Compilation failed: {}", err), None, 1))
}