Skip to content

Commit

Permalink
Merge pull request #62 from spotify/compilation_duration_bug
Browse files Browse the repository at this point in the history
Fixes Compilation duration bug and duplicated ids bug
  • Loading branch information
ecamacho committed Feb 17, 2020
2 parents 7ded2ab + 20b1db8 commit 73b7563
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/XCLogParser/commands/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import Foundation

public struct Version {

public static let current = "0.2.4"
public static let current = "0.2.5"

}
32 changes: 32 additions & 0 deletions Sources/XCLogParser/parser/BuildStep+Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ extension BuildStep {
compilationDuration: newCompilationDuration)
}

func with(identifier newIdentifier: String) -> BuildStep {
return BuildStep(type: type,
machineName: machineName,
buildIdentifier: buildIdentifier,
identifier: newIdentifier,
parentIdentifier: parentIdentifier,
domain: domain,
title: title,
signature: signature,
startDate: startDate,
endDate: endDate,
startTimestamp: startTimestamp,
endTimestamp: endTimestamp,
duration: duration,
detailStepType: detailStepType,
buildStatus: buildStatus,
schema: schema,
subSteps: subSteps,
warningCount: warningCount,
errorCount: errorCount,
architecture: architecture,
documentURL: documentURL,
warnings: warnings,
errors: errors,
notes: notes,
swiftFunctionTimes: swiftFunctionTimes,
fetchedFromCache: fetchedFromCache,
compilationEndTimestamp: compilationEndTimestamp,
compilationDuration: compilationDuration
)
}

private func filterNotices(_ notices: [Notice]?) -> [Notice]? {
guard let notices = notices else {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ extension IDEActivityLogSection {
/// Parses the swift files compiled in a module when `whole module` is used
///
/// - Parameter buildStep: the `BuildStep` that has the information about the module
/// - Parameter currentIndex: the Step current Index. This index is used to generated the unique identifier of
/// the steps
/// - Returns: An array of `BuildStep` with the data of each individual Swift file
/// including the warnings and errors generated by its compilation.
public func getSwiftIndividualSteps(buildStep: BuildStep) -> [BuildStep]? {
public func getSwiftIndividualSteps(buildStep: BuildStep, currentIndex: inout Int) -> [BuildStep]? {
let pattern = #"^CompileSwift\s\w+\s\w+\s.+\.swift\s"#
guard commandDetailDesc.range(of: pattern, options: .regularExpression) == nil else {
return nil
Expand All @@ -94,7 +96,9 @@ extension IDEActivityLogSection {
range: NSRange(location: 0, length: commandDetailDesc.count))
.map { match -> BuildStep in
let file = commandDetailDesc.substring(match.range(at: 1))
currentIndex += 1
return buildStep
.with(identifier: "\(buildStep.buildIdentifier)_\(currentIndex)")
.with(documentURL: "file://\(file)")
.with(title: "Compile \(file)")
.with(signature: "\(buildStep.signature) \(file)")
Expand Down
7 changes: 4 additions & 3 deletions Sources/XCLogParser/parser/ParserBuildSteps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public final class ParserBuildSteps {
}
if step.detailStepType == .swiftCompilation {
swiftFunctionTimesParser.addLogSection(logSection)
if let individualSwiftSteps = logSection.getSwiftIndividualSteps(buildStep: step) {
if let individualSwiftSteps = logSection.getSwiftIndividualSteps(buildStep: step,
currentIndex: &currentIndex) {
step.subSteps.append(contentsOf: individualSwiftSteps)
step = step.withFilteredNotices()
}
Expand Down Expand Up @@ -322,7 +323,7 @@ public final class ParserBuildSteps {

private func addCompilationTimesToTarget(_ target: BuildStep) -> BuildStep {
let lastCompilationStep = target.subSteps
.filter { $0.isCompilationStep() }
.filter { $0.isCompilationStep() && $0.fetchedFromCache == false }
.max { $0.compilationEndTimestamp < $1.compilationEndTimestamp }
guard let lastStep = lastCompilationStep else {
return target
Expand All @@ -333,7 +334,7 @@ public final class ParserBuildSteps {

private func addCompilationTimesToApp(_ app: BuildStep) -> BuildStep {
let lastCompilationStep = app.subSteps
.filter { $0.compilationEndTimestamp > 0 }
.filter { $0.compilationEndTimestamp > 0 && $0.fetchedFromCache == false }
.max { $0.compilationEndTimestamp < $1.compilationEndTimestamp }
guard let lastStep = lastCompilationStep else {
return app
Expand Down
15 changes: 15 additions & 0 deletions Tests/XCLogParserTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,21 @@ class ParserTests: XCTestCase {
"file:///test_project/PodsTest/Pods/Alamofire/Source/EventMonitor.swift"]
let documentURLs = buildStep.subSteps.map { $0.documentURL }
XCTAssertEqual(expectedDocumentURLs, documentURLs)

let parsedBuild = buildStep.flatten()
var idsDict: [String: String] = [:]
parsedBuild.compactMap { step -> String? in
if step.detailStepType == .swiftCompilation {
return step.identifier
}
return nil
}.forEach { identifier in
if idsDict[identifier] == nil {
idsDict[identifier] = identifier
} else {
XCTFail("Duplicated identifier \(identifier)")
}
}
}

// swiftlint:disable line_length
Expand Down

0 comments on commit 73b7563

Please sign in to comment.