Skip to content

Commit ba46699

Browse files
committed
Skip parsing of section attachments for logs with version less than 11
Signed-off-by: Steffen Matthischke <[email protected]>
1 parent 97e1375 commit ba46699

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

Sources/XCLogParser/activityparser/ActivityParser.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public class ActivityParser {
3030
/// that into account
3131
var isCommandLineLog = false
3232

33+
/// The version of the parsed `IDEActivityLog`.
34+
/// Used to skip parsing of the `IDEActivityLogSectionAttachment` list on version less than 11.
35+
var logVersion: Int8?
36+
3337
public init() {}
3438

3539
/// Parses the xcacticitylog argument into a `IDEActivityLog`
@@ -53,7 +57,9 @@ public class ActivityParser {
5357

5458
public func parseIDEActiviyLogFromTokens(_ tokens: [Token]) throws -> IDEActivityLog {
5559
var iterator = tokens.makeIterator()
56-
return IDEActivityLog(version: Int8(try parseAsInt(token: iterator.next())),
60+
let logVersion = Int8(try parseAsInt(token: iterator.next()))
61+
self.logVersion = logVersion
62+
return IDEActivityLog(version: logVersion,
5763
mainSection: try parseLogSection(iterator: &iterator))
5864
}
5965

@@ -458,6 +464,14 @@ public class ActivityParser {
458464

459465
private func parseIDEActivityLogSectionAttachments(iterator: inout IndexingIterator<[Token]>)
460466
throws -> [IDEActivityLogSectionAttachment] {
467+
guard let logVersion else {
468+
throw XCLogParserError.parseError("Log version not parsed before parsing " +
469+
"array of IDEActivityLogSectionAttachment")
470+
}
471+
/// The list of IDEActivityLogSectionAttachment was introduced with version 11
472+
guard logVersion >= 11 else {
473+
return []
474+
}
461475
guard let listToken = iterator.next() else {
462476
throw XCLogParserError.parseError("Unexpected EOF parsing array of IDEActivityLogSectionAttachment")
463477
}

Tests/XCLogParserTests/ActivityParserTests.swift

+60
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,34 @@ class ActivityParserTests: XCTestCase {
108108
return startTokens + logMessageTokens + endTokens
109109
}()
110110

111+
lazy var IDEActivityLogSectionTokensWithoutAttachments: [Token] = {
112+
let startTokens = [Token.int(2),
113+
Token.string("com.apple.dt.IDE.BuildLogSection"),
114+
Token.string("Prepare build"),
115+
Token.string("Prepare build"),
116+
Token.double(575479851.278759),
117+
Token.double(575479851.778325),
118+
Token.null,
119+
Token.string("note: Using legacy build system"),
120+
Token.list(1),
121+
Token.className("IDEActivityLogMessage"),
122+
Token.classNameRef("IDEActivityLogMessage"),
123+
]
124+
let logMessageTokens = IDEActivityLogMessageTokens
125+
let endTokens = [Token.int(1),
126+
Token.int(0),
127+
Token.int(1),
128+
Token.string("subtitle"),
129+
Token.null,
130+
Token.string("commandDetailDesc"),
131+
Token.string("501796C4-6BE4-4F80-9F9D-3269617ECC17"),
132+
Token.string("localizedResultString"),
133+
Token.string("xcbuildSignature"),
134+
Token.int(0)
135+
]
136+
return startTokens + logMessageTokens + endTokens
137+
}()
138+
111139
let IDEConsoleItemTokens: [Token] = [
112140
Token.className("IDEConsoleItem"),
113141
Token.classNameRef("IDEConsoleItem"),
@@ -288,6 +316,7 @@ class ActivityParserTests: XCTestCase {
288316
}
289317

290318
func testParseIDEActivityLogSection() throws {
319+
parser.logVersion = 11
291320
let tokens = IDEActivityLogSectionTokens
292321
var iterator = tokens.makeIterator()
293322
let logSection = try parser.parseIDEActivityLogSection(iterator: &iterator)
@@ -310,15 +339,46 @@ class ActivityParserTests: XCTestCase {
310339
XCTAssertEqual("501796C4-6BE4-4F80-9F9D-3269617ECC17", logSection.uniqueIdentifier)
311340
XCTAssertEqual("localizedResultString", logSection.localizedResultString)
312341
XCTAssertEqual("xcbuildSignature", logSection.xcbuildSignature)
342+
XCTAssertEqual(1, logSection.attachments.count)
343+
XCTAssertEqual(0, logSection.unknown)
344+
}
345+
346+
func testParseIDEActivityLogSection_version10() throws {
347+
parser.logVersion = 10
348+
let tokens = IDEActivityLogSectionTokensWithoutAttachments
349+
var iterator = tokens.makeIterator()
350+
let logSection = try parser.parseIDEActivityLogSection(iterator: &iterator)
351+
XCTAssertEqual(2, logSection.sectionType)
352+
XCTAssertEqual("com.apple.dt.IDE.BuildLogSection", logSection.domainType)
353+
XCTAssertEqual("Prepare build", logSection.title)
354+
XCTAssertEqual("Prepare build", logSection.signature)
355+
XCTAssertEqual(575479851.278759, logSection.timeStartedRecording)
356+
XCTAssertEqual(575479851.778325, logSection.timeStoppedRecording)
357+
XCTAssertEqual(0, logSection.subSections.count)
358+
XCTAssertEqual("note: Using legacy build system", logSection.text)
359+
XCTAssertEqual(1, logSection.messages.count)
360+
XCTAssertTrue(logSection.wasCancelled)
361+
XCTAssertFalse(logSection.isQuiet)
362+
XCTAssertTrue(logSection.wasFetchedFromCache)
363+
XCTAssertEqual("subtitle", logSection.subtitle)
364+
XCTAssertEqual("", logSection.location.documentURLString)
365+
XCTAssertEqual(0, logSection.location.timestamp)
366+
XCTAssertEqual("commandDetailDesc", logSection.commandDetailDesc)
367+
XCTAssertEqual("501796C4-6BE4-4F80-9F9D-3269617ECC17", logSection.uniqueIdentifier)
368+
XCTAssertEqual("localizedResultString", logSection.localizedResultString)
369+
XCTAssertEqual("xcbuildSignature", logSection.xcbuildSignature)
370+
XCTAssertEqual(0, logSection.attachments.count)
313371
XCTAssertEqual(0, logSection.unknown)
314372
}
315373

316374
func testParseActivityLog() throws {
317375
let activityLog = try parser.parseIDEActiviyLogFromTokens(IDEActivityLogTokens)
318376
XCTAssertEqual(10, activityLog.version)
377+
XCTAssertEqual(10, parser.logVersion)
319378
}
320379

321380
func testParseDBGConsoleLog() throws {
381+
parser.logVersion = 11
322382
let tokens = DBGConsoleLogTokens
323383
var iterator = tokens.makeIterator()
324384
let DBGConsoleLog = try parser.parseDBGConsoleLog(iterator: &iterator)

0 commit comments

Comments
 (0)