mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 19:22:33 +00:00
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:
parent
d28ce72351
commit
0bec82d6ea
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue