This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
/
XCToolUtil.m
685 lines (562 loc) · 22.4 KB
/
XCToolUtil.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
//
// Copyright 2013 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "XCToolUtil.h"
#import <mach-o/dyld.h>
#import "EventGenerator.h"
#import "EventSink.h"
#import "NSFileHandle+Print.h"
#import "Options.h"
#import "ReporterEvents.h"
#import "ReporterTask.h"
#import "TaskUtil.h"
#import "XcodeSubjectInfo.h"
static NSString *__tempDirectoryForAction = nil;
NSDictionary *BuildSettingsFromOutput(NSString *output)
{
NSScanner *scanner = [NSScanner scannerWithString:output];
[scanner setCharactersToBeSkipped:nil];
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
void (^scanUntilEmptyLine)() = ^{
// Advance until we hit an empty line.
while (![scanner scanString:@"\n" intoString:NULL]) {
[scanner scanUpToString:@"\n" intoString:NULL];
[scanner scanString:@"\n" intoString:NULL];
}
};
if ([scanner scanString:@"User defaults from command line:\n" intoString:NULL]) {
scanUntilEmptyLine();
}
if ([scanner scanString:@"Build settings from command line:\n" intoString:NULL]) {
scanUntilEmptyLine();
}
if ([scanner scanString:@"Build settings from configuration file" intoString:NULL]) {
scanUntilEmptyLine();
}
for (;;) {
NSString *target = nil;
NSMutableDictionary *targetSettings = [NSMutableDictionary dictionary];
// Line with look like...
// 'Build settings for action build and target SomeTarget:'
//
// or, if there are spaces in the target name...
// 'Build settings for action build and target "Some Target Name":'
if (!([scanner scanString:@"Build settings for action test and target " intoString:NULL] ||
[scanner scanString:@"Build settings for action build and target " intoString:NULL])) {
break;
}
[scanner scanUpToString:@":\n" intoString:&target];
[scanner scanString:@":\n" intoString:NULL];
// Target names with spaces will be quoted.
target = [target stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"\""]];
for (;;) {
if ([scanner scanString:@"\n" intoString:NULL]) {
// We know we've reached the end when we see one empty line.
break;
}
// Each line / setting looks like: " SOME_KEY = some value\n"
NSString *key = nil;
NSString *value = nil;
[scanner scanString:@" " intoString:NULL];
[scanner scanUpToString:@" = " intoString:&key];
[scanner scanString:@" = " intoString:NULL];
[scanner scanUpToString:@"\n" intoString:&value];
[scanner scanString:@"\n" intoString:NULL];
targetSettings[key] = (value == nil) ? @"" : value;
}
settings[target] = targetSettings;
}
return settings;
}
NSString *AbsoluteExecutablePath() {
char execRelativePath[PATH_MAX] = {0};
uint32_t execRelativePathSize = sizeof(execRelativePath);
_NSGetExecutablePath(execRelativePath, &execRelativePathSize);
return AbsolutePathFromRelative([NSString stringWithUTF8String:execRelativePath]);
}
NSString *XCToolBasePath(void)
{
if (IsRunningUnderTest()) {
// The Xcode scheme is configured to set XT_INSTALL_ROOT when running
// tests.
NSString *installRoot = [[NSProcessInfo processInfo] environment][@"XT_INSTALL_ROOT"];
NSCAssert(installRoot, @"XT_INSTALL_ROOT is not set.");
return installRoot;
} else {
return [[AbsoluteExecutablePath() stringByDeletingLastPathComponent]
stringByDeletingLastPathComponent];
}
}
NSString *XCToolLibPath(void)
{
return [XCToolBasePath() stringByAppendingPathComponent:@"lib"];
}
NSString *XCToolLibExecPath(void)
{
return [XCToolBasePath() stringByAppendingPathComponent:@"libexec"];
}
NSString *XCToolReportersPath(void)
{
return [XCToolBasePath() stringByAppendingPathComponent:@"reporters"];
}
NSString *XcodeDeveloperDirPath(void)
{
return XcodeDeveloperDirPathViaForcedConcreteTask(NO);
}
NSString *XcodeDeveloperDirPathViaForcedConcreteTask(BOOL forceConcreteTask)
{
NSString *(^getPath)() = ^{
NSTask *task = (forceConcreteTask ?
CreateConcreteTaskInSameProcessGroup() :
CreateTaskInSameProcessGroup());
[task setLaunchPath:@"/usr/bin/xcode-select"];
[task setArguments:@[@"--print-path"]];
NSDictionary *output = LaunchTaskAndCaptureOutput(task,
@"finding Xcode path via xcode-select --print-path");
NSString *path = output[@"stdout"];
path = [path stringByTrimmingCharactersInSet:
[NSCharacterSet newlineCharacterSet]];
[task release];
return path;
};
static NSString *savedPath = nil;
if (IsRunningUnderTest()) {
// Under test, we'd like to always invoke the task so it can be tested.
return getPath();
} else {
if (savedPath == nil) {
savedPath = [getPath() retain];
}
return savedPath;
}
}
NSString *MakeTempFileWithPrefix(NSString *prefix)
{
const char *template = [[TemporaryDirectoryForAction() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXX", prefix]] UTF8String];
char tempPath[PATH_MAX] = {0};
strcpy(tempPath, template);
int handle = mkstemp(tempPath);
assert(handle != -1);
close(handle);
return [NSString stringWithFormat:@"%s", tempPath];
}
/**
Helper function that takes the SDK dictionary, the file scanner and the SDK
version and will scan all the SDK values into a newly created NSDictionary,
then map the SDK version and its family to that new dictionary.
*/
static void AddSDKToDictionary(NSMutableDictionary *dict,
NSScanner *scanner,
NSString *sdk)
{
NSMutableDictionary *versionDict = [NSMutableDictionary dictionary];
// This isn't present in the output, but adding the mapping here in order
// to assist with looking up the SDK value quickly
versionDict[@"SDK"] = sdk;
for (;;) {
NSString *line = nil;
NSString *key = nil;
NSString *value = nil;
[scanner scanUpToString:@"\n" intoString:&line];
[scanner scanString:@"\n" intoString:nil];
if (line.length == 0) {
// a trailing empty line indicates we're done with this SDK section.
break;
}
NSScanner *lineScanner = [NSScanner scannerWithString:line];
// Parse the label/value pair from the line and add it to the dictionary
[lineScanner scanUpToString:@": " intoString:&key];
[lineScanner scanString:@": " intoString:nil];
[lineScanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet]
intoString:&value];
versionDict[key] = value;
}
// Map [name] -> [name][version]. i.e. 'iphoneos' -> 'iphoneos6.1'. Since
// SDKs are listed in ascending order by version number, this will always
// leave us with 'iphoneos' mapped to the newest 'iphoneos' SDK.
NSScanner *versionScanner = [NSScanner scannerWithString:sdk];
NSString *sdkWithoutVersion = nil;
[versionScanner scanCharactersFromSet:[NSCharacterSet letterCharacterSet]
intoString:&sdkWithoutVersion];
dict[sdkWithoutVersion] = versionDict;
dict[sdk] = versionDict;
}
NSDictionary *GetAvailableSDKsInfo()
{
NSTask *task = CreateTaskInSameProcessGroup();
[task setLaunchPath:[XcodeDeveloperDirPath() stringByAppendingPathComponent:@"usr/bin/xcodebuild"]];
[task setArguments:@[@"-sdk", @"-version"]];
NSDictionary *output = LaunchTaskAndCaptureOutput(task,
@"querying available SDKs");
NSString *sdkContents = output[@"stdout"];
[task release];
NSScanner *scanner = [NSScanner scannerWithString:sdkContents];
// We're choosing not to skip characters since we need to know when we
// encounter newline characters to determine when we've consumed an SDK
// "block"
[scanner setCharactersToBeSkipped:nil];
// Regex to pull out SDK value; matching lines with ".sdk" and "([\w.]+)"
// (capturing group around what's inside of the parentheses).
NSRegularExpression *sdkVersionRegex =
[NSRegularExpression
regularExpressionWithPattern:@"^[\\w.]+.sdk[\\s\\w-.]+\\(([\\w.]+)\\)$"
options:0
error:nil];
NSMutableDictionary *versionsAvaialble = [NSMutableDictionary dictionary];
while (![scanner isAtEnd]) {
NSString *str = nil;
// Read current line
[scanner scanUpToString:@"\n" intoString:&str];
[scanner scanString:@"\n" intoString:nil];
// Attempt to match the regex
NSArray *match = [sdkVersionRegex matchesInString:str
options:0
range:NSMakeRange(0, str.length)];
// If we don't find a match, we are done with the SDK parsing
if (match.count == 0) {
break;
}
// Pull the SDK value from our capturing group
NSString *sdkVersion = [str substringWithRange:[match[0] rangeAtIndex:1]];
AddSDKToDictionary(versionsAvaialble, scanner, sdkVersion);
}
return versionsAvaialble;
}
NSDictionary *GetAvailableSDKsAndAliases()
{
NSMutableDictionary *versionsAvailable = [NSMutableDictionary dictionary];
// GetAvailableSDKsInfo already does the hard work for us; we just need to
// iterate through its result to pull out the values cooresponding to the
// "SDK" field for each of the SDK entries.
NSDictionary *sdkInfo = GetAvailableSDKsInfo();
NSArray *keys = [sdkInfo allKeys];
for (NSString *key in keys) {
versionsAvailable[key] = sdkInfo[key][@"SDK"];
}
return versionsAvailable;
}
BOOL IsRunningUnderTest()
{
NSString *processName = [[NSProcessInfo processInfo] processName];
return ([processName isEqualToString:@"otest"] ||
[processName isEqualToString:@"otest-x86_64"]);
}
BOOL LaunchXcodebuildTaskAndFeedEventsToReporters(NSTask *task,
NSArray *reporters,
NSString **errorMessageOut,
long long *errorCodeOut)
{
__block NSString *errorMessage = nil;
__block long long errorCode = LONG_LONG_MIN;
__block BOOL hadFailingBuildCommand = NO;
LaunchTaskAndFeedOuputLinesToBlock(task,
@"running xcodebuild",
^(NSString *line){
NSError *error = nil;
NSDictionary *event = [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding]
options:0
error:&error];
NSCAssert(error == nil,
@"Got error while trying to deserialize event '%@': %@",
line,
[error localizedFailureReason]);
NSString *eventName = event[@"event"];
if ([eventName isEqualToString:@"__xcodebuild-error__"]) {
// xcodebuild-shim will generate this special event if it sees that
// xcodebuild failed with an error message. We don't want this to bubble
// up to reporters itself - instead the caller will capture the error
// message and include it in the 'end-xcodebuild' event.
errorMessage = [event[@"message"] retain];
errorCode = [event[@"code"] longLongValue];
} else {
PublishEventToReporters(reporters, event);
}
if ([eventName isEqualToString:kReporter_Events_EndBuildCommand]) {
BOOL succeeded = [event[kReporter_EndBuildCommand_SucceededKey] boolValue];
if (!succeeded) {
hadFailingBuildCommand = YES;
}
}
});
if (errorMessage) {
*errorMessageOut = errorMessage;
*errorCodeOut = errorCode;
}
// xcodebuild's 'archive' action has a bug where the build can fail, but
// xcodebuild will still print 'ARCHIVE SUCCEEDED' and give you an exit status
// of 0. To compensate, we'll only say xcodebuild succeeded if the exit status
// was 0 AND we saw no failing build commands.
return ([task terminationStatus] == 0) && !hadFailingBuildCommand;
}
BOOL RunXcodebuildAndFeedEventsToReporters(NSArray *arguments,
NSString *command,
NSString *title,
NSArray *reporters)
{
NSTask *task = CreateTaskInSameProcessGroup();
[task setLaunchPath:[XcodeDeveloperDirPath() stringByAppendingPathComponent:@"usr/bin/xcodebuild"]];
[task setArguments:arguments];
NSMutableDictionary *environment =
[NSMutableDictionary dictionaryWithDictionary:
[[NSProcessInfo processInfo] environment]];
[environment addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath()
stringByAppendingPathComponent:@"xcodebuild-shim.dylib"],
}];
[task setEnvironment:environment];
NSDictionary *beginEvent = EventDictionaryWithNameAndContent(
kReporter_Events_BeginXcodebuild, @{
kReporter_BeginXcodebuild_CommandKey: command,
kReporter_BeginXcodebuild_TitleKey: title
});
PublishEventToReporters(reporters, beginEvent);
NSString *xcodebuildErrorMessage = nil;
long long xcodebuildErrorCode = 0;
BOOL succeeded = LaunchXcodebuildTaskAndFeedEventsToReporters(task,
reporters,
&xcodebuildErrorMessage,
&xcodebuildErrorCode);
NSMutableDictionary *endEvent = [NSMutableDictionary dictionaryWithDictionary:
EventDictionaryWithNameAndContent(kReporter_Events_EndXcodebuild,
@{
kReporter_EndXcodebuild_CommandKey: command,
kReporter_EndXcodebuild_TitleKey: title,
kReporter_EndXcodebuild_SucceededKey : @(succeeded),
})];
id errorMessage = [NSNull null];
id errorCode = [NSNull null];
if (!succeeded && xcodebuildErrorMessage != nil) {
// xcodebuild failed, not because of a compile error, but because something
// was wrong with the workspace/project or scheme.
errorMessage = xcodebuildErrorMessage;
errorCode = @(xcodebuildErrorCode);
}
[endEvent addEntriesFromDictionary:@{
kReporter_EndXcodebuild_ErrorMessageKey: errorMessage,
kReporter_EndXcodebuild_ErrorCodeKey: errorCode,
}];
PublishEventToReporters(reporters, endEvent);
[task release];
return succeeded;
}
NSArray *ArgumentListByOverriding(NSArray *arguments,
NSString *option,
NSString *optionValue)
{
NSMutableArray *result = [NSMutableArray array];
BOOL foundAndReplaced = NO;
for (int i = 0; i < [arguments count]; i++) {
if ([arguments[i] isEqualToString:option]) {
[result addObjectsFromArray:@[option, optionValue]];
i++;
foundAndReplaced = YES;
} else {
[result addObject:arguments[i]];
}
}
if (!foundAndReplaced) {
[result addObjectsFromArray:@[option, optionValue]];
}
return result;
}
/**
Every line of arguments defined in an Xcode scheme may provide multiple command line arguments
which get passed to the testable. This method returns the command line arguments contained in one
argument line string. It splits the string into arguments at spaces which are not contained
in unescaped quotes
It treats quotes and escaped quotes like Xcode does when it runs
a test executable. (The escape character is the backslash.)
*/
NSArray *ParseArgumentsFromArgumentString(NSString *string)
{
NSCParameterAssert(string);
enum ParsingState {
OutsideOfArgument,
InsideArgument,
BetweenQuotes,
};
enum ParsingState state = OutsideOfArgument;
NSUInteger escapeIndex = NSNotFound; // points to the index following the last single backslash
unichar openingQuoteCharacter;
NSMutableArray *arguments = [NSMutableArray array];
NSMutableString *currentArgument = nil;
NSUInteger length = string.length;
for (NSUInteger index = 0; index < length; index++) {
unichar iChar = [string characterAtIndex:index];
if(iChar == '\\') {
if(escapeIndex == index) {
escapeIndex = NSNotFound;
} else {
escapeIndex = index + 1;
continue;
}
}
if(iChar == ' ') {
if(state == OutsideOfArgument) {
continue;
} else if(state == InsideArgument) {
state = OutsideOfArgument;
}
}
else if((iChar == '\'' || iChar == '"') && (index != escapeIndex)) {
if(state == BetweenQuotes) {
if(iChar == openingQuoteCharacter) {
state = InsideArgument;
continue;
}
} else {
openingQuoteCharacter = iChar;
state = BetweenQuotes;
continue;
}
}
else if(state == OutsideOfArgument) {
state = InsideArgument;
}
if(state == OutsideOfArgument) {
if(currentArgument.length > 0) {
[arguments addObject:currentArgument];
currentArgument = nil;
}
} else {
if(!currentArgument) {
currentArgument = [NSMutableString string];
}
// As of Mac OS 10.9/iOS 7.0 there still is no Objective-C method for appending single
// characters to strings therefore we have to fall back to using a CF function.
CFStringAppendCharacters((CFMutableStringRef)currentArgument, &iChar, 1);
}
}
if(currentArgument.length > 0) {
[arguments addObject:currentArgument];
}
return arguments;
}
NSString *TemporaryDirectoryForAction()
{
if (__tempDirectoryForAction == nil) {
NSString *nameTemplate = nil;
// Let our names be consistent while under test - we don't want our tests
// to have to match against random values.
if (IsRunningUnderTest()) {
nameTemplate = @"xctool_temp_UNDERTEST";
} else {
nameTemplate = @"xctool_temp_XXXXXX";
}
__tempDirectoryForAction = [MakeTemporaryDirectory(nameTemplate) retain];
}
return __tempDirectoryForAction;
}
void CleanupTemporaryDirectoryForAction()
{
if (__tempDirectoryForAction != nil) {
NSError *error = nil;
if (![[NSFileManager defaultManager] removeItemAtPath:__tempDirectoryForAction
error:&error]) {
NSLog(@"Failed to remove temporary directory '%@': %@",
__tempDirectoryForAction,
[error localizedFailureReason]);
abort();
}
[__tempDirectoryForAction release];
__tempDirectoryForAction = nil;
}
}
void PublishEventToReporters(NSArray *reporters, NSDictionary *event)
{
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:event options:0 error:&error];
NSCAssert(jsonData != nil, @"Error while encoding event into JSON: %@", [error localizedFailureReason]);
for (id<EventSink> reporter in reporters) {
[reporter publishDataForEvent:jsonData];
}
}
NSArray *AvailableReporters()
{
NSString *reportersPath = XCToolReportersPath();
NSError *error = nil;
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:reportersPath
error:&error];
NSCAssert(contents != nil,
@"Failed to read from reporters directory '%@': %@", reportersPath, [error localizedFailureReason]);
return contents;
}
NSString *AbsolutePathFromRelative(NSString *path)
{
char absolutePath[PATH_MAX] = {0};
assert(realpath((const char *)[path UTF8String], absolutePath) != NULL);
return [NSString stringWithUTF8String:absolutePath];
}
NSString *SystemPaths()
{
NSError *error = nil;
NSString *pathLines = [NSString stringWithContentsOfFile:@"/etc/paths"
encoding:NSUTF8StringEncoding
error:&error];
NSCAssert(error == nil, @"Failed to read from /etc/paths: %@", [error localizedFailureReason]);
return [[pathLines componentsSeparatedByString:@"\n"] componentsJoinedByString:@":"];
}
int XcodebuildVersion()
{
NSString *xcodePlistPath = [XcodeDeveloperDirPathViaForcedConcreteTask(YES)
stringByAppendingPathComponent:@"../Info.plist"];
NSCAssert([[NSFileManager defaultManager] fileExistsAtPath:xcodePlistPath isDirectory:NULL],
@"Cannot find Xcode's plist at: %@", xcodePlistPath);
NSDictionary *infoDict = [NSDictionary dictionaryWithContentsOfFile:xcodePlistPath];
NSCAssert(infoDict[@"DTXcode"], @"Cannot find the 'DTXcode' key in Xcode's Info.plist.");
return [infoDict[@"DTXcode"] intValue];
}
BOOL ToolchainIsXcode5OrBetter(void)
{
return (XcodebuildVersion() >= 0500);
}
NSString *MakeTemporaryDirectory(NSString *nameTemplate)
{
NSMutableData *template = [[[[NSTemporaryDirectory() stringByAppendingPathComponent:nameTemplate]
dataUsingEncoding:NSUTF8StringEncoding] mutableCopy] autorelease];
[template appendBytes:"\0" length:1];
if (!mkdtemp(template.mutableBytes) && !IsRunningUnderTest()) {
NSLog(@"Failed to create temporary directory: %s", strerror(errno));
abort();
}
return [NSString stringWithUTF8String:template.bytes];
}
// Forward declaration for private CFBundle API.
// https://www.opensource.apple.com/source/CF/CF-855.11/CFBundle.c
CFStringRef _CFBundleCopyFileTypeForFileURL(CFURLRef url);
static BOOL IsMachOExecutable(NSString *path)
{
NSURL *fileURL = [NSURL fileURLWithPath:path];
CFStringRef fileType = _CFBundleCopyFileTypeForFileURL((CFURLRef)fileURL);
if (fileType != NULL) {
CFComparisonResult result = CFStringCompare(fileType, CFSTR("tool"), 0);
CFRelease(fileType);
return (result == kCFCompareEqualTo);
} else {
return NO;
}
}
BOOL TestableSettingsIndicatesApplicationTest(NSDictionary *settings)
{
NSString *testHostPath = settings[@"TEST_HOST"];
// Sometimes the TEST_HOST is wrapped in double quotes - not sure if our
// projects are misconfigured or if these are funky Xcode defaults.
testHostPath = [testHostPath stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"\""]];
return (testHostPath != nil &&
[[NSFileManager defaultManager] isExecutableFileAtPath:testHostPath] &&
IsMachOExecutable(testHostPath));
}