Skip to content

Commit 0552412

Browse files
committed
fix file system sync
1 parent 91ef10c commit 0552412

File tree

4 files changed

+142
-17
lines changed

4 files changed

+142
-17
lines changed

XCode/PBXBuildPhase.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@
125125
*/
126126
- (BOOL) link;
127127

128+
/**
129+
* Returns all files including those from groups (like synchronized groups).
130+
* This method combines the regular files with files discovered from groups.
131+
*/
132+
- (NSArray *) allFiles;
133+
134+
/**
135+
* Returns files from groups that support the children method.
136+
* This includes PBXFileSystemSynchronizedRootGroup and other group types.
137+
*/
138+
- (NSArray *) filesFromGroups;
139+
128140
@end
129141

130142
#endif

XCode/PBXBuildPhase.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,54 @@ - (BOOL) link
134134
return YES;
135135
}
136136

137+
- (NSArray *) allFiles
138+
{
139+
NSMutableArray *result = [NSMutableArray arrayWithArray: _files];
140+
NSArray *groupFiles = [self filesFromGroups];
141+
[result addObjectsFromArray: groupFiles];
142+
return result;
143+
}
144+
145+
- (NSArray *) filesFromGroups
146+
{
147+
NSMutableArray *result = [NSMutableArray array];
148+
149+
if (_target != nil)
150+
{
151+
// Get files from synchronized groups (like PBXFileSystemSynchronizedRootGroup)
152+
NSArray *synchronizedSources = [_target synchronizedSources];
153+
if (synchronizedSources != nil)
154+
{
155+
[result addObjectsFromArray: synchronizedSources];
156+
}
157+
158+
// Get files from synchronized headers
159+
NSArray *synchronizedHeaders = [_target synchronizedHeaders];
160+
if (synchronizedHeaders != nil)
161+
{
162+
[result addObjectsFromArray: synchronizedHeaders];
163+
}
164+
165+
// Future enhancement: We could extend this to handle other group types
166+
// that support the children method by iterating through all groups in the target.
167+
// This would allow build phases to automatically discover files from any
168+
// group type that implements the children method, not just synchronized groups.
169+
//
170+
// Example approach for future expansion:
171+
// NSArray *allGroups = [_target allGroups]; // hypothetical method
172+
// NSEnumerator *groupEnum = [allGroups objectEnumerator];
173+
// id group = nil;
174+
// while ((group = [groupEnum nextObject]) != nil)
175+
// {
176+
// if ([group respondsToSelector: @selector(children)])
177+
// {
178+
// NSArray *children = [group children];
179+
// [result addObjectsFromArray: children];
180+
// }
181+
// }
182+
}
183+
184+
return result;
185+
}
186+
137187
@end

XCode/PBXHeadersBuildPhase.m

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ - (BOOL) build
5050
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
5151
NSError *error = nil;
5252

53-
NSArray *synchronizedFiles = [_target synchronizedHeaders];
54-
NSArray *files = [_files arrayByAddingObjectsFromArray: synchronizedFiles];
53+
// Use the new allFiles method to include files from groups
54+
NSArray *allFiles = [self allFiles];
5555

56-
NSEnumerator *en = [files objectEnumerator];
56+
NSEnumerator *en = [allFiles objectEnumerator];
5757
NSString *derivedSourceHeaderDir = [context objectForKey: @"DERIVED_SOURCE_HEADER_DIR"];
5858
while((file = [en nextObject]) != nil && result)
5959
{
@@ -74,7 +74,29 @@ - (BOOL) build
7474
if([productType isEqualToString: FRAMEWORK_TYPE])
7575
{
7676
xcputs([[NSString stringWithFormat: @"\t* Copying headers to framework header folder..."] cString]);
77-
en = [_files objectEnumerator];
77+
78+
// Filter for header files only in framework case
79+
NSMutableArray *headerFiles = [NSMutableArray array];
80+
NSEnumerator *allEn = [allFiles objectEnumerator];
81+
id headerFile = nil;
82+
83+
while ((headerFile = [allEn nextObject]) != nil)
84+
{
85+
if ([headerFile isKindOfClass: [PBXBuildFile class]])
86+
{
87+
PBXFileReference *fr = [headerFile fileRef];
88+
NSString *name = [fr path];
89+
90+
if ([[name pathExtension] isEqualToString: @"h"]
91+
|| [[name pathExtension] isEqualToString: @"hpp"]
92+
|| [[name pathExtension] isEqualToString: @"hh"])
93+
{
94+
[headerFiles addObject: headerFile];
95+
}
96+
}
97+
}
98+
99+
en = [headerFiles objectEnumerator];
78100
NSString *headerDir = [context objectForKey: @"HEADER_DIR"];
79101
while((file = [en nextObject]) != nil && result)
80102
{
@@ -112,15 +134,18 @@ - (BOOL) generate
112134
BOOL result = YES;
113135
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
114136

137+
// Use the new allFiles method to include files from groups
138+
NSArray *allFiles = [self allFiles];
139+
115140
// NSString *derivedSourceHeaderDir = [context objectForKey: @"DERIVED_SOURCE_HEADER_DIR"];
116-
[context setObject: _files forKey: @"DERIVED_HEADERS"];
141+
[context setObject: allFiles forKey: @"DERIVED_HEADERS"];
117142
xcputs([[NSString stringWithFormat: @"\tAdding entry for derived header files"] cString]);
118143

119144
// Only copy into the framework header folder, if it's a framework...
120145
if([productType isEqualToString: FRAMEWORK_TYPE])
121146
{
122147
// NSString *headerDir = [context objectForKey: @"HEADER_DIR"];
123-
[context setObject: _files forKey: @"HEADERS"];
148+
[context setObject: allFiles forKey: @"HEADERS"];
124149
xcputs([[NSString stringWithFormat: @"\tAdding entry for derived header"] cString]);
125150
}
126151

XCode/PBXSourcesBuildPhase.m

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,22 @@ - (BOOL) build
8686
xcprintf("\t* Parallel build using %ld CPUs...\n", _cpus);
8787
}
8888

89+
xcputs("=== Executing Sources Build Phase");
90+
91+
// Use the new allFiles method which includes files from groups
92+
NSArray *allFiles = [self allFiles];
93+
94+
// Check if we should use the database instead
95+
BOOL usingSynchronizedGroups = NO;
8996
NSArray *synchronizedFiles = [_target synchronizedSources];
90-
files = [files arrayByAddingObjectsFromArray: synchronizedFiles];
91-
// NSLog(@"files = %@", files);
97+
if ([synchronizedFiles count] > 0)
98+
{
99+
usingSynchronizedGroups = YES;
100+
xcputs([[NSString stringWithFormat: @"%s+++ Using synchronized group...%s", YELLOW, RESET] cString]);
101+
}
92102

93103
// if the database is present use it's list of files...
94-
if (db != nil && [synchronizedFiles count] == 0)
104+
if (db != nil && !usingSynchronizedGroups)
95105
{
96106
if ([db isEmpty])
97107
{
@@ -103,11 +113,35 @@ - (BOOL) build
103113
}
104114
else
105115
{
106-
xcputs([[NSString stringWithFormat: @"%s+++ Using synchronized group...%s", YELLOW, RESET] cString]);
116+
// Filter to only include source files (since allFiles might include headers too)
117+
NSMutableArray *sourceFiles = [NSMutableArray array];
118+
NSEnumerator *allEn = [allFiles objectEnumerator];
119+
id file = nil;
120+
121+
while ((file = [allEn nextObject]) != nil)
122+
{
123+
if ([file isKindOfClass: [PBXBuildFile class]])
124+
{
125+
PBXFileReference *fr = [file fileRef];
126+
NSString *name = [fr path];
127+
128+
if ([[name pathExtension] isEqualToString: @"m"]
129+
|| [[name pathExtension] isEqualToString: @"mm"]
130+
|| [[name pathExtension] isEqualToString: @"M"]
131+
|| [[name pathExtension] isEqualToString: @"c"]
132+
|| [[name pathExtension] isEqualToString: @"cc"]
133+
|| [[name pathExtension] isEqualToString: @"C"]
134+
|| [[name pathExtension] isEqualToString: @"swift"])
135+
{
136+
[sourceFiles addObject: file];
137+
}
138+
}
139+
}
140+
141+
files = sourceFiles;
107142
}
108-
109-
en = [files objectEnumerator];
110-
xcputs("=== Executing Sources Build Phase");
143+
144+
en = [files objectEnumerator];
111145
while((file = [en nextObject]) != nil && result)
112146
{
113147
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
@@ -148,9 +182,13 @@ - (BOOL) build
148182
- (BOOL) generate
149183
{
150184
xcputs("=== Generating using Sources Build Phase");
151-
NSEnumerator *en = [_files objectEnumerator];
185+
186+
// Use the new allFiles method to include files from groups
187+
NSArray *allFiles = [self allFiles];
188+
NSEnumerator *en = [allFiles objectEnumerator];
152189
id file = nil;
153190
BOOL result = YES;
191+
154192
while((file = [en nextObject]) != nil && result)
155193
{
156194
[file setTarget: _target];
@@ -175,9 +213,9 @@ - (BOOL) link
175213

176214
buildDir = [buildDir stringByAppendingPathComponent: [_target name]];
177215

178-
NSArray *synchronizedFiles = [_target synchronizedSources];
179-
NSArray *files = [_files arrayByAddingObjectsFromArray: synchronizedFiles];
180-
en = [files objectEnumerator];
216+
// Use the new allFiles method to include files from groups
217+
NSArray *allFiles = [self allFiles];
218+
en = [allFiles objectEnumerator];
181219

182220
xcputs("=== Executing Sources Build Phase (LINK)");
183221
while((file = [en nextObject]) != nil && result)

0 commit comments

Comments
 (0)