4 use std::path::{Path, PathBuf};
9 cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
13 // TODO use own error enum?
14 pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
16 #[derive(Debug, Clone)]
17 pub struct ProjectWorkspace {
18 pub cargo: CargoWorkspace,
22 impl ProjectWorkspace {
23 pub fn discover(path: &Path) -> Result<ProjectWorkspace> {
24 let cargo_toml = find_cargo_toml(path)?;
25 let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml)?;
26 let sysroot = Sysroot::discover(&cargo_toml)?;
27 let res = ProjectWorkspace { cargo, sysroot };
32 fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
33 if path.ends_with("Cargo.toml") {
34 return Ok(path.to_path_buf());
36 let mut curr = Some(path);
37 while let Some(path) = curr {
38 let candidate = path.join("Cargo.toml");
39 if candidate.exists() {
44 bail!("can't find Cargo.toml at {}", path.display())