-
Notifications
You must be signed in to change notification settings - Fork 99
/
XCProject.cs
1083 lines (965 loc) · 32.3 KB
/
XCProject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace UnityEditor.XCodeEditor
{
public partial class XCProject : System.IDisposable
{
// private string _filePath;
private PBXDictionary _datastore;
public PBXDictionary _objects;
private PBXDictionary _configurations;
private PBXGroup _rootGroup;
private string _defaultConfigurationName;
private string _rootObjectKey;
public string projectRootPath { get; private set; }
private FileInfo projectFileInfo;
public string filePath { get; private set; }
private string sourcePathRoot;
private bool modified = false;
#region Data
// Objects
private PBXDictionary<PBXBuildFile> _buildFiles;
private PBXDictionary<PBXGroup> _groups;
private PBXDictionary<PBXFileReference> _fileReferences;
private PBXDictionary<PBXNativeTarget> _nativeTargets;
private PBXDictionary<PBXFrameworksBuildPhase> _frameworkBuildPhases;
private PBXDictionary<PBXResourcesBuildPhase> _resourcesBuildPhases;
private PBXDictionary<PBXShellScriptBuildPhase> _shellScriptBuildPhases;
private PBXDictionary<PBXSourcesBuildPhase> _sourcesBuildPhases;
private PBXDictionary<PBXCopyFilesBuildPhase> _copyBuildPhases;
private PBXDictionary<XCBuildConfiguration> _buildConfigurations;
private PBXDictionary<XCConfigurationList> _configurationLists;
private PBXProject _project;
#endregion
#region Constructor
public XCProject()
{
}
public XCProject( string filePath ) : this()
{
if( !System.IO.Directory.Exists( filePath ) ) {
Debug.LogWarning( "Path does not exists." );
return;
}
if( filePath.EndsWith( ".xcodeproj" ) ) {
Debug.Log( "Opening project " + filePath );
this.projectRootPath = Path.GetDirectoryName( filePath );
this.filePath = filePath;
} else {
Debug.Log( "Looking for xcodeproj files in " + filePath );
string[] projects = System.IO.Directory.GetDirectories( filePath, "*.xcodeproj" );
if( projects.Length == 0 ) {
Debug.LogWarning( "Error: missing xcodeproj file" );
return;
}
this.projectRootPath = filePath;
this.filePath = projects[ 0 ];
}
// Convert to absolute
this.projectRootPath = Path.GetFullPath(this.projectRootPath);
projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) );
StreamReader sr = projectFileInfo.OpenText();
string contents = sr.ReadToEnd();
sr.Close();
PBXParser parser = new PBXParser();
_datastore = parser.Decode( contents );
if( _datastore == null ) {
throw new System.Exception( "Project file not found at file path " + filePath );
}
if( !_datastore.ContainsKey( "objects" ) ) {
Debug.Log( "Errore " + _datastore.Count );
return;
}
_objects = (PBXDictionary)_datastore["objects"];
modified = false;
_rootObjectKey = (string)_datastore["rootObject"];
if( !string.IsNullOrEmpty( _rootObjectKey ) ) {
// _rootObject = (PBXDictionary)_objects[ _rootObjectKey ];
_project = new PBXProject( _rootObjectKey, (PBXDictionary)_objects[ _rootObjectKey ] );
// _rootGroup = (PBXDictionary)_objects[ (string)_rootObject[ "mainGroup" ] ];
_rootGroup = new PBXGroup( _rootObjectKey, (PBXDictionary)_objects[ _project.mainGroupID ] );
}
else {
Debug.LogWarning( "error: project has no root object" );
_project = null;
_rootGroup = null;
}
}
#endregion
#region Properties
public PBXProject project {
get {
return _project;
}
}
public PBXGroup rootGroup {
get {
return _rootGroup;
}
}
public PBXDictionary<PBXBuildFile> buildFiles {
get {
if( _buildFiles == null ) {
_buildFiles = new PBXDictionary<PBXBuildFile>( _objects );
}
return _buildFiles;
}
}
public PBXDictionary<PBXGroup> groups {
get {
if( _groups == null ) {
_groups = new PBXDictionary<PBXGroup>( _objects );
}
return _groups;
}
}
public PBXDictionary<PBXFileReference> fileReferences {
get {
if( _fileReferences == null ) {
_fileReferences = new PBXDictionary<PBXFileReference>( _objects );
}
return _fileReferences;
}
}
public PBXDictionary<PBXNativeTarget> nativeTargets {
get {
if( _nativeTargets == null ) {
_nativeTargets = new PBXDictionary<PBXNativeTarget>( _objects );
}
return _nativeTargets;
}
}
public PBXDictionary<XCBuildConfiguration> buildConfigurations {
get {
if( _buildConfigurations == null ) {
_buildConfigurations = new PBXDictionary<XCBuildConfiguration>( _objects );
}
return _buildConfigurations;
}
}
public PBXDictionary<XCConfigurationList> configurationLists {
get {
if( _configurationLists == null ) {
_configurationLists = new PBXDictionary<XCConfigurationList>( _objects );
}
return _configurationLists;
}
}
public PBXDictionary<PBXFrameworksBuildPhase> frameworkBuildPhases {
get {
if( _frameworkBuildPhases == null ) {
_frameworkBuildPhases = new PBXDictionary<PBXFrameworksBuildPhase>( _objects );
}
return _frameworkBuildPhases;
}
}
public PBXDictionary<PBXResourcesBuildPhase> resourcesBuildPhases {
get {
if( _resourcesBuildPhases == null ) {
_resourcesBuildPhases = new PBXDictionary<PBXResourcesBuildPhase>( _objects );
}
return _resourcesBuildPhases;
}
}
public PBXDictionary<PBXShellScriptBuildPhase> shellScriptBuildPhases {
get {
if( _shellScriptBuildPhases == null ) {
_shellScriptBuildPhases = new PBXDictionary<PBXShellScriptBuildPhase>( _objects );
}
return _shellScriptBuildPhases;
}
}
public PBXDictionary<PBXSourcesBuildPhase> sourcesBuildPhases {
get {
if( _sourcesBuildPhases == null ) {
_sourcesBuildPhases = new PBXDictionary<PBXSourcesBuildPhase>( _objects );
}
return _sourcesBuildPhases;
}
}
public PBXDictionary<PBXCopyFilesBuildPhase> copyBuildPhases {
get {
if( _copyBuildPhases == null ) {
_copyBuildPhases = new PBXDictionary<PBXCopyFilesBuildPhase>( _objects );
}
return _copyBuildPhases;
}
}
#endregion
#region PBXMOD
public bool AddOtherCFlags( string flag )
{
return AddOtherCFlags( new PBXList( flag ) );
}
public bool AddOtherCFlags( PBXList flags )
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
buildConfig.Value.AddOtherCFlags( flags );
}
modified = true;
return modified;
}
public bool AddOtherLDFlags( string flag )
{
return AddOtherLDFlags( new PBXList( flag ) );
}
public bool AddOtherLDFlags( PBXList flags )
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
buildConfig.Value.AddOtherLDFlags( flags );
}
modified = true;
return modified;
}
public bool GccEnableCppExceptions (string value)
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
buildConfig.Value.GccEnableCppExceptions( value );
}
modified = true;
return modified;
}
public bool GccEnableObjCExceptions (string value)
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
buildConfig.Value.GccEnableObjCExceptions( value );
}
modified = true;
return modified;
}
public bool AddHeaderSearchPaths( string path )
{
return AddHeaderSearchPaths( new PBXList( path ) );
}
public bool AddHeaderSearchPaths( PBXList paths )
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
// Debug.Log( "ADDING HEADER PATH: " + paths + " to " + buildConfig.Key );
buildConfig.Value.AddHeaderSearchPaths( paths );
}
modified = true;
return modified;
}
public bool AddLibrarySearchPaths( string path )
{
return AddLibrarySearchPaths( new PBXList( path ) );
}
public bool AddLibrarySearchPaths( PBXList paths )
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
buildConfig.Value.AddLibrarySearchPaths( paths );
}
modified = true;
return modified;
}
public bool AddFrameworkSearchPaths(string path)
{
return AddFrameworkSearchPaths(new PBXList(path));
}
public bool AddFrameworkSearchPaths(PBXList paths)
{
foreach (KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations)
{
buildConfig.Value.AddFrameworkSearchPaths(paths);
}
modified = true;
return modified;
}
//FRAMEWORK_SEARCH_PATHS = (
// "$(inherited)",
// "\"$(SRCROOT)/../../../../../../../Documents/FacebookSDK\"",
//);
// public PBXList GetObjectOfType( string type )
// {
// PBXList result = new PBXList();
// foreach( KeyValuePair<string, object> current in _objects ) {
// //Debug.Log( "object: " + ((PBXDictionary)current.Value)["isa"] );
// if( string.Compare( (string)((PBXDictionary)current.Value)["isa"], type ) == 0 )
// result.Add( current.Value );
// }
// return result;
// }
public object GetObject( string guid )
{
return _objects[guid];
}
// public PBXDictionary<PBXBuildPhase> GetBuildPhase( string buildPhase )
// {
// switch( buildPhase ) {
// case "PBXFrameworksBuildPhase":
// return (PBXDictionary<PBXBuildPhase>)frameworkBuildPhases;
// case "PBXResourcesBuildPhase":
// return (PBXDictionary<PBXBuildPhase>)resourcesBuildPhases;
// case "PBXShellScriptBuildPhase":
// return (PBXDictionary<PBXBuildPhase>)shellScriptBuildPhases;
// case "PBXSourcesBuildPhase":
// return (PBXDictionary<PBXBuildPhase>)sourcesBuildPhases;
// case "PBXCopyFilesBuildPhase":
// return (PBXDictionary<PBXBuildPhase>)copyBuildPhases;
// default:
// return default(T);
// }
// }
public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false )
{
PBXDictionary results = new PBXDictionary();
string absPath = string.Empty;
if( Path.IsPathRooted( filePath ) ) {
absPath = filePath;
// Debug.Log( "Is rooted: " + absPath );
}
else if( tree.CompareTo( "SDKROOT" ) != 0) {
absPath = Path.Combine( Application.dataPath.Replace("Assets", ""), filePath );
// Debug.Log( "RElative: " + absPath );
}
if( !( File.Exists( absPath ) || Directory.Exists( absPath ) ) && tree.CompareTo( "SDKROOT" ) != 0 ) {
Debug.Log( "Missing file: " + absPath + " > " + filePath );
return results;
}
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 || tree.CompareTo( "GROUP" ) == 0 ) {
System.Uri fileURI = new System.Uri( absPath );
System.Uri rootURI = new System.Uri( ( projectRootPath + "/." ) );
filePath = rootURI.MakeRelativeUri( fileURI ).ToString();
}
// else {
// tree = "<absolute>";
// Debug.Log( "3: " + filePath );
// }
// Debug.Log( "Add file result path: " + filePath );
if( parent == null ) {
parent = _rootGroup;
}
// TODO: Aggiungere controllo se file già presente
PBXFileReference fileReference = GetFile( System.IO.Path.GetFileName( filePath ) );
if( fileReference != null ) {
// Debug.Log( "File già presente." );
return null;
}
fileReference = new PBXFileReference( filePath, (TreeEnum)System.Enum.Parse( typeof(TreeEnum), tree ) );
parent.AddChild( fileReference );
fileReferences.Add( fileReference );
results.Add( fileReference.guid, fileReference );
//Create a build file for reference
if( !string.IsNullOrEmpty( fileReference.buildPhase ) && createBuildFiles ) {
// PBXDictionary<PBXBuildPhase> currentPhase = GetBuildPhase( fileReference.buildPhase );
PBXBuildFile buildFile;
switch( fileReference.buildPhase ) {
case "PBXFrameworksBuildPhase":
foreach( KeyValuePair<string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases ) {
buildFile = new PBXBuildFile( fileReference, weak );
buildFiles.Add( buildFile );
currentObject.Value.AddBuildFile( buildFile );
}
if ( !string.IsNullOrEmpty( absPath ) && File.Exists(absPath) && tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
//Debug.LogError(absPath);
string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
this.AddLibrarySearchPaths( new PBXList(libraryPath) );
}
else if (!string.IsNullOrEmpty( absPath ) && Directory.Exists(absPath) && absPath.EndsWith(".framework") && tree.CompareTo("GROUP") == 0) { // Annt: Add framework search path for FacebookSDK
string frameworkPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
this.AddFrameworkSearchPaths(new PBXList(frameworkPath));
}
break;
case "PBXResourcesBuildPhase":
foreach( KeyValuePair<string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases ) {
buildFile = new PBXBuildFile( fileReference, weak );
buildFiles.Add( buildFile );
currentObject.Value.AddBuildFile( buildFile );
}
break;
case "PBXShellScriptBuildPhase":
foreach( KeyValuePair<string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases ) {
buildFile = new PBXBuildFile( fileReference, weak );
buildFiles.Add( buildFile );
currentObject.Value.AddBuildFile( buildFile );
}
break;
case "PBXSourcesBuildPhase":
foreach( KeyValuePair<string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases ) {
buildFile = new PBXBuildFile( fileReference, weak );
buildFiles.Add( buildFile );
currentObject.Value.AddBuildFile( buildFile );
}
break;
case "PBXCopyFilesBuildPhase":
foreach( KeyValuePair<string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases ) {
buildFile = new PBXBuildFile( fileReference, weak );
buildFiles.Add( buildFile );
currentObject.Value.AddBuildFile( buildFile );
}
break;
case null:
Debug.LogWarning( "fase non supportata null" );
break;
default:
Debug.LogWarning( "fase non supportata def" );
return null;
}
}
// Debug.Log( "Results " + results.Count + " - " );
// foreach( KeyValuePair<string, object> obj in results ){
// Debug.Log( obj.Key + " - " + obj.Value.GetType().Name );
// }
return results;
// def add_file(self, f_path, parent=None, tree='SOURCE_ROOT', create_build_files=True, weak=False):
// results = []
//
// abs_path = ''
//
// if os.path.isabs(f_path):
// abs_path = f_path
//
// if not os.path.exists(f_path):
// return results
// elif tree == 'SOURCE_ROOT':
// f_path = os.path.relpath(f_path, self.source_root)
// else:
// tree = '<absolute>'
//
// if not parent:
// parent = self.root_group
// elif not isinstance(parent, PBXGroup):
// # assume it's an id
// parent = self.objects.get(parent, self.root_group)
//
// file_ref = PBXFileReference.Create(f_path, tree)
// parent.add_child(file_ref)
// results.append(file_ref)
// # create a build file for the file ref
// if file_ref.build_phase and create_build_files:
// phases = self.get_build_phases(file_ref.build_phase)
//
// for phase in phases:
// build_file = PBXBuildFile.Create(file_ref, weak=weak)
//
// phase.add_build_file(build_file)
// results.append(build_file)
//
// if abs_path and tree == 'SOURCE_ROOT' and os.path.isfile(abs_path)\
// and file_ref.build_phase == 'PBXFrameworksBuildPhase':
//
// library_path = os.path.join('$(SRCROOT)', os.path.split(f_path)[0])
//
// self.add_library_search_paths([library_path], recursive=False)
//
// for r in results:
// self.objects[r.id] = r
//
// if results:
// self.modified = True
//
// return results
}
public bool AddFolder( string folderPath, PBXGroup parent = null, string[] exclude = null, bool recursive = true, bool createBuildFile = true )
{
if( !Directory.Exists( folderPath ) )
return false;
DirectoryInfo sourceDirectoryInfo = new DirectoryInfo( folderPath );
if( exclude == null )
exclude = new string[] {};
string regexExclude = string.Format( @"{0}", string.Join( "|", exclude ) );
PBXDictionary results = new PBXDictionary();
if( parent == null )
parent = rootGroup;
// Create group
PBXGroup newGroup = GetGroup( sourceDirectoryInfo.Name, null /*relative path*/, parent );
// groups.Add( newGroup );
foreach( string directory in Directory.GetDirectories( folderPath ) )
{
if( Regex.IsMatch( directory, regexExclude ) ) {
continue;
}
// special_folders = ['.bundle', '.framework', '.xcodeproj']
Debug.Log( "DIR: " + directory );
if( directory.EndsWith( ".bundle" ) ) {
// Treath it like a file and copy even if not recursive
Debug.LogWarning( "This is a special folder: " + directory );
AddFile( directory, newGroup, "SOURCE_ROOT", createBuildFile );
Debug.Log( "fatto" );
continue;
}
if( recursive ) {
Debug.Log( "recursive" );
AddFolder( directory, newGroup, exclude, recursive, createBuildFile );
}
}
// Adding files.
foreach( string file in Directory.GetFiles( folderPath ) ) {
if( Regex.IsMatch( file, regexExclude ) ) {
continue;
}
//Debug.Log( "--> " + file + ", " + newGroup );
AddFile( file, newGroup, "SOURCE_ROOT", createBuildFile );
}
modified = true;
return modified;
// def add_folder(self, os_path, parent=None, excludes=None, recursive=True, create_build_files=True):
// if not os.path.isdir(os_path):
// return []
//
// if not excludes:
// excludes = []
//
// results = []
//
// if not parent:
// parent = self.root_group
// elif not isinstance(parent, PBXGroup):
// # assume it's an id
// parent = self.objects.get(parent, self.root_group)
//
// path_dict = {os.path.split(os_path)[0]:parent}
// special_list = []
//
// for (grp_path, subdirs, files) in os.walk(os_path):
// parent_folder, folder_name = os.path.split(grp_path)
// parent = path_dict.get(parent_folder, parent)
//
// if [sp for sp in special_list if parent_folder.startswith(sp)]:
// continue
//
// if folder_name.startswith('.'):
// special_list.append(grp_path)
// continue
//
// if os.path.splitext(grp_path)[1] in XcodeProject.special_folders:
// # if this file has a special extension (bundle or framework mainly) treat it as a file
// special_list.append(grp_path)
//
// new_files = self.verify_files([folder_name], parent=parent)
//
// if new_files:
// results.extend(self.add_file(grp_path, parent, create_build_files=create_build_files))
//
// continue
//
// # create group
// grp = self.get_or_create_group(folder_name, path=self.get_relative_path(grp_path) , parent=parent)
// path_dict[grp_path] = grp
//
// results.append(grp)
//
// file_dict = {}
//
// for f in files:
// if f[0] == '.' or [m for m in excludes if re.match(m,f)]:
// continue
//
// kwds = {
// 'create_build_files': create_build_files,
// 'parent': grp,
// 'name': f
// }
//
// f_path = os.path.join(grp_path, f)
//
// file_dict[f_path] = kwds
//
// new_files = self.verify_files([n.get('name') for n in file_dict.values()], parent=grp)
//
// add_files = [(k,v) for k,v in file_dict.items() if v.get('name') in new_files]
//
// for path, kwds in add_files:
// kwds.pop('name', None)
//
// self.add_file(path, **kwds)
//
// if not recursive:
// break
//
// for r in results:
// self.objects[r.id] = r
//
// return results
}
#endregion
#region Getters
public PBXFileReference GetFile( string name )
{
if( string.IsNullOrEmpty( name ) ) {
return null;
}
foreach( KeyValuePair<string, PBXFileReference> current in fileReferences ) {
if( !string.IsNullOrEmpty( current.Value.name ) && current.Value.name.CompareTo( name ) == 0 ) {
return current.Value;
}
}
return null;
}
public PBXGroup GetGroup( string name, string path = null, PBXGroup parent = null )
{
// Debug.Log( "GetGroup: " + name + ", " + path + ", " + parent );
if( string.IsNullOrEmpty( name ) )
return null;
if( parent == null )
parent = rootGroup;
foreach( KeyValuePair<string, PBXGroup> current in groups ) {
// Debug.Log( "current: " + current.Value.guid + ", " + current.Value.name + ", " + current.Value.path + " - " + parent.HasChild( current.Key ) );
if( string.IsNullOrEmpty( current.Value.name ) ) {
if( current.Value.path.CompareTo( name ) == 0 && parent.HasChild( current.Key ) ) {
return current.Value;
}
}
else if( current.Value.name.CompareTo( name ) == 0 && parent.HasChild( current.Key ) ) {
return current.Value;
}
}
PBXGroup result = new PBXGroup( name, path );
groups.Add( result );
parent.AddChild( result );
modified = true;
return result;
// def get_or_create_group(self, name, path=None, parent=None):
// if not name:
// return None
//
// if not parent:
// parent = self.root_group
// elif not isinstance(parent, PBXGroup):
// # assume it's an id
// parent = self.objects.get(parent, self.root_group)
//
// groups = self.get_groups_by_name(name)
//
// for grp in groups:
// if parent.has_child(grp.id):
// return grp
//
// grp = PBXGroup.Create(name, path)
// parent.add_child(grp)
//
// self.objects[grp.id] = grp
//
// self.modified = True
//
// return grp
}
#endregion
// #region Files
//
//
// /// <summary>
// /// Returns all file resources in the project, as an array of `XCSourceFile` objects.
// /// </summary>
// /// <returns>
// /// The files.
// /// </returns>
// public ArrayList GetFiles()
// {
// return null;
// }
//
// /// <summary>
// /// Returns the project file with the specified key, or nil.
// /// </summary>
// /// <returns>
// /// The file with key.
// /// </returns>
// /// <param name='key'>
// /// Key.
// /// </param>
// public XCSourceFile GetFileWithKey( string key )
// {
// return null;
// }
//
// /// <summary>
// /// Returns the project file with the specified name, or nil. If more than one project file matches the specified name,
// /// which one is returned is undefined.
// /// </summary>
// /// <returns>
// /// The file with name.
// /// </returns>
// /// <param name='name'>
// /// Name.
// /// </param>
// public XCSourceFile GetFileWithName( string name )
// {
// return null;
// }
//
// /// <summary>
// /// Returns all header files in the project, as an array of `XCSourceFile` objects.
// /// </summary>
// /// <returns>
// /// The header files.
// /// </returns>
// public ArrayList GetHeaderFiles()
// {
// return null;
// }
//
// /**
// * Returns all implementation obj-c implementation files in the project, as an array of `XCSourceFile` objects.
// */
// public ArrayList GetObjectiveCFiles()
// {
// return null;
// }
//
// /**
// * Returns all implementation obj-c++ implementation files in the project, as an array of `XCSourceFile` objects.
// */
// public ArrayList GetObjectiveCPlusPlusFiles()
// {
// return null;
// }
//
// /**
// * Returns all the xib files in the project, as an array of `XCSourceFile` objects.
// */
// public ArrayList GetXibFiles()
// {
// return null;
//
// }
//
// public ArrayList getImagePNGFiles()
// {
// return null;
// }
//
// #endregion
// #region Groups
// /**
// * Lists the groups in an xcode project, returning an array of `PBXGroup` objects.
// */
// public PBXList groups {
// get {
// return null;
// }
// }
//
// /**
// * Returns the root (top-level) group.
// */
// public PBXGroup rootGroup {
// get {
// return null;
// }
// }
//
// /**
// * Returns the root (top-level) groups, if there are multiple. An array of rootGroup if there is only one.
// */
// public ArrayList rootGroups {
// get {
// return null;
// }
// }
//
// /**
// * Returns the group with the given key, or nil.
// */
// public PBXGroup GetGroupWithKey( string key )
// {
// return null;
// }
//
// /**
// * Returns the group with the specified display name path - the directory relative to the root group. Eg Source/Main
// */
// public PBXGroup GetGroupWithPathFromRoot( string path )
// {
// return null;
// }
//
// /**
// * Returns the parent group for the group or file with the given key;
// */
// public PBXGroup GetGroupForGroupMemberWithKey( string key )
// {
// return null;
// }
//
// /**
// * Returns the parent group for the group or file with the source file
// */
// public PBXGroup GetGroupWithSourceFile( XCSourceFile sourceFile )
// {
// return null;
// }
//
// #endregion
// #region Target
//
// /**
// * Lists the targets in an xcode project, returning an array of `XCTarget` objects.
// */
// public ArrayList targets {
// get {
// return null;
// }
// }
//
// /**
// * Returns the target with the specified name, or nil.
// */
// public XCTarget GetTargetWithName( string name )
// {
// return null;
// }
//
// #endregion
// #region Configurations
//
// /**
// * Returns the target with the specified name, or nil.
// */
// public Dictionary<string, string> configurations {
// get {
// return null;
// }
// }
//
// public Dictionary<string, string> GetConfigurationWithName( string name )
// {
// return null;
// }
//
// public XCBuildConfigurationList defaultConfiguration {
// get {
// return null;
// }
// }
//
// #endregion
#region Mods
public void ApplyMod( string pbxmod )
{
XCMod mod = new XCMod( pbxmod );
ApplyMod( mod );
}
public void ApplyMod( XCMod mod )
{
PBXGroup modGroup = this.GetGroup( mod.group );
Debug.Log( "Adding libraries..." );
PBXGroup librariesGroup = this.GetGroup( "Libraries" );
foreach( XCModFile libRef in mod.libs ) {
string completeLibPath = System.IO.Path.Combine( "usr/lib", libRef.filePath );
this.AddFile( completeLibPath, modGroup, "SDKROOT", true, libRef.isWeak );
}
Debug.Log( "Adding frameworks..." );
PBXGroup frameworkGroup = this.GetGroup( "Frameworks" );
foreach( string framework in mod.frameworks ) {
string[] filename = framework.Split( ':' );
bool isWeak = ( filename.Length > 1 ) ? true : false;
string completePath = System.IO.Path.Combine( "System/Library/Frameworks", filename[0] );
this.AddFile( completePath, frameworkGroup, "SDKROOT", true, isWeak );
}
Debug.Log( "Adding files..." );
foreach( string filePath in mod.files ) {
string absoluteFilePath = System.IO.Path.Combine( mod.path, filePath );
if( filePath.EndsWith(".framework") )
this.AddFile( absoluteFilePath, frameworkGroup, "GROUP", true, false);
else
this.AddFile( absoluteFilePath, modGroup );
}
Debug.Log( "Adding folders..." );
foreach( string folderPath in mod.folders ) {
string absoluteFolderPath = System.IO.Path.Combine( mod.path, folderPath );
this.AddFolder( absoluteFolderPath, modGroup, (string[])mod.excludes.ToArray( typeof(string) ) );
}
Debug.Log( "Adding headerpaths..." );
foreach( string headerpath in mod.headerpaths ) {
string absoluteHeaderPath = System.IO.Path.Combine( mod.path, headerpath );
this.AddHeaderSearchPaths( absoluteHeaderPath );
}
Debug.Log( "Configure build settings..." );
Hashtable buildSettings = mod.buildSettings;
if (mod.buildSettings != null)
{
if( buildSettings.ContainsKey("OTHER_LDFLAGS") )
{
Debug.Log( " Adding other linker flags..." );
ArrayList otherLinkerFlags = (ArrayList) buildSettings["OTHER_LDFLAGS"];
foreach( string linker in otherLinkerFlags )
{
string _linker = linker;
if( !_linker.StartsWith("-") )
_linker = "-" + _linker;
this.AddOtherLDFlags( _linker );
}
}
if( buildSettings.ContainsKey("GCC_ENABLE_CPP_EXCEPTIONS") )
{
Debug.Log( " GCC_ENABLE_CPP_EXCEPTIONS = " + buildSettings["GCC_ENABLE_CPP_EXCEPTIONS"] );
this.GccEnableCppExceptions( (string) buildSettings["GCC_ENABLE_CPP_EXCEPTIONS"] );
}
if( buildSettings.ContainsKey("GCC_ENABLE_OBJC_EXCEPTIONS") )
{
Debug.Log( " GCC_ENABLE_OBJC_EXCEPTIONS = " + buildSettings["GCC_ENABLE_OBJC_EXCEPTIONS"] );
this.GccEnableObjCExceptions( (string) buildSettings["GCC_ENABLE_OBJC_EXCEPTIONS"] );
}
}
this.Consolidate();