Repository: cpisciotta/xcbeautify
Pull request #360 (2025-01-21 22:42:30)

Add Architecture Enum

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/cpisciotta/xcbeautify/pull/360?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 89.96%. Comparing base [(`ae76ebe`)](https://app.codecov.io/gh/cpisciotta/xcbeautify/commit/ae76ebe68551f3e6d95fa629a5ae6fa6eef384b0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta) to head [(`62a58ab`)](https://app.codecov.io/gh/cpisciotta/xcbeautify/commit/62a58abed9c912044ce76d8bf6d0af20d09ef8fa?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #360   +/-   ##
=======================================
  Coverage   89.95%   89.96%           
=======================================
  Files          17       17           
  Lines        2420     2421    +1     
=======================================
+ Hits         2177     2178    +1     
  Misses        243      243           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/cpisciotta/xcbeautify/pull/360?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).


Patch:
diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift
index 84b513a..2f186d4 100644
--- a/Sources/XcbeautifyLib/CaptureGroups.swift
+++ b/Sources/XcbeautifyLib/CaptureGroups.swift
@@ -1205,14 +1205,16 @@ struct RegisterExecutionPolicyExceptionCaptureGroup: CaptureGroup {
 struct ScanDependenciesCaptureGroup: CaptureGroup {
     static let outputType: OutputType = .task
 
-    static let regex = XCRegex(pattern: #"ScanDependencies .* normal (?:arm64|x86_64) .* \(in target '(.*)' from project '(.*)'\)$"#)
+    static let regex = XCRegex(pattern: #"ScanDependencies .* normal (arm64|arm64_32|armv7k|i386|x86_64) .* \(in target '(.*)' from project '(.*)'\)$"#)
 
+    let arch: Architecture
     let target: String
     let project: String
 
     init?(groups: [String]) {
-        assert(groups.count == 2)
-        guard let target = groups[safe: 0], let project = groups[safe: 1] else { return nil }
+        assert(groups.count == 3)
+        guard let _arch = groups[safe: 0], let arch = Architecture(rawValue: _arch), let target = groups[safe: 1], let project = groups[safe: 2] else { return nil }
+        self.arch = arch
         self.target = target
         self.project = project
     }
@@ -1928,17 +1930,17 @@ struct SwiftDriverJobDiscoveryCompilingCaptureGroup: CaptureGroup {
     // $3 = filenames
     // $4 = target
     // $5 = project
-    static let regex = XCRegex(pattern: #"^SwiftDriverJobDiscovery (\S+) (\S+) Compiling ((?:\S|(?>, )|(?<=\\) )+) \(in target '(.*)' from project '(.*)'\)"#)
+    static let regex = XCRegex(pattern: #"^SwiftDriverJobDiscovery (\S+) (arm64|arm64_32|armv7k|i386|x86_64) Compiling ((?:\S|(?>, )|(?<=\\) )+) \(in target '(.*)' from project '(.*)'\)"#)
 
     let state: String // Currently, the only expected/known value is `normal`
-    let architecture: String
+    let architecture: Architecture
     let filenames: [String]
     let target: String
     let project: String
 
     init?(groups: [String]) {
         assert(groups.count == 5)
-        guard let state = groups[safe: 0], let architecture = groups[safe: 1], let filenamesGroup = groups[safe: 2], let target = groups[safe: 3], let project = groups[safe: 4] else { return nil }
+        guard let state = groups[safe: 0], let _architecture = groups[safe: 1], let architecture = Architecture(rawValue: _architecture), let filenamesGroup = groups[safe: 2], let target = groups[safe: 3], let project = groups[safe: 4] else { return nil }
         self.state = state
         self.architecture = architecture
         filenames = filenamesGroup.components(separatedBy: ", ")
@@ -2247,7 +2249,7 @@ struct SwiftTestingPassingArgumentCaptureGroup: CaptureGroup {
 struct SwiftDriverTargetCaptureGroup: CaptureGroup {
     static let outputType: OutputType = .task
 
-    static let regex = XCRegex(pattern: #"^SwiftDriver (.*) normal (?:arm64|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
+    static let regex = XCRegex(pattern: #"^SwiftDriver (.*) normal (?:arm64|arm64_32|armv7k|i386|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
 
     let target: String
 
@@ -2261,7 +2263,7 @@ struct SwiftDriverTargetCaptureGroup: CaptureGroup {
 struct SwiftDriverCompilationTarget: CaptureGroup {
     static let outputType: OutputType = .task
 
-    static let regex = XCRegex(pattern: #"^SwiftDriver\\ Compilation (.*) normal (?:arm64|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
+    static let regex = XCRegex(pattern: #"^SwiftDriver\\ Compilation (.*) normal (?:arm64|arm64_32|armv7k|i386|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
 
     let target: String
 
@@ -2275,7 +2277,7 @@ struct SwiftDriverCompilationTarget: CaptureGroup {
 struct SwiftDriverCompilationRequirementsCaptureGroup: CaptureGroup {
     static let outputType: OutputType = .task
 
-    static let regex = XCRegex(pattern: #"^SwiftDriver\\ Compilation\\ Requirements (.*) normal (?:arm64|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
+    static let regex = XCRegex(pattern: #"^SwiftDriver\\ Compilation\\ Requirements (.*) normal (?:arm64|arm64_32|armv7k|i386|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
 
     let target: String
 
@@ -2297,16 +2299,16 @@ struct MkDirCaptureGroup: CaptureGroup {
 struct SwiftEmitModuleCaptureGroup: CaptureGroup {
     static let outputType: OutputType = .task
 
-    static let regex = XCRegex(pattern: #"^SwiftEmitModule normal (arm64|x86_64|i386) Emitting\\ module\\ for\\ (.+) \(in target '(.+)' from project '(.+)'\)$"#)
+    static let regex = XCRegex(pattern: #"^SwiftEmitModule normal (arm64|arm64_32|armv7k|i386|x86_64) Emitting\\ module\\ for\\ (.+) \(in target '(.+)' from project '(.+)'\)$"#)
 
-    let arch: String
+    let arch: Architecture
     let module: String
     let target: String
     let project: String
 
     init?(groups: [String]) {
         assert(groups.count == 4)
-        guard let arch = groups[safe: 0], let module = groups[safe: 1], let target = groups[safe: 2], let project = groups[safe: 3] else { return nil }
+        guard let _arch = groups[safe: 0], let arch = Architecture(rawValue: _arch), let module = groups[safe: 1], let target = groups[safe: 2], let project = groups[safe: 3] else { return nil }
         self.arch = arch
         self.module = module
         self.target = target
@@ -2317,15 +2319,15 @@ struct SwiftEmitModuleCaptureGroup: CaptureGroup {
 struct EmitSwiftModuleCaptureGroup: CaptureGroup {
     static let outputType: OutputType = .task
 
-    static let regex = XCRegex(pattern: #"^EmitSwiftModule normal (arm64|x86_64|i386) \(in target '(.+)' from project '(.+)'\)$"#)
+    static let regex = XCRegex(pattern: #"^EmitSwiftModule normal (arm64|arm64_32|armv7k|i386|x86_64) \(in target '(.+)' from project '(.+)'\)$"#)
 
-    let arch: String
+    let arch: Architecture
     let target: String
     let project: String
 
     init?(groups: [String]) {
         assert(groups.count == 3)
-        guard let arch = groups[safe: 0], let target = groups[safe: 1], let project = groups[safe: 2] else { return nil }
+        guard let _arch = groups[safe: 0], let arch = Architecture(rawValue: _arch), let target = groups[safe: 1], let project = groups[safe: 2] else { return nil }
         self.arch = arch
         self.target = target
         self.project = project
diff --git a/Sources/XcbeautifyLib/Constants.swift b/Sources/XcbeautifyLib/Constants.swift
index 43cac68..556667b 100644
--- a/Sources/XcbeautifyLib/Constants.swift
+++ b/Sources/XcbeautifyLib/Constants.swift
@@ -1,3 +1,11 @@
+enum Architecture: String {
+    case arm64
+    case arm64_32
+    case armv7k
+    case i386
+    case x86_64
+}
+
 enum Format {
     static let indent = "    "
 }


Test patch:
diff --git a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
index 716db69..cd87016 100644
--- a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
+++ b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
@@ -57,9 +57,10 @@ final class CaptureGroupTests: XCTestCase {
     func testScanDependencies() throws {
         let input = #"ScanDependencies /Users/Some/Random-Path/_To/A/Build/Intermediates.noindex/Some/Other.build/x86_64/file-ABC123.o /Users/Some/Other-Random-Path/_To/A/Build/Intermediates.noindex/Some/Other.build/x86_64/file-DEF456.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'SomeTarget' from project 'SomeProject')"#
         let groups = try XCTUnwrap(ScanDependenciesCaptureGroup.regex.captureGroups(for: input))
-        XCTAssertEqual(groups.count, 2)
-        XCTAssertEqual(groups[0], "SomeTarget")
-        XCTAssertEqual(groups[1], "SomeProject")
+        XCTAssertEqual(groups.count, 3)
+        XCTAssertEqual(groups[0], "x86_64")
+        XCTAssertEqual(groups[1], "SomeTarget")
+        XCTAssertEqual(groups[2], "SomeProject")
     }
 
     func testSigning() throws {
diff --git a/Tests/XcbeautifyLibTests/ParserTests.swift b/Tests/XcbeautifyLibTests/ParserTests.swift
index 603cb9b..7d6d7b1 100644
--- a/Tests/XcbeautifyLibTests/ParserTests.swift
+++ b/Tests/XcbeautifyLibTests/ParserTests.swift
@@ -82,7 +82,7 @@ final class ParserTests: XCTestCase {
         let input = #"SwiftDriverJobDiscovery normal arm64 Compiling resource_bundle_accessor.swift (in target 'Some Target' from project 'Some Project')"#
         let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftDriverJobDiscoveryCompilingCaptureGroup)
         XCTAssertEqual(captureGroup.state, "normal")
-        XCTAssertEqual(captureGroup.architecture, "arm64")
+        XCTAssertEqual(captureGroup.architecture, .arm64)
         XCTAssertEqual(captureGroup.filenames, ["resource_bundle_accessor.swift"])
         XCTAssertEqual(captureGroup.target, "Some Target")
         XCTAssertEqual(captureGroup.project, "Some Project")
@@ -92,7 +92,7 @@ final class ParserTests: XCTestCase {
         let input = #"SwiftDriverJobDiscovery normal x86_64 Compiling BackyardVisitorEvent+DataGeneration.swift, BackyardVisitors\ &\ Events.swift, Bird+DataGeneration.swift, Bird.swift (in target 'BackyardBirdsDataTarget' from project 'BackyardBirdsDataProject')"#
         let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftDriverJobDiscoveryCompilingCaptureGroup)
         XCTAssertEqual(captureGroup.state, "normal")
-        XCTAssertEqual(captureGroup.architecture, "x86_64")
+        XCTAssertEqual(captureGroup.architecture, .x86_64)
         XCTAssertEqual(captureGroup.filenames, ["BackyardVisitorEvent+DataGeneration.swift", #"BackyardVisitors\ &\ Events.swift"#, "Bird+DataGeneration.swift", "Bird.swift"])
         XCTAssertEqual(captureGroup.target, "BackyardBirdsDataTarget")
         XCTAssertEqual(captureGroup.project, "BackyardBirdsDataProject")
@@ -285,7 +285,7 @@ final class ParserTests: XCTestCase {
 
     func testSwiftEmitModule() throws {
         let captureGroup = try XCTUnwrap(parser.parse(line: #"SwiftEmitModule normal i386 Emitting\ module\ for\ CasePaths (in target 'CasePathsTarget' from project 'swift-case-paths')"#) as? SwiftEmitModuleCaptureGroup)
-        XCTAssertEqual(captureGroup.arch, "i386")
+        XCTAssertEqual(captureGroup.arch, .i386)
         XCTAssertEqual(captureGroup.module, "CasePaths")
         XCTAssertEqual(captureGroup.target, "CasePathsTarget")
         XCTAssertEqual(captureGroup.project, "swift-case-paths")
@@ -293,7 +293,7 @@ final class ParserTests: XCTestCase {
 
     func testEmitSwiftModule() throws {
         let captureGroup = try XCTUnwrap(parser.parse(line: #"EmitSwiftModule normal arm64 (in target 'Target' from project 'Project')"#) as? EmitSwiftModuleCaptureGroup)
-        XCTAssertEqual(captureGroup.arch, "arm64")
+        XCTAssertEqual(captureGroup.arch, .arm64)
         XCTAssertEqual(captureGroup.target, "Target")
         XCTAssertEqual(captureGroup.project, "Project")
     }