Skip to content

Commit b9f1a85

Browse files
committed
Fix xclogparser typechecking/functiontiming in modern xcode builds
Signed-off-by: Hesham Salman <[email protected]>
1 parent 7cf8c50 commit b9f1a85

File tree

7 files changed

+29
-30
lines changed

7 files changed

+29
-30
lines changed

Sources/XCLogParser/parser/BuildStep.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public enum DetailStepType: String, Encodable {
9696
switch signature {
9797
case Prefix("CompileC "):
9898
return .cCompilation
99-
case Prefix("CompileSwift "):
99+
case Prefix("SwiftCompile "):
100100
return .swiftCompilation
101101
case Prefix("Ld "):
102102
return .linker

Sources/XCLogParser/parser/IDEActivityLogSection+Parsing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension IDEActivityLogSection {
8787
public func getSwiftIndividualSteps(buildStep: BuildStep,
8888
parentCommandDetailDesc: String,
8989
currentIndex: inout Int) -> [BuildStep]? {
90-
let pattern = #"^CompileSwift\s\w+\s\w+\s.+\.swift\s"#
90+
let pattern = #"^SwiftCompile\s\w+\s\w+\s.+\.swift\s"#
9191
guard commandDetailDesc.range(of: pattern, options: .regularExpression) == nil else {
9292
return nil
9393
}

Sources/XCLogParser/parser/ParserBuildSteps.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public final class ParserBuildSteps {
7575
}()
7676

7777
lazy var swiftcArchRegexp: NSRegularExpression? = {
78-
let pattern = "^CompileSwift normal (\\w*) "
78+
let pattern = "^SwiftCompile normal (\\w*) "
7979
return NSRegularExpression.fromPattern(pattern)
8080
}()
8181

Sources/XCLogParser/parser/SwiftFunctionTime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import Foundation
2121

2222
/// Represents the time it took to the Swift Compiler to compile a function
23-
public struct SwiftFunctionTime: Encodable {
23+
public struct SwiftFunctionTime: Encodable, Hashable {
2424
/// URL of the file where the function is
2525
public let file: String
2626

Sources/XCLogParser/parser/SwiftTypeCheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import Foundation
2121

2222
/// Represents the time it took to the Swift Compiler to type check an expression
23-
public struct SwiftTypeCheck: Encodable {
23+
public struct SwiftTypeCheck: Encodable, Hashable {
2424

2525
/// URL of the file where the function is
2626
public let file: String

Sources/XCLogParser/reporter/HtmlReporter.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,40 +203,39 @@ public struct HtmlReporter: LogReporter {
203203
let steps = build.subSteps.map { $0.subSteps }.joined()
204204
let aggretatedAndSwiftSteps = steps.filter { !$0.fetchedFromCache &&
205205
($0.detailStepType == .swiftCompilation || $0.detailStepType == .swiftAggregatedCompilation) }
206-
var swiftFunctionTimes: [SwiftFunctionTime] = []
207-
var swiftTypeCheckTimes: [SwiftTypeCheck] = []
206+
var _swiftFunctionTimes: Set<SwiftFunctionTime> = []
207+
var _swiftTypeCheckTimes: Set<SwiftTypeCheck> = []
208208
var swiftSteps: [BuildStep] = []
209209

210210
aggretatedAndSwiftSteps.forEach { step in
211-
if step.detailStepType == .swiftAggregatedCompilation {
212-
let swiftSubSteps = step.subSteps.filter { $0.detailStepType == .swiftCompilation}
213-
.map { subStep in
214-
subStep.with(parentIdentifier: step.parentIdentifier)
215-
}
216-
swiftSteps.append(contentsOf: swiftSubSteps)
217-
let functions = swiftSubSteps
218-
.compactMap { $0.swiftFunctionTimes }
219-
.joined()
220-
let typeChecks = swiftSubSteps
221-
.compactMap { $0.swiftTypeCheckTimes }
222-
.joined()
223-
swiftFunctionTimes.append(contentsOf: functions)
224-
swiftTypeCheckTimes.append(contentsOf: typeChecks)
225-
} else {
226-
swiftSteps.append(step)
227-
if let functions = step.swiftFunctionTimes {
228-
swiftFunctionTimes.append(contentsOf: functions)
229-
}
230-
if let typeChecks = step.swiftTypeCheckTimes {
231-
swiftTypeCheckTimes.append(contentsOf: typeChecks)
211+
let swiftSubSteps = step.subSteps.filter { $0.detailStepType == .swiftCompilation}
212+
.map { subStep in
213+
subStep.with(parentIdentifier: step.parentIdentifier)
232214
}
215+
swiftSteps.append(contentsOf: swiftSubSteps)
216+
let functions = swiftSubSteps
217+
.compactMap { $0.swiftFunctionTimes }
218+
.joined()
219+
let typeChecks = swiftSubSteps
220+
.compactMap { $0.swiftTypeCheckTimes }
221+
.joined()
222+
if let functionTimes = step.swiftFunctionTimes {
223+
functionTimes.forEach { _swiftFunctionTimes.insert($0) }
224+
}
225+
if let typeCheckTimes = step.swiftTypeCheckTimes {
226+
typeCheckTimes.forEach { _swiftTypeCheckTimes.insert($0) }
233227
}
228+
functions.forEach { _swiftFunctionTimes.insert($0) }
229+
typeChecks.forEach { _swiftTypeCheckTimes.insert($0) }
234230
}
235231

236232
swiftSteps.sort { $0.compilationDuration > $1.compilationDuration }
237233
let cSteps = steps.filter { !$0.fetchedFromCache && $0.detailStepType == .cCompilation }
238234
.sorted { $0.compilationDuration > $1.compilationDuration }
239235

236+
var swiftFunctionTimes: [SwiftFunctionTime] = Array(_swiftFunctionTimes)
237+
var swiftTypeCheckTimes: [SwiftTypeCheck] = Array(_swiftTypeCheckTimes)
238+
240239
swiftFunctionTimes.sort { $0.durationMS > $1.durationMS }
241240
let topFunctions = Array(swiftFunctionTimes.prefix(Self.maxSwifTypeChecks))
242241

Tests/XCLogParserTests/ParserTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ CompileSwift normal x86_64 (in target 'Alamofire' from project 'Pods')
541541
lazy var fakeSwiftCompilation: IDEActivityLogSection = {
542542
return IDEActivityLogSection(sectionType: 1,
543543
domainType: "",
544-
title: "CompileSwift",
545-
signature: "CompileSwift normal x86_64",
544+
title: "SwiftCompile",
545+
signature: "SwiftCompile normal x86_64",
546546
timeStartedRecording: 1.0,
547547
timeStoppedRecording: 2.0,
548548
subSections: [],

0 commit comments

Comments
 (0)