Skip to content

Commit

Permalink
Add CopyFilesCaptureGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta committed Jul 30, 2024
1 parent 5ddce47 commit 316d0a8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
22 changes: 22 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ struct CompileStoryboardCaptureGroup: CompileFileCaptureGroup {
}
}

struct CopyFilesCaptureGroup: CaptureGroup {
static let outputType: OutputType = .task

static let regex = Regex(pattern: #"^Copy (\/.*) (\/.*) \(in target '(.*)' from project '.*'\)$"#)

let firstFilePath: String
let firstFilename: String
let secondFilePath: String
let secondFilename: String
let target: String

init?(groups: [String]) {
assert(groups.count == 3)
guard let firstFilePath = groups[safe: 0], let secondFilePath = groups[safe: 1], let target = groups[safe: 2] else { return nil }
self.firstFilePath = firstFilePath
firstFilename = URL(fileURLWithPath: firstFilePath).lastPathComponent
self.secondFilePath = secondFilePath
secondFilename = URL(fileURLWithPath: secondFilePath).lastPathComponent
self.target = target
}
}

struct CopyHeaderCaptureGroup: CopyCaptureGroup {
static let outputType: OutputType = .task

Expand Down
2 changes: 2 additions & 0 deletions Sources/XcbeautifyLib/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ package struct Formatter {
return renderer.formatCompileWarning(group: group)
case let group as CompileXibCaptureGroup:
return renderer.formatCompile(group: group)
case let group as CopyFilesCaptureGroup:
return renderer.formatCopyFiles(group: group)
case let group as CopyHeaderCaptureGroup:
return renderer.formatCopy(group: group)
case let group as CopyPlistCaptureGroup:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package final class Parser {
CompileCommandCaptureGroup.self,
CompileXibCaptureGroup.self,
CompileStoryboardCaptureGroup.self,
CopyFilesCaptureGroup.self,
CopyHeaderCaptureGroup.self,
CopyPlistCaptureGroup.self,
CopyStringsCaptureGroup.self,
Expand Down
8 changes: 8 additions & 0 deletions Sources/XcbeautifyLib/Renderers/OutputRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol OutputRendering {
func formatCompileError(group: CompileErrorCaptureGroup) -> String
func formatCompileWarning(group: CompileWarningCaptureGroup) -> String
func formatCopy(group: any CopyCaptureGroup) -> String
func formatCopyFiles(group: CopyFilesCaptureGroup) -> String
func formatCoverageReport(group: GeneratedCoverageReportCaptureGroup) -> String
func formatCursor(group: CursorCaptureGroup) -> String?
func formatDuplicateLocalizedStringKey(group: DuplicateLocalizedStringKeyCaptureGroup) -> String
Expand Down Expand Up @@ -129,6 +130,13 @@ extension OutputRendering {
return colored ? "[\(target.f.Cyan)] \("Copying".s.Bold) \(filename)" : "[\(target)] Copying \(filename)"
}

func formatCopyFiles(group: CopyFilesCaptureGroup) -> String {
let target = group.target
let firstFilename = group.firstFilename
let secondFilename = group.secondFilename
return colored ? "[\(target.f.Cyan)] \("Copy".s.Bold) \(firstFilename) -> \(secondFilename)" : "[\(target)] Copy \(firstFilename) -> \(secondFilename)"
}

func formatCursor(group: CursorCaptureGroup) -> String? {
nil
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ final class CaptureGroupTests: XCTestCase {
XCTAssertTrue(CompilationResultCaptureGroup.regex.match(string: input))
}

func testMatchCopyFilesMatchingSourceAndDestinationFilenames() {
let input = #"Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"#
XCTAssertTrue(CopyFilesCaptureGroup.regex.match(string: input))
}

func testMatchSwiftDriverJobDiscoveryEmittingModule() {
let input = #"SwiftDriverJobDiscovery normal arm64 Emitting module for Widgets (in target 'Widgets' from project 'Backyard Birds')"#
XCTAssertTrue(SwiftDriverJobDiscoveryEmittingModuleCaptureGroup.regex.match(string: input))
Expand Down
8 changes: 4 additions & 4 deletions Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class ParsingTests: XCTestCase {
// Update this magic number whenever `uncapturedOutput` is less than the current magic number.
// There's a regression whenever `uncapturedOutput` is greater than the current magic number.
#if os(macOS)
XCTAssertEqual(uncapturedOutput, 437)
XCTAssertEqual(uncapturedOutput, 381)
#else
XCTAssertEqual(uncapturedOutput, 453)
XCTAssertEqual(uncapturedOutput, 397)
#endif
}

Expand Down Expand Up @@ -56,9 +56,9 @@ final class ParsingTests: XCTestCase {
// Update this magic number whenever `uncapturedOutput` is less than the current magic number.
// There's a regression whenever `uncapturedOutput` is greater than the current magic number.
#if os(macOS)
XCTAssertEqual(uncapturedOutput, 14922)
XCTAssertEqual(uncapturedOutput, 12938)
#else
XCTAssertEqual(uncapturedOutput, 15490)
XCTAssertEqual(uncapturedOutput, 13506)
#endif
}
}

0 comments on commit 316d0a8

Please sign in to comment.