Skip to content

Commit caf6d54

Browse files
authored
fix silent crash when output from compiler is too large (#3478)
motivation: silent crashes, confused uers changes: * change the order in swiftCompilerOutputParser such that print the stdout happens before any parsing attenpts are made * contraint the parsing attempts to output < 10k, since otherwise they struggle to complete rdar://77558631
1 parent 052e692 commit caf6d54

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,18 +586,22 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
586586
}
587587

588588
if let output = message.standardOutput {
589-
// Scoop out any errors from the output, so they can later be passed to the advice provider in case of failure.
590-
let regex = try! RegEx(pattern: #".*(error:[^\n]*)\n.*"#, options: .dotMatchesLineSeparators)
591-
for match in regex.matchGroups(in: output) {
592-
self.errorMessagesByTarget[parser.targetName] = (self.errorMessagesByTarget[parser.targetName] ?? []) + [match[0]]
593-
}
594-
589+
// first we want to print the output so users have it handy
595590
if !self.isVerbose {
596591
self.progressAnimation.clear()
597592
}
598593

599594
self.outputStream <<< output
600595
self.outputStream.flush()
596+
597+
// next we want to try and scoop out any errors from the output (if reasonable size, otherwise this will be very slow),
598+
// so they can later be passed to the advice provider in case of failure.
599+
if output.utf8.count < 1024 * 10 {
600+
let regex = try! RegEx(pattern: #".*(error:[^\n]*)\n.*"#, options: .dotMatchesLineSeparators)
601+
for match in regex.matchGroups(in: output) {
602+
self.errorMessagesByTarget[parser.targetName] = (self.errorMessagesByTarget[parser.targetName] ?? []) + [match[0]]
603+
}
604+
}
601605
}
602606
}
603607
}

0 commit comments

Comments
 (0)