1+ mod full_path;
12mod kind;
23mod obj;
34mod setget;
@@ -123,95 +124,6 @@ impl PBXFSReference {
123124 pub fn parent ( & self ) -> Option < Rc < RefCell < Self > > > {
124125 self . parent . upgrade ( )
125126 }
126-
127- /// Returns a file path to current fs reference using source root.
128- pub fn full_path < P : AsRef < Path > > ( & self , source_root : P ) -> Result < PathBuf > {
129- let source_root = source_root. as_ref ( ) ;
130-
131- let path = || {
132- self . path ( )
133- . ok_or_else ( || anyhow:: anyhow!( "Expected path to be set in file element!!" ) )
134- } ;
135-
136- fn get_parts ( path : & String ) -> Vec < & str > {
137- if path. contains ( "/" ) {
138- path. split ( "/" ) . collect ( )
139- } else {
140- vec ! [ path]
141- }
142- }
143-
144- match self . source_tree ( ) {
145- Some ( PBXSourceTree :: Absolute ) => path ( ) ?. pipe ( PathBuf :: from) ,
146- Some ( PBXSourceTree :: SourceRoot ) => {
147- let mut root = source_root. to_path_buf ( ) ;
148- root. extend ( get_parts ( path ( ) ?) ) ;
149- root
150- }
151- Some ( PBXSourceTree :: Group ) => {
152- let mut group_path: PathBuf ;
153-
154- if let Some ( parent) = self . parent ( ) {
155- println ! ( "Using parent path" ) ;
156- group_path = parent. borrow ( ) . full_path ( & source_root) ?;
157- if let Some ( path) = self . path ( ) {
158- group_path. extend ( get_parts ( path) )
159- }
160- } else {
161- let objects = self
162- . objects
163- . upgrade ( )
164- . ok_or_else ( || anyhow:: anyhow!( "objects is released already!" ) ) ?;
165-
166- let objects = objects. borrow ( ) ;
167-
168- if objects
169- . projects ( )
170- . into_iter ( )
171- . find ( |( _, p) | & * p. borrow ( ) . main_group ( ) . borrow ( ) == self )
172- . is_some ( )
173- {
174- if let Some ( path) = self . path ( ) {
175- let mut root = source_root. to_path_buf ( ) ;
176- root. extend ( get_parts ( path) ) ;
177- println ! ( "Joining {source_root:?} with {path:?}" ) ;
178- return Ok ( root) ;
179- } else {
180- println ! ( "Self is main group and return source_root as is!" ) ;
181- return Ok ( source_root. to_path_buf ( ) ) ;
182- }
183- }
184-
185- println ! ( "Falling back to search through all groups" ) ;
186-
187- // Fallback if parent is nil and it's not root element
188- let group = objects
189- . groups ( )
190- . into_iter ( )
191- . find ( |( _, o) | {
192- o. borrow ( )
193- . children ( )
194- . into_iter ( )
195- . any ( |o| & * o. borrow ( ) == self )
196- } )
197- . map ( |( _, o) | o)
198- . ok_or_else ( || {
199- anyhow:: anyhow!(
200- "Invalid group path {source_root:?} with {:?}" ,
201- self . path( )
202- )
203- } ) ?;
204-
205- group_path = group. borrow ( ) . full_path ( source_root) ?;
206- }
207- group_path
208- }
209- _ => {
210- bail ! ( "Can't get full_path from {:#?}" , self )
211- }
212- }
213- . pipe ( Ok )
214- }
215127}
216128
217129impl Eq for PBXFSReference { }
@@ -241,35 +153,10 @@ impl PartialEq for PBXFSReference {
241153 }
242154}
243155
244- #[ test]
245- fn test_parent ( ) {
246- use crate :: pbxproj:: test_demo_file;
247- let project = test_demo_file ! ( demo1) ;
248- let main_group = project
249- . objects ( )
250- . projects ( )
251- . first ( )
252- . unwrap ( )
253- . 1
254- . borrow ( )
255- . main_group ( ) ;
256-
257- let main_group = main_group. borrow ( ) ;
258- let source_group = main_group. get_subgroup ( "Source" ) . unwrap ( ) ;
259- let source_group = source_group. borrow ( ) ;
260- let parent = source_group. parent ( ) ;
261-
262- assert_eq ! (
263- parent. unwrap( ) . borrow( ) . children_references( ) ,
264- main_group. children_references( )
265- )
266- }
267156#[ cfg( test) ]
268157mod tests {
269- use super :: * ;
270-
271158 #[ test]
272- fn get_root_full_path ( ) {
159+ fn get_parent ( ) {
273160 use crate :: pbxproj:: test_demo_file;
274161 let project = test_demo_file ! ( demo1) ;
275162 let main_group = project
@@ -281,52 +168,14 @@ mod tests {
281168 . borrow ( )
282169 . main_group ( ) ;
283170
284- let root = PathBuf :: from ( "/path/to/project" ) ;
285171 let main_group = main_group. borrow ( ) ;
286- let main_group_full_path = main_group. full_path ( & root) ;
287- assert_eq ! ( main_group_full_path. unwrap( ) , root) ;
288- }
289-
290- #[ test]
291- fn get_subgroup_full_path ( ) {
292- let root = PathBuf :: from ( "/path/to/project" ) ;
293- let project = crate :: pbxproj:: test_demo_file!( demo1) ;
294-
295- let source_group = project
296- . objects ( )
297- . groups ( )
298- . into_iter ( )
299- . find ( |( _, o) | o. borrow ( ) . path ( ) . map ( |p| p == "Source" ) . unwrap_or_default ( ) )
300- . map ( |( _, o) | o. clone ( ) )
301- . unwrap ( ) ;
302-
172+ let source_group = main_group. get_subgroup ( "Source" ) . unwrap ( ) ;
303173 let source_group = source_group. borrow ( ) ;
304- let source_group_full_path = source_group. full_path ( & root) ;
305- assert_eq ! ( source_group_full_path. unwrap( ) , root. join( "Source" ) ) ;
306- }
307-
308- #[ test]
309- fn get_file_full_path ( ) {
310- let root = PathBuf :: from ( "/path/to/project" ) ;
311- let project = crate :: pbxproj:: test_demo_file!( demo1) ;
312-
313- let mut expected_file_path = root. clone ( ) ;
314- expected_file_path. extend ( & [ "Source" , "Views" , "GuessView.swift" ] ) ;
315-
316- let file = project
317- . objects ( )
318- . get_fs_references ( |fs_reference| {
319- fs_reference
320- . path ( )
321- . map ( |name| name == "GuessView.swift" )
322- . unwrap_or_default ( )
323- } )
324- . first ( )
325- . map ( |( _, o) | o. clone ( ) )
326- . unwrap ( ) ;
327-
328- let file = file. borrow ( ) ;
174+ let parent = source_group. parent ( ) ;
329175
330- assert_eq ! ( file. full_path( root) . unwrap( ) , expected_file_path)
176+ assert_eq ! (
177+ parent. unwrap( ) . borrow( ) . children_references( ) ,
178+ main_group. children_references( )
179+ )
331180 }
332181}
0 commit comments