Skip to content

Commit

Permalink
Add Architecture Enum (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta authored Jan 21, 2025
1 parent ae76ebe commit f44a1ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
32 changes: 17 additions & 15 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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: ", ")
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Sources/XcbeautifyLib/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
enum Architecture: String {
case arm64
case arm64_32
case armv7k
case i386
case x86_64
}

enum Format {
static let indent = " "
}
Expand Down
7 changes: 4 additions & 3 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -285,15 +285,15 @@ 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")
}

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")
}
Expand Down

0 comments on commit f44a1ed

Please sign in to comment.