forked from keysight-eggplant/libs-xcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PBXProject.m
297 lines (249 loc) · 6.41 KB
/
PBXProject.m
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
#import "PBXCommon.h"
#import "PBXProject.h"
#import "PBXNativeTarget.h"
#import "GSXCBuildContext.h"
#import <unistd.h>
@implementation PBXProject
// Methods....
- (NSString *) developmentRegion // getter
{
return developmentRegion;
}
- (void) setDevelopmentRegion: (NSString *)object; // setter
{
ASSIGN(developmentRegion,object);
}
- (NSMutableArray *) knownRegions // getter
{
return knownRegions;
}
- (void) setKnownRegions: (NSMutableArray *)object; // setter
{
ASSIGN(knownRegions,object);
}
- (NSString *) compatibilityVersion // getter
{
return compatibilityVersion;
}
- (void) setCompatibilityVersion: (NSString *)object; // setter
{
ASSIGN(compatibilityVersion,object);
}
- (NSMutableArray *) projectReferences // getter
{
return projectReferences;
}
- (void) setProjectReferences: (NSMutableArray *)object; // setter
{
ASSIGN(projectReferences,object);
}
- (NSMutableArray *) targets // getter
{
return targets;
}
- (void) setTargets: (NSMutableArray *)object; // setter
{
ASSIGN(targets,object);
}
- (NSString *) projectDirPath // getter
{
return projectDirPath;
}
- (void) setProjectDirPath: (NSString *)object; // setter
{
ASSIGN(projectDirPath,object);
}
- (NSString *) projectRoot // getter
{
return projectRoot;
}
- (void) setProjectRoot: (NSString *)object; // setter
{
ASSIGN(projectRoot,object);
}
- (XCConfigurationList *) buildConfigurationList // getter
{
return buildConfigurationList;
}
- (void) setBuildConfigurationList: (XCConfigurationList *)object; // setter
{
ASSIGN(buildConfigurationList,object);
}
- (PBXGroup *) mainGroup // getter
{
return mainGroup;
}
- (void) setMainGroup: (PBXGroup *)object; // setter
{
ASSIGN(mainGroup,object);
}
- (NSString *) hasScannedForEncodings // getter
{
return hasScannedForEncodings;
}
- (void) setHasScannedForEncodings: (NSString *)object; // setter
{
ASSIGN(hasScannedForEncodings,object);
}
- (PBXGroup *) productRefGroup // getter
{
return productRefGroup;
}
- (void) setProductRefGroup: (PBXGroup *)object; // setter
{
ASSIGN(productRefGroup,object);
}
- (PBXContainer *) container
{
return container;
}
- (void) setContainer: (PBXContainer *)object
{
container = object; // container retains us, do not retain it...
}
- (void) setContext: (NSDictionary *)context
{
ASSIGN(ctx,context);
}
- (void) _sourceRootFromMainGroup
{
PBXGroup *sourceGroup = [[mainGroup children] objectAtIndex: 0];
// get first group, which is the source group.
NSString *sourceRoot = [sourceGroup path];
if(sourceRoot == nil)
{
sourceRoot = @"";
}
setenv("SOURCE_ROOT",[sourceRoot cString],1);
NSDebugLog(@"\tSOURCE_ROOT = %@",sourceRoot);
}
- (NSString *) buildString
{
FILE *fp;
char string[1035];
NSString *output = @"";
/* Open the command for reading. */
fp = popen("gnustep-config --debug-flags", "r");
if (fp == NULL) {
puts("*** Failed to run command\n" );
return nil;
}
/* Read the output a line at a time - output it. */
while (fgets(string, sizeof(string)-1, fp) != NULL) {
int len = strlen(string);
int i = 0;
for(i = 0; i < len; i++)
{
if(string[i] == '\n')
{
string[i] = ' ';
}
}
output = [output stringByAppendingString:
[NSString stringWithCString: string]];
}
// Context...
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
[context setObject: output
forKey: @"CONFIG_STRING"];
/* close */
pclose(fp);
return output;
}
- (BOOL) build
{
puts("=== Building Project");
[buildConfigurationList applyDefaultConfiguration];
[self _sourceRootFromMainGroup];
NSFileManager *fileManager = [NSFileManager defaultManager];
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSEnumerator *en = [targets objectEnumerator];
id target = nil;
BOOL result = YES;
while((target = [en nextObject]) != nil && result)
{
BOOL targetInSubdir = NO;
NSString *currentDirectory = [NSString stringWithCString: getcwd(NULL,0)];
[context contextDictionaryForName: [target name]];
[self buildString];
// Go into the target...
if(YES == [fileManager fileExistsAtPath:[target name]])
{
targetInSubdir = YES;
chdir([[target name] UTF8String]);
[context setObject: @"YES"
forKey: @"TARGET_IN_SUBDIR"];
}
[context setObject: mainGroup
forKey: @"MAIN_GROUP"];
[context setObject: container
forKey: @"CONTAINER"];
[context setObject: currentDirectory
forKey: @"PROJECT_ROOT"];
[context addEntriesFromDictionary:ctx];
result = [target build];
[context popCurrentContext];
// Back to the current dir...
if(YES == targetInSubdir)
{
chdir([currentDirectory UTF8String]);
}
}
puts("=== Completed Building Project");
return result;
}
- (BOOL) clean
{
puts("=== Cleaning Project");
[buildConfigurationList applyDefaultConfiguration];
NSFileManager *fileManager = [NSFileManager defaultManager];
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSEnumerator *en = [targets objectEnumerator];
NSString *currentDirectory = [NSString stringWithCString: getcwd(NULL,0)];
id target = nil;
BOOL result = YES;
while((target = [en nextObject]) != nil && result)
{
BOOL targetInSubdir = NO;
// Go into the target...
if(YES == [fileManager fileExistsAtPath:[target name]])
{
targetInSubdir = YES;
chdir([[target name] UTF8String]);
[context setObject: @"YES"
forKey: @"TARGET_IN_SUBDIR"];
}
[context contextDictionaryForName: [target name]];
[context setObject: mainGroup
forKey: @"MAIN_GROUP"];
result = [target clean];
[context popCurrentContext];
// Back to the current dir...
if(YES == targetInSubdir)
{
chdir([currentDirectory UTF8String]);
}
}
puts("=== Completed Cleaning Project");
return result;
}
- (BOOL) install
{
puts("=== Installing Project");
[buildConfigurationList applyDefaultConfiguration];
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSEnumerator *en = [targets objectEnumerator];
id target = nil;
BOOL result = YES;
while((target = [en nextObject]) != nil && result)
{
[context contextDictionaryForName: [target name]];
[context setObject: mainGroup
forKey: @"MAIN_GROUP"];
result = [target install];
[context popCurrentContext];
}
puts("=== Completed Installing Project");
return result;
}
@end