Skip to content

Commit

Permalink
feat(xcodeproj): create from project root
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Jun 19, 2022
1 parent 7ca1076 commit b5ddde2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
23 changes: 20 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -23,8 +23,25 @@ pub struct XCodeProject {
}

impl XCodeProject {
/// Create new XCodeProject object
pub fn new<P: AsRef<Path>>(xcodeproj_folder: P) -> Result<Self> {
/// Create new XCodeProject object from project root
pub fn new<P: AsRef<Path>>(root: P) -> Result<Self> {
let matches = wax::walk("*.xcodeproj", &root)
.context("Glob")?
.flatten()
.map(|entry| entry.into_path())
.collect::<Vec<PathBuf>>();

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<P: AsRef<Path>>(xcodeproj_folder: P) -> Result<Self> {
let xcodeproj_folder = xcodeproj_folder.as_ref();
let pbxproj_path = xcodeproj_folder.join("project.pbxproj");

Expand Down

0 comments on commit b5ddde2

Please sign in to comment.