diff --git a/src/bin/cargo-compile.rs b/src/bin/cargo-compile.rs index 07d4ccc19..dca60173c 100644 --- a/src/bin/cargo-compile.rs +++ b/src/bin/cargo-compile.rs @@ -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>() -> CLIResult } fn execute() -> CLIResult<()> { - compile(try!(flags::()).manifest_path.as_slice()).to_result(|err| + let options = try!(flags::()); + + 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)) }