From 1d53ff6b58851a195fafad7f840fd90a08dc3ce8 Mon Sep 17 00:00:00 2001 From: Charles Pisciotta Date: Sat, 22 Feb 2025 14:05:37 -0500 Subject: [PATCH] Add CompileAssetCatalogCaptureGroup --- Sources/XcbeautifyLib/CaptureGroups.swift | 20 +++++++++++++++++++ Sources/XcbeautifyLib/Formatter.swift | 2 ++ Sources/XcbeautifyLib/Parser.swift | 1 + .../Renderers/OutputRendering.swift | 7 +++++++ .../CaptureGroupTests.swift | 9 +++++++++ Tests/XcbeautifyLibTests/ParserTests.swift | 9 +++++++++ Tests/XcbeautifyLibTests/ParsingTests.swift | 8 ++++---- .../AzureDevOpsPipelinesRendererTests.swift | 5 +++++ .../GitHubActionsRendererTests.swift | 5 +++++ .../RendererTests/TeamCityRendererTests.swift | 5 +++++ .../RendererTests/TerminalRendererTests.swift | 5 +++++ 11 files changed, 72 insertions(+), 4 deletions(-) diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift index d77860a3..b94c6812 100644 --- a/Sources/XcbeautifyLib/CaptureGroups.swift +++ b/Sources/XcbeautifyLib/CaptureGroups.swift @@ -313,6 +313,26 @@ struct SwiftCompilingCaptureGroup: CaptureGroup { init?(groups: [String]) { } } +struct CompileAssetCatalogCaptureGroup: CaptureGroup { + static let outputType: OutputType = .task + + static var regex = XCRegex(pattern: #"^CompileAssetCatalog (.+) \(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 CompileCommandCaptureGroup: CaptureGroup { static let outputType: OutputType = .task diff --git a/Sources/XcbeautifyLib/Formatter.swift b/Sources/XcbeautifyLib/Formatter.swift index 493d06df..36eba9a0 100644 --- a/Sources/XcbeautifyLib/Formatter.swift +++ b/Sources/XcbeautifyLib/Formatter.swift @@ -58,6 +58,8 @@ package struct Formatter { return renderer.formatCompile(group: group) case let group as SwiftCompilingCaptureGroup: return renderer.formatSwiftCompiling(group: group) + case let group as CompileAssetCatalogCaptureGroup: + return renderer.formatCompileAssetCatalog(group: group) case let group as CompileCommandCaptureGroup: return renderer.formatCompileCommand(group: group) case let group as CompileErrorCaptureGroup: diff --git a/Sources/XcbeautifyLib/Parser.swift b/Sources/XcbeautifyLib/Parser.swift index 904eb103..3f939127 100644 --- a/Sources/XcbeautifyLib/Parser.swift +++ b/Sources/XcbeautifyLib/Parser.swift @@ -13,6 +13,7 @@ package final class Parser { CodesignFrameworkCaptureGroup.self, CodesignCaptureGroup.self, CompilationResultCaptureGroup.self, + CompileAssetCatalogCaptureGroup.self, CompileCaptureGroup.self, SwiftCompileCaptureGroup.self, SwiftCompilingCaptureGroup.self, diff --git a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift index b9b7c4de..763154c3 100644 --- a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift +++ b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift @@ -18,6 +18,7 @@ protocol OutputRendering { func formatCompile(group: any CompileFileCaptureGroup) -> String func formatCreateUniversalBinary(group: CreateUniversalBinaryCaptureGroup) -> String func formatSwiftCompiling(group: SwiftCompilingCaptureGroup) -> String? + func formatCompileAssetCatalog(group: CompileAssetCatalogCaptureGroup) -> String func formatCompileCommand(group: CompileCommandCaptureGroup) -> String? func formatCompileError(group: CompileErrorCaptureGroup) -> String func formatCompileXCStrings(group: CompileXCStringsCaptureGroup) -> String @@ -146,6 +147,12 @@ extension OutputRendering { return colored ? "[\(target.f.Cyan)] \("Compiling".s.Bold) \(filename)" : "[\(target)] Compiling \(filename)" } + func formatCompileAssetCatalog(group: CompileAssetCatalogCaptureGroup) -> String { + let filename = group.filename + let target = group.target + return colored ? "[\(target.f.Cyan)] \("Compile Asset Catalog".s.Bold) \(filename)" : "[\(target)] Compile Asset Catalog \(filename)" + } + func formatCompileCommand(group: CompileCommandCaptureGroup) -> String? { nil } diff --git a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift index eb52f5c8..156e88ca 100644 --- a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift +++ b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift @@ -27,6 +27,15 @@ final class CaptureGroupTests: XCTestCase { XCTAssertNotNil(CompilationResultCaptureGroup.regex.captureGroups(for: input)) } + func testMatchAssetCatalog() throws { + let input = #"CompileAssetCatalog /Backyard-Birds/Build/Products/Debug/LayeredArtworkLibrary_LayeredArtworkLibrary.bundle/Contents/Resources /Backyard-Birds/LayeredArtworkLibrary/Assets.xcassets (in target 'LayeredArtworkLibrary_LayeredArtworkLibrary' from project 'LayeredArtworkLibrary')"# + let groups = try XCTUnwrap(CompileAssetCatalogCaptureGroup.regex.captureGroups(for: input)) + XCTAssertEqual(groups.count, 3) + XCTAssertEqual(groups[0], "/Backyard-Birds/Build/Products/Debug/LayeredArtworkLibrary_LayeredArtworkLibrary.bundle/Contents/Resources /Backyard-Birds/LayeredArtworkLibrary/Assets.xcassets") + XCTAssertEqual(groups[1], "LayeredArtworkLibrary_LayeredArtworkLibrary") + XCTAssertEqual(groups[2], "LayeredArtworkLibrary") + } + 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)) diff --git a/Tests/XcbeautifyLibTests/ParserTests.swift b/Tests/XcbeautifyLibTests/ParserTests.swift index a3f2192f..89bf169e 100644 --- a/Tests/XcbeautifyLibTests/ParserTests.swift +++ b/Tests/XcbeautifyLibTests/ParserTests.swift @@ -21,6 +21,15 @@ final class ParserTests: XCTestCase { try super.tearDownWithError() } + func testMatchCompileAssetCatalog() throws { + let input = #"CompileAssetCatalog /Backyard-Birds/Build/Products/Debug/Widgets.appex/Contents/Resources /Backyard-Birds/Widgets/Assets.xcassets (in target 'Widgets' from project 'Backyard Birds')"# + let captureGroup = try XCTUnwrap(parser.parse(line: input) as? CompileAssetCatalogCaptureGroup) + XCTAssertEqual(captureGroup.filePath, "/Backyard-Birds/Build/Products/Debug/Widgets.appex/Contents/Resources /Backyard-Birds/Widgets/Assets.xcassets") + XCTAssertEqual(captureGroup.filename, "Assets.xcassets") + XCTAssertEqual(captureGroup.target, "Widgets") + XCTAssertEqual(captureGroup.project, "Backyard Birds") + } + 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) diff --git a/Tests/XcbeautifyLibTests/ParsingTests.swift b/Tests/XcbeautifyLibTests/ParsingTests.swift index 15bcaf9e..32051692 100644 --- a/Tests/XcbeautifyLibTests/ParsingTests.swift +++ b/Tests/XcbeautifyLibTests/ParsingTests.swift @@ -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, 68) + XCTAssertEqual(uncapturedOutput, 63) #else - XCTAssertEqual(uncapturedOutput, 84) + XCTAssertEqual(uncapturedOutput, 79) #endif } @@ -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, 2268) + XCTAssertEqual(uncapturedOutput, 2100) #else - XCTAssertEqual(uncapturedOutput, 2836) + XCTAssertEqual(uncapturedOutput, 2668) #endif } diff --git a/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift index a3211d7d..27a96473 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift @@ -94,6 +94,11 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase { XCTAssertEqual(formattedFramework, "Signing build/Release/MyFramework.framework") } + func testCompileAssetCatalog() { + let formatted = logFormatted(#"CompileAssetCatalog /Backyard-Birds/Build/Products/Debug/Backyard\ Birds.app/Contents/Resources /Backyard-Birds/Multiplatform/Assets.xcassets (in target 'Backyard Birds' from project 'Backyard Birds')"#) + XCTAssertEqual(formatted, "[Backyard Birds] Compile Asset Catalog Assets.xcassets") + } + func testCompileCommand() { } func testCompileError() { diff --git a/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift index f34e9825..b52eda19 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift @@ -106,6 +106,11 @@ final class GitHubActionsRendererTests: XCTestCase { #endif } + func testCompileAssetCatalog() { + let formatted = logFormatted(#"CompileAssetCatalog /Backyard-Birds/Build/Products/Debug/BackyardBirdsUI_BackyardBirdsUI.bundle/Contents/Resources /Backyard-Birds/BackyardBirdsUI/SomeAssets.xcassets (in target 'BackyardBirdsUI_BackyardBirdsUI' from project 'BackyardBirdsUI')"#) + XCTAssertEqual(formatted, "[BackyardBirdsUI_BackyardBirdsUI] Compile Asset Catalog SomeAssets.xcassets") + } + func testCreateBuildDirectory() { let formatted = logFormatted("CreateBuildDirectory /Backyard-Birds/Build/Products") XCTAssertNil(formatted) diff --git a/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift index 0d2d8c5a..4a9e4f14 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift @@ -109,6 +109,11 @@ final class TeamCityRendererTests: XCTestCase { #endif } + func testCompileAssetCatalog() { + let formatted = noColoredFormatted(#"CompileAssetCatalog /Backyard-Birds/Build/Products/Debug/LayeredArtworkLibrary_LayeredArtworkLibrary.bundle/Contents/Resources /Backyard-Birds/LayeredArtworkLibrary/AssetCatalog.xcassets (in target 'LayeredArtworkLibrary_LayeredArtworkLibrary' from project 'LayeredArtworkLibrary')"#) + XCTAssertEqual(formatted, "[LayeredArtworkLibrary_LayeredArtworkLibrary] Compile Asset Catalog AssetCatalog.xcassets") + } + func testCreateBuildDirectory() { let formatted = noColoredFormatted("CreateBuildDirectory /Backyard-Birds/Build/Intermediates.noindex/EagerLinkingTBDs/Debug") XCTAssertNil(formatted) diff --git a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift index 96d11a2d..6b5dd918 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift @@ -106,6 +106,11 @@ final class TerminalRendererTests: XCTestCase { #endif } + func testCompileAssetCatalog() { + let formatted = noColoredFormatted(#"CompileAssetCatalog /Backyard-Birds/Build/Products/Debug/Widgets.appex/Contents/Resources /Backyard-Birds/Widgets/AnAssetCatalog.xcassets (in target 'Widgets' from project 'Backyard Birds')"#) + XCTAssertEqual(formatted, "[Widgets] Compile Asset Catalog AnAssetCatalog.xcassets") + } + func testCreateBuildDirectory() { let formatted = noColoredFormatted("CreateBuildDirectory /Backyard-Birds/Build/Products/Debug/PackageFrameworks") XCTAssertNil(formatted)