Skip to content

Commit 967cd47

Browse files
authored
Merge pull request #126 from spotify/skip_notes
Reduced memory used and add option to skip notes
2 parents ab85951 + 9f6b7ac commit 967cd47

File tree

8 files changed

+100
-16
lines changed

8 files changed

+100
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Example output available in the [reporters](#reporters) section.
160160
| `--strictProjectName` | Used in conjunction with `--project`. If specified, a stricter name matching will be done for the project name. | No |
161161
| `--machine_name` | If specified, the machine name will be used to create the `buildIdentifier`. If it is not specified, the host name will be used. | No |
162162
| `--omit_warnings` | Omit the warnings details in the final report. This is useful if there are too many of them and the report's size is too big with them. | No |
163+
| `--omit_notes` | Omit the notes details in the final report. This is useful if there are too many of them and the report's size is too big with them. | No |
163164

164165
>No *: One of `--file`, `--project`, `--workspace`, `--xcodeproj` parameters is required.
165166

Sources/XCLogParser/activityparser/ActivityParser.swift

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ public class ActivityParser {
4646
public func parseActivityLogInURL(_ logURL: URL,
4747
redacted: Bool,
4848
withoutBuildSpecificInformation: Bool) throws -> IDEActivityLog {
49-
let logLoader = LogLoader()
50-
let content = try logLoader.loadFromURL(logURL)
51-
let lexer = Lexer(filePath: logURL.path)
52-
let tokens = try lexer.tokenize(contents: content,
53-
redacted: redacted,
54-
withoutBuildSpecificInformation: withoutBuildSpecificInformation)
49+
let tokens = try getTokens(logURL, redacted: redacted,
50+
withoutBuildSpecificInformation: withoutBuildSpecificInformation)
5551
return try parseIDEActiviyLogFromTokens(tokens)
5652
}
5753

@@ -238,6 +234,29 @@ public class ActivityParser {
238234
endLocation: try parseDocumentLocation(iterator: &iterator))
239235
}
240236

237+
private func getTokens(_ logURL: URL,
238+
redacted: Bool,
239+
withoutBuildSpecificInformation: Bool) throws -> [Token] {
240+
let logLoader = LogLoader()
241+
var tokens: [Token] = []
242+
#if os(Linux)
243+
let content = try logLoader.loadFromURL(logURL)
244+
let lexer = Lexer(filePath: logURL.path)
245+
tokens = try lexer.tokenize(contents: content,
246+
redacted: redacted,
247+
withoutBuildSpecificInformation: withoutBuildSpecificInformation)
248+
#else
249+
try autoreleasepool {
250+
let content = try logLoader.loadFromURL(logURL)
251+
let lexer = Lexer(filePath: logURL.path)
252+
tokens = try lexer.tokenize(contents: content,
253+
redacted: redacted,
254+
withoutBuildSpecificInformation: withoutBuildSpecificInformation)
255+
}
256+
#endif
257+
return tokens
258+
}
259+
241260
private func parseMessages(iterator: inout IndexingIterator<[Token]>) throws -> [IDEActivityLogMessage] {
242261
guard let listToken = iterator.next() else {
243262
throw XCLogParserError.parseError("Parsing [IDEActivityLogMessage]")

Sources/XCLogParser/commands/ActionOptions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,24 @@ public struct ActionOptions {
4949
/// If true, the parse command won't add the Warnings details to the output.
5050
public let omitWarningsDetails: Bool
5151

52+
/// If true, the parse command won't add the Notes details to the output.
53+
public let omitNotesDetails: Bool
54+
5255
public init(reporter: Reporter,
5356
outputPath: String,
5457
redacted: Bool,
5558
withoutBuildSpecificInformation: Bool,
5659
machineName: String? = nil,
5760
rootOutput: String = "",
58-
omitWarningsDetails: Bool = false) {
61+
omitWarningsDetails: Bool = false,
62+
omitNotesDetails: Bool = false) {
5963
self.reporter = reporter
6064
self.outputPath = outputPath
6165
self.redacted = redacted
6266
self.withoutBuildSpecificInformation = withoutBuildSpecificInformation
6367
self.machineName = machineName
6468
self.rootOutput = rootOutput
6569
self.omitWarningsDetails = omitWarningsDetails
70+
self.omitNotesDetails = omitNotesDetails
6671
}
6772
}

Sources/XCLogParser/commands/CommandHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public struct CommandHandler {
6464
options.withoutBuildSpecificInformation)
6565

6666
let buildParser = ParserBuildSteps(machineName: options.machineName,
67-
omitWarningsDetails: options.omitWarningsDetails)
67+
omitWarningsDetails: options.omitWarningsDetails,
68+
omitNotesDetails: options.omitNotesDetails)
6869
let buildSteps = try buildParser.parse(activityLog: activityLog)
6970
let reporterOutput = ReporterOutputFactory.makeReporterOutput(path: options.outputPath)
7071
let logReporter = options.reporter.makeLogReporter()

Sources/XCLogParser/commands/Version.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ import Foundation
2121

2222
public struct Version {
2323

24-
public static let current = "0.2.24"
24+
public static let current = "0.2.25"
2525

2626
}

Sources/XCLogParser/parser/ParserBuildSteps.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public final class ParserBuildSteps {
3838
/// Useful to save space.
3939
let omitWarningsDetails: Bool
4040

41+
/// If true, the Notes won't be parsed.
42+
/// Usefult to save space.
43+
let omitNotesDetails: Bool
44+
4145
public lazy var dateFormatter: DateFormatter = {
4246
let formatter = DateFormatter()
4347
formatter.timeZone = TimeZone(abbreviation: "UTC")
@@ -73,13 +77,18 @@ public final class ParserBuildSteps {
7377

7478
/// - parameter machineName: The name of the machine. It will be used to create a unique identifier
7579
/// for the log. If `nil`, the host name will be used instead.
76-
public init(machineName: String? = nil, omitWarningsDetails: Bool) {
80+
/// - parameter omitWarningsDetails: if true, the Warnings won't be parsed
81+
/// - parameter omitNotesDetails: if true, the Notes won't be parsed
82+
public init(machineName: String? = nil,
83+
omitWarningsDetails: Bool,
84+
omitNotesDetails: Bool) {
7785
if let machineName = machineName {
7886
self.machineName = machineName
7987
} else {
8088
self.machineName = MacOSMachineNameReader().machineName ?? "unknown"
8189
}
8290
self.omitWarningsDetails = omitWarningsDetails
91+
self.omitNotesDetails = omitNotesDetails
8392
}
8493

8594
/// Parses the content from an Xcode log into a `BuildStep`
@@ -154,7 +163,7 @@ public final class ParserBuildSteps {
154163
documentURL: logSection.location.documentURLString,
155164
warnings: omitWarningsDetails ? [] : warnings,
156165
errors: errors,
157-
notes: notes,
166+
notes: omitNotesDetails ? [] : notes,
158167
swiftFunctionTimes: nil,
159168
fetchedFromCache: wasFetchedFromCache(parent:
160169
parentSection, section: logSection),

Sources/XCLogParserApp/commands/ParseCommand.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ struct ParseCommand: ParsableCommand {
114114
""")
115115
var omitWarnings: Bool = false
116116

117+
@Flag(name: .customLong("omit_notes"),
118+
help: """
119+
If present, the report will omit the Notes found in the log.
120+
Useful to reduce the size of the final report.
121+
""")
122+
var omitNotes: Bool = false
123+
117124
mutating func validate() throws {
118125
if !hasValidLogOptions() {
119126
throw ValidationError("""

Tests/XCLogParserTests/ParserTests.swift

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import XCTest
2323
// swiftlint:disable type_body_length file_length
2424
class ParserTests: XCTestCase {
2525

26-
let parser = ParserBuildSteps(omitWarningsDetails: false)
26+
let parser = ParserBuildSteps(omitWarningsDetails: false,
27+
omitNotesDetails: false)
2728

2829
func testDateFormatterUsesJSONFormat() {
2930
let jsonDateString = "2014-09-27T12:30:00.450000Z"
@@ -39,7 +40,9 @@ class ParserTests: XCTestCase {
3940
let machineName = UUID.init().uuidString
4041
let uniqueIdentifier = "uniqueIdentifier"
4142
let timestamp = Date().timeIntervalSinceNow
42-
let parser = ParserBuildSteps(machineName: machineName, omitWarningsDetails: false)
43+
let parser = ParserBuildSteps(machineName: machineName,
44+
omitWarningsDetails: false,
45+
omitNotesDetails: false)
4346
let fakeMainSection = IDEActivityLogSection(sectionType: 1,
4447
domainType: "",
4548
title: "Main",
@@ -65,7 +68,9 @@ class ParserTests: XCTestCase {
6568
XCTAssertEqual("\(machineName)_\(uniqueIdentifier)", buildStep.buildIdentifier)
6669

6770
if let hostName = Host.current().localizedName {
68-
let parserNoMachineName = ParserBuildSteps(machineName: nil, omitWarningsDetails: false)
71+
let parserNoMachineName = ParserBuildSteps(machineName: nil,
72+
omitWarningsDetails: false,
73+
omitNotesDetails: false)
6974
let buildStepNoMachineName = try parserNoMachineName.parse(activityLog: fakeActivityLog)
7075
XCTAssertEqual("\(hostName)_\(uniqueIdentifier)", buildStepNoMachineName.buildIdentifier)
7176
}
@@ -387,7 +392,9 @@ note: use 'updatedDoSomething' instead\r doSomething()\r ^~~~~~~~~~~\r
387392
}
388393

389394
func testGetIndividualSteps() throws {
390-
let buildStep = try parser.parseLogSection(logSection: fakeSwiftCompilation, type: .detail, parentSection: nil)
395+
let buildStep = try parser.parseLogSection(logSection: fakeSwiftCompilation,
396+
type: .detail,
397+
parentSection: nil)
391398
let expectedDocumentURLs = ["file:///test_project/PodsTest/Pods/Alamofire/Source/AFError.swift",
392399
"file:///test_project/PodsTest/Pods/Alamofire/Source/Alamofire.swift",
393400
"file:///test_project/PodsTest/Pods/Alamofire/Source/AlamofireExtended.swift",
@@ -441,12 +448,47 @@ note: use 'updatedDoSomething' instead\r doSomething()\r ^~~~~~~~~~~\r
441448
let fakeLog = getFakeIDEActivityLogWithMessages([warningMessage],
442449
andText: "This is deprecated, [-Wdeprecated-declarations]",
443450
loc: textDocumentLocation)
444-
let parser = ParserBuildSteps(omitWarningsDetails: true)
451+
let parser = ParserBuildSteps(omitWarningsDetails: true,
452+
omitNotesDetails: false)
445453
let build = try parser.parse(activityLog: fakeLog)
446454
XCTAssertEqual(0, build.warnings?.count ?? 0, "Warnings should be empty")
447455
XCTAssertEqual(1, build.warningCount, "Number of warnings should be reported")
448456
}
449457

458+
func testParseOmitNotes() throws {
459+
let timestamp = Date().timeIntervalSinceReferenceDate
460+
let textDocumentLocation = DVTTextDocumentLocation(documentURLString: "file://project/file.m",
461+
timestamp: timestamp,
462+
startingLineNumber: 10,
463+
startingColumnNumber: 11,
464+
endingLineNumber: 12,
465+
endingColumnNumber: 13,
466+
characterRangeEnd: 14,
467+
characterRangeStart: 15,
468+
locationEncoding: 16)
469+
470+
let noteMessage = IDEActivityLogMessage(title: "This is a npte",
471+
shortTitle: "",
472+
timeEmitted: timestamp,
473+
rangeEndInSectionText: 18446744073709551615,
474+
rangeStartInSectionText: 0,
475+
subMessages: [],
476+
severity: 1,
477+
type: "com.apple.dt.IDE.diagnostic",
478+
location: textDocumentLocation,
479+
categoryIdent: "",
480+
secondaryLocations: [],
481+
additionalDescription: "")
482+
483+
let fakeLog = getFakeIDEActivityLogWithMessages([noteMessage],
484+
andText: "Log",
485+
loc: textDocumentLocation)
486+
let parser = ParserBuildSteps(omitWarningsDetails: false,
487+
omitNotesDetails: true)
488+
let build = try parser.parse(activityLog: fakeLog)
489+
XCTAssertEqual(0, build.notes?.count ?? 0, "Notes should be empty")
490+
}
491+
450492
// swiftlint:disable line_length
451493
let commandDetailSwiftSteps = """
452494
CompileSwift normal x86_64 (in target 'Alamofire' from project 'Pods')

0 commit comments

Comments
 (0)