diff --git a/Cargo.toml b/Cargo.toml index b608332..fc0c6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xcodeproj" -version = "0.2.7" +version = "0.2.8" edition = "2021" description = "xcodeproj reader and parser." license = "MIT OR Apache-2.0" @@ -28,6 +28,7 @@ derive_is_enum_variant = "0.1.1" enum_variant_macros = "0.2.0" phf = "0.10.1" serde = { version = "1.0.137", features = ["derive"] } +wax = "0.5.0" [dev-dependencies] tracing-test = "0.2.1" diff --git a/src/lib.rs b/src/lib.rs index aa9bc74..2af7d28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ #![deny(rustdoc::broken_intra_doc_links)] #![doc = include_str!("../README.md")] -use anyhow::Result; +use anyhow::{bail, Context, Result}; use pbxproj::PBXRootObject; use std::path::{Path, PathBuf}; @@ -23,8 +23,25 @@ pub struct XCodeProject { } impl XCodeProject { - /// Create new XCodeProject object - pub fn new>(xcodeproj_folder: P) -> Result { + /// Create new XCodeProject object from project root + pub fn new>(root: P) -> Result { + let matches = wax::walk("*.xcodeproj", &root) + .context("Glob")? + .flatten() + .map(|entry| entry.into_path()) + .collect::>(); + + let path = if matches.is_empty() { + bail!("No Xcodeproj found at {:#?}", root.as_ref()); + } else { + &matches[0] + }; + + Self::new_from_xcodeproj_folder(path) + } + + /// Create new XCodeProject object from xcodeproj_folder + pub fn new_from_xcodeproj_folder>(xcodeproj_folder: P) -> Result { let xcodeproj_folder = xcodeproj_folder.as_ref(); let pbxproj_path = xcodeproj_folder.join("project.pbxproj");