Skip to content

Commit 63fd784

Browse files
committed
build commands are only successful if resultCode == 0 and they have no errors
This fixes facebookarchive#262. Tested by changing a Run Script to emit strings in the form of "error: blah" and "warning: "blah", and verified that xctool reported failure and warnings correctly.
1 parent d81e1b4 commit 63fd784

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Common/ReporterEvents.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
#define kReporter_EndBuildCommand_SucceededKey @"succeeded"
9696
#define kReporter_EndBuildCommand_EmittedOutputTextKey @"emittedOutputText"
9797
#define kReporter_EndBuildCommand_DurationKey @"duration"
98+
#define kReporter_EndBuildCommand_ResultCode @"resultCode"
99+
#define kReporter_EndBuildCommand_TotalNumberOfWarnings @"totalNumberOfWarnings"
100+
#define kReporter_EndBuildCommand_TotalNumberOfErrors @"totalNumberOfErrors"
98101

99102
#define kReporter_BeginBuildTarget_ProjectKey @"project"
100103
#define kReporter_BeginBuildTarget_TargetKey @"target"

reporters/text/TextReporter.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ - (void)endBuildCommand:(NSDictionary *)event
530530

531531
NSString *indicator = nil;
532532
if (succeeded) {
533-
if ([outputText rangeOfString:@"warning:"].location != NSNotFound) {
533+
if ([event[kReporter_EndBuildCommand_TotalNumberOfWarnings] unsignedIntegerValue] > 0) {
534534
indicator = [self warningIndicatorString];
535535
} else {
536536
indicator = [self passIndicatorString];

xcodebuild-shim/xcodebuild-shim/xcodebuild_shim.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static void XTSwizzleSelectorForFunction(Class cls, SEL sel, IMP newImp)
4343
method_exchangeImplementations(originalMethod, newMethod);
4444
}
4545

46+
// from IDEFoundation.framework
4647
@interface IDEActivityLogSection : NSObject
4748

4849
// Will be 0 for success, 1 for failure.
@@ -70,6 +71,12 @@ @interface IDEActivityLogSection : NSObject
7071
@property(readonly) double timeStoppedRecording;
7172
@property(readonly) double timeStartedRecording;
7273

74+
// The number of times "warning:" appears in the output.
75+
@property(readonly) NSUInteger totalNumberOfWarnings;
76+
77+
// The number of times "error:" appears in the output.
78+
@property(readonly) NSUInteger totalNumberOfErrors;
79+
7380
@end
7481

7582
#define kDomainTypeBuildItem @"com.apple.dt.IDE.BuildLogSection"
@@ -170,12 +177,18 @@ static void AnnounceEndSection(IDEActivityLogSection *section)
170177
PrintJSON(EventDictionaryWithNameAndContent(
171178
kReporter_Events_EndBuildCommand, @{
172179
kReporter_EndBuildCommand_TitleKey : section.title,
173-
kReporter_EndBuildCommand_SucceededKey : (section.resultCode == 0) ? @YES : @NO,
180+
// Xcode will only consider something a success if resultCode == 0 AND
181+
// there's no output that contains the string "error: ".
182+
kReporter_EndBuildCommand_SucceededKey : ((section.resultCode == 0) &&
183+
(section.totalNumberOfErrors == 0)) ? @YES : @NO,
174184
// Sometimes things will fail and 'emittedOutputText' will be nil. We've seen this
175185
// happen when Xcode's Copy command fails. In this case, just send an empty string
176186
// so Reporters don't have to worry about this sometimes being [NSNull null].
177187
kReporter_EndBuildCommand_EmittedOutputTextKey : section.emittedOutputText ?: @"",
178188
kReporter_EndBuildCommand_DurationKey : @(section.timeStoppedRecording - section.timeStartedRecording),
189+
kReporter_EndBuildCommand_ResultCode : @(section.resultCode),
190+
kReporter_EndBuildCommand_TotalNumberOfWarnings : @(section.totalNumberOfWarnings),
191+
kReporter_EndBuildCommand_TotalNumberOfErrors : @(section.totalNumberOfErrors),
179192
}));
180193
} else if ([sectionTypeString hasPrefix:kDomainTypeProductItemPrefix]) {
181194
NSString *project = nil;

0 commit comments

Comments
 (0)