Skip to content

Commit 6821e39

Browse files
Add a header comment to generated files
1 parent 6505e9a commit 6821e39

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

BuildSettingExtractor/BuildSettingExtractor.m

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,32 @@ - (void)writeConfigFilesToDestinationFolder:(NSURL *)destinationURL {
103103
[self.buildSettingsByTarget enumerateKeysAndObjectsUsingBlock:^(id targetName, id obj, BOOL *stop) {
104104
[obj enumerateKeysAndObjectsUsingBlock:^(id configName, id settings, BOOL *stop) {
105105

106+
NSString *filename = [self configFilenameWithTargetName:targetName configName:configName];
107+
108+
NSString *configFileString = @"";
109+
110+
// Add header comment
111+
NSString *headerComment = [self headerCommentForFilename:filename];
112+
if (headerComment) {
113+
configFileString = [configFileString stringByAppendingString:headerComment];
114+
}
115+
106116
// If the config name is not the shared config, we need to import the shared config
107117
if (![configName isEqualToString:self.sharedConfigName]) {
108118
NSString *configFilename = [self configFilenameWithTargetName:targetName configName:self.sharedConfigName];
109119
NSString *includeDirective = [NSString stringWithFormat:@"#include \"%@\"\n\n", configFilename];
110-
settings = [includeDirective stringByAppendingString:settings];
120+
configFileString = [configFileString stringByAppendingString:includeDirective];
111121
}
112122

123+
configFileString = [configFileString stringByAppendingString:settings];
124+
113125
// Trim whitespace and newlines
114-
settings = [settings stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
126+
configFileString = [configFileString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
115127

116-
NSString *filename = [self configFilenameWithTargetName:targetName configName:configName];
117128

118129
NSURL *fileURL = [destinationURL URLByAppendingPathComponent:filename];
119130

120-
BOOL success = [settings writeToURL:fileURL atomically:YES encoding:NSUTF8StringEncoding error:nil];
131+
BOOL success = [configFileString writeToURL:fileURL atomically:YES encoding:NSUTF8StringEncoding error:nil];
121132
if (!success) NSLog(@"No success with %@", fileURL);
122133
}];
123134
}];
@@ -128,6 +139,23 @@ - (NSString *)configFilenameWithTargetName:(NSString *)targetName configName:(NS
128139
return [NSString stringWithFormat:@"%@-%@.xcconfig", targetName, configName];
129140
}
130141

142+
// Given the filename generate the header comment
143+
- (NSString *)headerCommentForFilename:(NSString *)filename {
144+
NSString *headerComment = @"";
145+
146+
NSString *dateString = [NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterNoStyle];
147+
148+
headerComment = [headerComment stringByAppendingString:@"//\n"];
149+
headerComment = [headerComment stringByAppendingFormat:@"// %@\n", filename];
150+
headerComment = [headerComment stringByAppendingString:@"//\n"];
151+
headerComment = [headerComment stringByAppendingFormat:@"// Generated by BuildSettingExtractor on %@\n", dateString];
152+
headerComment = [headerComment stringByAppendingString:@"// https://github.com/dempseyatgithub/BuildSettingExtractor\n"];
153+
headerComment = [headerComment stringByAppendingString:@"//\n"];
154+
headerComment = [headerComment stringByAppendingString:@"\n"];
155+
156+
return headerComment;
157+
}
158+
131159

132160
/* Given a build setting dictionary, returns a string representation of the build settings, suitable for an xcconfig file. */
133161
- (NSString *)stringRepresentationOfBuildSettings:(NSDictionary *)buildSettings {

0 commit comments

Comments
 (0)