Skip to content

Commit 3907f04

Browse files
Add mechanism to handle build info files removed from future Xcode versions
- Read in Xcode version from its Info.plist - New key 'deprecatedSubpathsByVersion' reads in a dictionary - Keys of dictionary are versions - Values of dictionary is an array of subpath arrays - The version is the first Xcode version where the subpath is missing - For each version key, if Xcode version is less, add the subpaths for processing - Requires BuildSettingInfoSubpaths.plist values to update - Resolves #38
1 parent e4fd30a commit 3907f04

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

BuildSettingExtractor/BuildSettingInfoSource.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ - (BOOL)loadBuildSettingInfo {
156156
BOOL allSubpathsReadSuccessfully = YES;
157157

158158
NSString *defaultXcodePath = @"/Applications/Xcode.app";
159+
160+
// Read Xcode version
161+
NSString *pathToXcodeInfoPlist = [defaultXcodePath stringByAppendingPathComponent:@"Contents/Info.plist"];
162+
NSDictionary *xcodeInfoDictionary = [NSDictionary dictionaryWithContentsOfFile:pathToXcodeInfoPlist];
163+
NSString *versionString = xcodeInfoDictionary[@"DTXcode"];
164+
NSInteger xcodeVersion = [versionString integerValue];
165+
if (!versionString || xcodeVersion == 0) {
166+
NSLog(@"Could not read Xcode version. Version string: %@, Version Number: %ld", versionString, (long)xcodeVersion);
167+
}
168+
169+
// Load subpaths
159170
NSURL *buildSettingInfoPlistURL = [[NSBundle mainBundle] URLForResource:@"BuildSettingInfoSubpaths" withExtension:@"plist"];
160171
NSDictionary *buildSettingInfoDict = [NSDictionary dictionaryWithContentsOfURL:buildSettingInfoPlistURL];
161172
NSArray *buildSettingInfoSubpaths = buildSettingInfoDict[@"subpaths"];
@@ -166,6 +177,22 @@ - (BOOL)loadBuildSettingInfo {
166177
NSDictionary *backstopSettingsInfo = buildSettingInfoDict[@"backstopSettingInfo"];
167178
[infoStringFile addEntriesFromDictionary:backstopSettingsInfo];
168179

180+
// Add deprecated subpaths that are valid in the version of Xcode we are using
181+
NSMutableArray *subpathsToAdd = nil;
182+
NSDictionary *deprecatedSubpaths = buildSettingInfoDict[@"deprecatedSubpathsByVersion"];
183+
for (NSString *versionKey in [deprecatedSubpaths allKeys]) {
184+
NSInteger maxVersion = [versionKey integerValue];
185+
if (xcodeVersion < maxVersion) {
186+
if (!subpathsToAdd) {
187+
subpathsToAdd = [NSMutableArray array];
188+
}
189+
[subpathsToAdd addObjectsFromArray:deprecatedSubpaths[versionKey]];
190+
}
191+
}
192+
if (subpathsToAdd) {
193+
buildSettingInfoSubpaths = [buildSettingInfoSubpaths arrayByAddingObjectsFromArray:subpathsToAdd];
194+
}
195+
169196
// Rather than track exactly what Xcode versions contain which files, group versions of an expected file in an array.
170197
// Log if no file in the group can be read in.
171198
for (NSArray *buildSettingInfoSubpathList in buildSettingInfoSubpaths) {

0 commit comments

Comments
 (0)