Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CompileXCStringsCaptureGroup #363

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ struct CompileCommandCaptureGroup: CaptureGroup {
}
}

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

static let regex = XCRegex(pattern: #"^CompileXCStrings (.+) \(in target '(.+)' from project '(.+)'\)$"#)

let filePath: String
let filename: String
let target: String
let project: String

init?(groups: [String]) {
assert(groups.count == 3)
guard let filePath = groups[safe: 0], let target = groups[safe: 1], let project = groups[safe: 2] else { return nil }
self.filePath = filePath
filename = filePath.lastPathComponent
self.target = target
self.project = project
}
}

struct CompileXibCaptureGroup: CompileFileCaptureGroup {
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 @@ -66,6 +66,8 @@ package struct Formatter {
return renderer.formatCompile(group: group)
case let group as CompileWarningCaptureGroup:
return renderer.formatCompileWarning(group: group)
case let group as CompileXCStringsCaptureGroup:
return renderer.formatCompileXCStrings(group: group)
case let group as CompileXibCaptureGroup:
return renderer.formatCompile(group: group)
case let group as CopyFilesCaptureGroup:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package final class Parser {
SwiftCompileCaptureGroup.self,
SwiftCompilingCaptureGroup.self,
CompileCommandCaptureGroup.self,
CompileXCStringsCaptureGroup.self,
CompileXibCaptureGroup.self,
CompileStoryboardCaptureGroup.self,
CopyFilesCaptureGroup.self,
Expand Down
7 changes: 7 additions & 0 deletions Sources/XcbeautifyLib/Renderers/OutputRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protocol OutputRendering {
func formatSwiftCompiling(group: SwiftCompilingCaptureGroup) -> String?
func formatCompileCommand(group: CompileCommandCaptureGroup) -> String?
func formatCompileError(group: CompileErrorCaptureGroup) -> String
func formatCompileXCStrings(group: CompileXCStringsCaptureGroup) -> String
func formatCompileWarning(group: CompileWarningCaptureGroup) -> String
func formatCopy(group: any CopyCaptureGroup) -> String
func formatCopyFiles(group: CopyFilesCaptureGroup) -> String
Expand Down Expand Up @@ -149,6 +150,12 @@ extension OutputRendering {
nil
}

func formatCompileXCStrings(group: CompileXCStringsCaptureGroup) -> String {
let filename = group.filename
let target = group.target
return colored ? "[\(target.f.Cyan)] \("Compile XCStrings".s.Bold) \(filename)" : "[\(target)] Compile XCStrings \(filename)"
}

func formatCompilationResult(group: CompilationResultCaptureGroup) -> String? {
nil
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ final class CaptureGroupTests: XCTestCase {
XCTAssertNotNil(CompilationResultCaptureGroup.regex.captureGroups(for: input))
}

func testMatchCompileXCStrings() throws {
let input = #"CompileXCStrings /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings (in target 'BackyardBirdsData_BackyardBirdsData' from project 'BackyardBirdsData')"#
let groups = try XCTUnwrap(CompileXCStringsCaptureGroup.regex.captureGroups(for: input))
XCTAssertEqual(groups.count, 3)
XCTAssertEqual(groups[0], "/Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings")
XCTAssertEqual(groups[1], "BackyardBirdsData_BackyardBirdsData")
XCTAssertEqual(groups[2], "BackyardBirdsData")
}

func testMatchCreateUniversalBinary() throws {
let input = #"CreateUniversalBinary /Backyard-Birds/Build/Products/Debug/BackyardBirdsData.o normal arm64\ x86_64 (in target 'BackyardBirdsDataTarget' from project 'BackyardBirdsDataProject')"#
let groups = try XCTUnwrap(CreateUniversalBinaryCaptureGroup.regex.captureGroups(for: input))
Expand Down
9 changes: 9 additions & 0 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ final class ParserTests: XCTestCase {
try super.tearDownWithError()
}

func testMatchCompileXCStrings() throws {
let input = #"CompileXCStrings /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings (in target 'BackyardBirdsData_BackyardBirdsData' from project 'BackyardBirdsData')"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? CompileXCStringsCaptureGroup)
XCTAssertEqual(captureGroup.filePath, "/Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings")
XCTAssertEqual(captureGroup.filename, "Backyards.xcstrings")
XCTAssertEqual(captureGroup.target, "BackyardBirdsData_BackyardBirdsData")
XCTAssertEqual(captureGroup.project, "BackyardBirdsData")
}

func testMatchCopyFilesMatchingSourceAndDestinationFilenames() throws {
let input = #"Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? CopyFilesCaptureGroup)
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, 159)
XCTAssertEqual(uncapturedOutput, 150)
#else
XCTAssertEqual(uncapturedOutput, 175)
XCTAssertEqual(uncapturedOutput, 166)
#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, 5240)
XCTAssertEqual(uncapturedOutput, 4944)
#else
XCTAssertEqual(uncapturedOutput, 5808)
XCTAssertEqual(uncapturedOutput, 5512)
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
XCTAssertEqual(logFormatted(input), output)
}

func testCompileXCStrings() {
let formatted = logFormatted(#"CompileXCStrings /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings (in target 'BackyardBirdsData_BackyardBirdsData' from project 'BackyardBirdsData')"#)
XCTAssertEqual(formatted, "[BackyardBirdsData_BackyardBirdsData] Compile XCStrings Backyards.xcstrings")
}

func testCompileXib() {
let input = "CompileXIB /path/file.xib (in target 'MyApp' from project 'MyProject')"
let output = "[MyApp] Compiling file.xib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ final class GitHubActionsRendererTests: XCTestCase {
XCTAssertEqual(logFormatted(input), output)
}

func testCompileXCStrings() {
let formatted = logFormatted(#"CompileXCStrings /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings (in target 'BackyardBirdsData_BackyardBirdsData' from project 'BackyardBirdsData')"#)
XCTAssertEqual(formatted, "[BackyardBirdsData_BackyardBirdsData] Compile XCStrings Backyards.xcstrings")
}

func testCompileXib() {
let input = "CompileXIB /path/file.xib (in target 'MyApp' from project 'MyProject')"
let output = "[MyApp] Compiling file.xib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ final class TeamCityRendererTests: XCTestCase {
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCompileXCStrings() {
let formatted = noColoredFormatted(#"CompileXCStrings /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings (in target 'BackyardBirdsData_BackyardBirdsData' from project 'BackyardBirdsData')"#)
XCTAssertEqual(formatted, "[BackyardBirdsData_BackyardBirdsData] Compile XCStrings Backyards.xcstrings")
}

func testCompileXib() {
let input = "CompileXIB /path/file.xib (in target 'MyApp' from project 'MyProject')"
let output = "[MyApp] Compiling file.xib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ final class TerminalRendererTests: XCTestCase {
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCompileXCStrings() {
let formatted = noColoredFormatted(#"CompileXCStrings /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData_BackyardBirdsData.build/ /Backyard-Birds/BackyardBirdsData/Backyards/Backyards.xcstrings (in target 'BackyardBirdsData_BackyardBirdsData' from project 'BackyardBirdsData')"#)
XCTAssertEqual(formatted, "[BackyardBirdsData_BackyardBirdsData] Compile XCStrings Backyards.xcstrings")
}

func testCompileXib() {
let input = "CompileXIB /path/file.xib (in target 'MyApp' from project 'MyProject')"
let output = "[MyApp] Compiling file.xib"
Expand Down