Skip to content

Commit 365ebd7

Browse files
committed
fix: parse Xcode 27 activity log sections
1 parent 44fc3b3 commit 365ebd7

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

Sources/XCLogParser/activityparser/ActivityParser.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ public class ActivityParser {
105105
let timeStartedRecording = try parseAsDouble(token: iterator.next())
106106
let timeStoppedRecording = try parseAsDouble(token: iterator.next())
107107
let subSections = try parseIDEActivityLogSections(iterator: &iterator)
108-
let text = try parseAsString(token: iterator.next())
108+
var textToken = iterator.next()
109+
// On Xcode 27.0+, an unknown integer appears before text
110+
if case .some(.int) = textToken {
111+
textToken = iterator.next()
112+
}
113+
let text = try parseAsString(token: textToken)
109114
let messages = try parseMessages(iterator: &iterator)
110115
let wasCancelled = try parseBoolean(token: iterator.next())
111116
let isQuiet = try parseBoolean(token: iterator.next())

Tests/XCLogParserTests/ActivityParserTests.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,37 @@ class ActivityParserTests: XCTestCase {
214214
return startTokens + logMessageTokens + endTokens
215215
}()
216216

217+
// Xcode 27.0 format: unknown integer appears before text
218+
lazy var IDEActivityLogSectionTokensXcode270: [Token] = {
219+
let startTokens = [Token.int(2),
220+
Token.string("com.apple.dt.IDE.BuildLogSection"),
221+
Token.string("Prepare build"),
222+
Token.string("Prepare build"),
223+
Token.double(575479851.278759),
224+
Token.double(575479851.778325),
225+
Token.null,
226+
Token.int(0),
227+
Token.string("note: Using legacy build system"),
228+
Token.list(1),
229+
Token.className("IDEActivityLogMessage"),
230+
Token.classNameRef("IDEActivityLogMessage"),
231+
]
232+
let logMessageTokens = IDEActivityLogMessageTokens
233+
let endTokens = [Token.int(1),
234+
Token.int(0),
235+
Token.int(1),
236+
Token.int(42),
237+
Token.string("subtitle"),
238+
Token.null,
239+
Token.string("commandDetailDesc"),
240+
Token.string("501796C4-6BE4-4F80-9F9D-3269617ECC17"),
241+
Token.string("localizedResultString"),
242+
Token.string("xcbuildSignature"),
243+
Token.list(0), // attachments
244+
]
245+
return startTokens + logMessageTokens + endTokens
246+
}()
247+
217248
let IDEConsoleItemTokens: [Token] = [
218249
Token.className("IDEConsoleItem"),
219250
Token.classNameRef("IDEConsoleItem"),
@@ -519,6 +550,34 @@ class ActivityParserTests: XCTestCase {
519550
XCTAssertEqual(42, logSection.unknown)
520551
}
521552

553+
func testParseIDEActivityLogSectionXcode270() throws {
554+
parser.logVersion = 13
555+
let tokens = IDEActivityLogSectionTokensXcode270
556+
var iterator = tokens.makeIterator()
557+
let logSection = try parser.parseIDEActivityLogSection(iterator: &iterator)
558+
XCTAssertEqual(2, logSection.sectionType)
559+
XCTAssertEqual("com.apple.dt.IDE.BuildLogSection", logSection.domainType)
560+
XCTAssertEqual("Prepare build", logSection.title)
561+
XCTAssertEqual("Prepare build", logSection.signature)
562+
XCTAssertEqual(575479851.278759, logSection.timeStartedRecording)
563+
XCTAssertEqual(575479851.778325, logSection.timeStoppedRecording)
564+
XCTAssertEqual(0, logSection.subSections.count)
565+
XCTAssertEqual("note: Using legacy build system", logSection.text)
566+
XCTAssertEqual(1, logSection.messages.count)
567+
XCTAssertTrue(logSection.wasCancelled)
568+
XCTAssertFalse(logSection.isQuiet)
569+
XCTAssertTrue(logSection.wasFetchedFromCache)
570+
XCTAssertEqual("subtitle", logSection.subtitle)
571+
XCTAssertEqual("", logSection.location.documentURLString)
572+
XCTAssertEqual(0, logSection.location.timestamp)
573+
XCTAssertEqual("commandDetailDesc", logSection.commandDetailDesc)
574+
XCTAssertEqual("501796C4-6BE4-4F80-9F9D-3269617ECC17", logSection.uniqueIdentifier)
575+
XCTAssertEqual("localizedResultString", logSection.localizedResultString)
576+
XCTAssertEqual("xcbuildSignature", logSection.xcbuildSignature)
577+
XCTAssertEqual(0, logSection.attachments.count)
578+
XCTAssertEqual(42, logSection.unknown)
579+
}
580+
522581
func testParseActivityLog() throws {
523582
let activityLog = try parser.parseIDEActiviyLogFromTokens(IDEActivityLogTokens)
524583
XCTAssertEqual(10, activityLog.version)

Tests/XCLogParserTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extension ActivityParserTests {
1313
("testParseIDEActivityLogAnalyzerResultMessage", testParseIDEActivityLogAnalyzerResultMessage),
1414
("testParseIDEActivityLogMessage", testParseIDEActivityLogMessage),
1515
("testParseIDEActivityLogSection", testParseIDEActivityLogSection),
16+
("testParseIDEActivityLogSectionXcode270", testParseIDEActivityLogSectionXcode270),
1617
("testParseXcode3ProjectLocation", testParseXcode3ProjectLocation),
1718
]
1819
}

0 commit comments

Comments
 (0)