|
1 | | -use super::{PBXHashMap, PBXObject, PBXObjectCollection}; |
| 1 | +use super::{PBXFSReference, PBXHashMap, PBXObject, PBXObjectCollection, PBXProject, PBXTarget}; |
2 | 2 | use anyhow::Result; |
3 | 3 | use std::{ |
4 | 4 | cell::{Ref, RefCell, RefMut}, |
@@ -65,6 +65,29 @@ impl PBXRootObject { |
65 | 65 | pub fn clone_objects<'a>(&'a self) -> Weak<RefCell<PBXObjectCollection>> { |
66 | 66 | Rc::downgrade(&self.objects) |
67 | 67 | } |
| 68 | + |
| 69 | + /// Get Project's targets |
| 70 | + pub fn targets(&self) -> Vec<Rc<RefCell<PBXTarget>>> { |
| 71 | + self.objects() |
| 72 | + .targets() |
| 73 | + .into_iter() |
| 74 | + .map(|(_, o)| o) |
| 75 | + .collect() |
| 76 | + } |
| 77 | + |
| 78 | + /// Get Root PBXProject |
| 79 | + pub fn root_project(&self) -> Option<Rc<RefCell<PBXProject>>> { |
| 80 | + self.objects() |
| 81 | + .projects() |
| 82 | + .into_iter() |
| 83 | + .find(|(k, _)| k == self.root_object_reference()) |
| 84 | + .map(|(_, o)| o) |
| 85 | + } |
| 86 | + |
| 87 | + /// Get root group |
| 88 | + pub fn root_group(&self) -> Option<Rc<RefCell<PBXFSReference>>> { |
| 89 | + Some(self.root_project()?.borrow().main_group()) |
| 90 | + } |
68 | 91 | } |
69 | 92 |
|
70 | 93 | impl TryFrom<PBXHashMap> for PBXRootObject { |
@@ -142,7 +165,9 @@ impl TryFrom<PathBuf> for PBXRootObject { |
142 | 165 | fn test_parse() { |
143 | 166 | let test_content = include_str!("../../tests/samples/demo1.pbxproj"); |
144 | 167 | let project = PBXRootObject::try_from(test_content).unwrap(); |
145 | | - println!("{project:#?}"); |
| 168 | + |
| 169 | + println!("{:#?}", project.root_project()); |
| 170 | + println!("{:#?}", project.targets()); |
146 | 171 | } |
147 | 172 |
|
148 | 173 | #[cfg(test)] |
|
0 commit comments