@@ -37,17 +37,24 @@ + (XCGroup *)groupWithProject:(XCProject *)project key:(NSString *)key alias:(NS
37
37
children : (NSArray *)children
38
38
{
39
39
40
- return [[XCGroup alloc ] initWithProject: project key: key alias: alias path: path children: children];
40
+ return [[XCGroup alloc ] initWithProject: project key: key alias: alias path: path children: children memberType: PBXGroupType];
41
+ }
42
+
43
+ + (XCGroup *)groupWithProject : (XCProject *)project key : (NSString *)key alias : (NSString *)alias path : (NSString *)path children : (NSArray <id<XcodeGroupMember>> *)children memberType : (XcodeMemberType)groupType
44
+ {
45
+ return [[XCGroup alloc ]initWithProject:project key: key alias: alias path: path children: children memberType: groupType];
41
46
}
42
47
43
48
// -------------------------------------------------------------------------------------------
44
49
#pragma mark - Initialization & Destruction
45
50
// -------------------------------------------------------------------------------------------
46
51
47
- - (id )initWithProject : (XCProject *)project key : (NSString *)key alias : (NSString *)alias path : (NSString *)path
48
- children : (NSArray *)children
52
+ - (id )initWithProject : (XCProject *)project key : (NSString *)key alias : (NSString *)alias path : (NSString *)path children : (NSArray <id<XcodeGroupMember>> *)children memberType : (XcodeMemberType)groupType
49
53
{
50
54
self = [super init ];
55
+
56
+ assert (groupType == PBXGroupType || groupType == PBXVariantGroupType);
57
+
51
58
if (self) {
52
59
_project = project;
53
60
_fileOperationQueue = [_project fileOperationQueue ];
@@ -59,10 +66,18 @@ - (id)initWithProject:(XCProject *)project key:(NSString *)key alias:(NSString *
59
66
if (!_children) {
60
67
_children = [[NSMutableArray alloc ] init ];
61
68
}
69
+
70
+ _memberType = groupType;
62
71
}
63
72
return self;
64
73
}
65
74
75
+ - (id )initWithProject : (XCProject *)project key : (NSString *)key alias : (NSString *)alias path : (NSString *)path
76
+ children : (NSArray *)children
77
+ {
78
+ return [self initWithProject: project key: key alias: alias path: path children: children memberType: PBXGroupType];
79
+ }
80
+
66
81
// -------------------------------------------------------------------------------------------
67
82
#pragma mark - Interface Methods
68
83
// -------------------------------------------------------------------------------------------
@@ -276,7 +291,12 @@ - (XCGroup *)addGroupWithPath:(NSString *)path
276
291
return group;
277
292
}
278
293
279
- - (XCGroup*)addGroupWithAlias : (NSString *)alias
294
+ - (XCGroup *)addGroupWithAlias : (NSString *)alias
295
+ {
296
+ return [self addGroupWithAlias: alias groupType: PBXGroupType];
297
+ }
298
+
299
+ - (XCGroup*)addGroupWithAlias : (NSString *)alias groupType : (XcodeMemberType)type
280
300
{
281
301
NSString *groupKey = [[XCKeyBuilder forItemNamed: alias] build ];
282
302
@@ -290,7 +310,7 @@ - (XCGroup*)addGroupWithAlias:(NSString *)alias
290
310
}
291
311
}
292
312
293
- XCGroup *group = [[XCGroup alloc ] initWithProject: _project key: groupKey alias: alias path: nil children: nil ];
313
+ XCGroup *group = [[XCGroup alloc ] initWithProject: _project key: groupKey alias: alias path: nil children: nil memberType: type ];
294
314
NSDictionary *groupDict = [group asDictionary ];
295
315
296
316
[_project objects ][groupKey] = groupDict;
@@ -591,6 +611,68 @@ - (NSString *)pathRelativeToProjectRoot
591
611
return _pathRelativeToProjectRoot;
592
612
}
593
613
614
+ // -------------------------------------------------------------------------------------------
615
+ #pragma mark - XCBuildFile Methods
616
+
617
+ - (BOOL ) canBecomeBuildFile
618
+ {
619
+ return _memberType == PBXVariantGroupType;
620
+ }
621
+
622
+ - (XcodeMemberType)buildPhase
623
+ {
624
+ if (_memberType == PBXVariantGroupType)
625
+ return PBXResourcesBuildPhaseType;
626
+
627
+ return PBXNilType;
628
+ }
629
+
630
+ - (NSString *)buildFileKey
631
+ {
632
+ if (_buildFileKey == nil ) {
633
+ [[_project objects ] enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSDictionary *obj, BOOL *stop) {
634
+ if ([[obj valueForKey: @" isa" ] xce_hasBuildFileType ]) {
635
+ if ([[obj valueForKey: @" fileRef" ] isEqualToString: _key]) {
636
+ _buildFileKey = [key copy ];
637
+ }
638
+ }
639
+ }];
640
+ }
641
+ return [_buildFileKey copy ];
642
+
643
+ }
644
+
645
+
646
+ - (void )becomeBuildFile
647
+ {
648
+ if (![self isBuildFile ]) {
649
+ if ([self canBecomeBuildFile ]) {
650
+ NSMutableDictionary *sourceBuildFile = [NSMutableDictionary dictionary ];
651
+ sourceBuildFile[@" isa" ] = [NSString xce_stringFromMemberType: PBXBuildFileType];
652
+ sourceBuildFile[@" fileRef" ] = _key;
653
+ NSString *buildFileKey = [[XCKeyBuilder forItemNamed: [self .displayName stringByAppendingString: @" .buildFile" ]] build ];
654
+ [_project objects ][buildFileKey] = sourceBuildFile;
655
+ }
656
+ }
657
+ }
658
+
659
+ - (BOOL )isBuildFile
660
+ {
661
+ if ([self canBecomeBuildFile ] && _isBuildFile == nil ) {
662
+ _isBuildFile = @NO ;
663
+ [[_project objects ] enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSDictionary *obj, BOOL *stop) {
664
+ if ([[obj valueForKey: @" isa" ] xce_hasBuildFileType ]) {
665
+ if ([[obj valueForKey: @" fileRef" ] isEqualToString: _key]) {
666
+ _isBuildFile = nil ;
667
+
668
+ _isBuildFile = @YES ;
669
+ }
670
+ }
671
+ }];
672
+ }
673
+ return [_isBuildFile boolValue ];
674
+ }
675
+
594
676
// -------------------------------------------------------------------------------------------
595
677
#pragma mark - Utility Methods
596
678
@@ -828,7 +910,7 @@ - (NSDictionary *)makeFileReferenceWithPath:(NSString *)path name:(NSString *)na
828
910
- (NSDictionary *)asDictionary
829
911
{
830
912
NSMutableDictionary *groupData = [NSMutableDictionary dictionary ];
831
- groupData[@" isa" ] = [NSString xce_stringFromMemberType: PBXGroupType ];
913
+ groupData[@" isa" ] = [NSString xce_stringFromMemberType: _memberType ];
832
914
groupData[@" sourceTree" ] = @" <group>" ;
833
915
834
916
if (_alias != nil ) {
@@ -859,4 +941,4 @@ - (void)addSourceFile:(XCSourceFile *)sourceFile toTargets:(NSArray *)targets
859
941
}
860
942
}
861
943
862
- @end
944
+ @end
0 commit comments