Skip to content

Commit

Permalink
Add CompileAssetCatalogCaptureGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta committed Feb 22, 2025
1 parent b5f4f3f commit eb263e2
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 4 deletions.
20 changes: 20 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Sources/XcbeautifyLib/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package final class Parser {
CodesignFrameworkCaptureGroup.self,
CodesignCaptureGroup.self,
CompilationResultCaptureGroup.self,
CompileAssetCatalogCaptureGroup.self,
CompileCaptureGroup.self,
SwiftCompileCaptureGroup.self,
SwiftCompilingCaptureGroup.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 @@ -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
Expand Down Expand Up @@ -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
}
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 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))
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 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)
Expand Down
8 changes: 4 additions & 4 deletions Tests/XcbeautifyLibTests/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, 68)
XCTAssertEqual(uncapturedOutput, 63)
#else
XCTAssertEqual(uncapturedOutput, 84)
XCTAssertEqual(uncapturedOutput, 79)
#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, 2268)
XCTAssertEqual(uncapturedOutput, 2100)
#else
XCTAssertEqual(uncapturedOutput, 2836)
XCTAssertEqual(uncapturedOutput, 2668)
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "[BackyardBirdsData_BackyardBirdsData] Assets.xcassets")
}

func testCompileCommand() { }

func testCompileError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] SomeAssets.xcassets")
}

func testCreateBuildDirectory() {
let formatted = logFormatted("CreateBuildDirectory /Backyard-Birds/Build/Products")
XCTAssertNil(formatted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] AssetCatalog.xcassets")
}

func testCreateBuildDirectory() {
let formatted = noColoredFormatted("CreateBuildDirectory /Backyard-Birds/Build/Intermediates.noindex/EagerLinkingTBDs/Debug")
XCTAssertNil(formatted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] AnAssetCatalog.xcassets")
}

func testCreateBuildDirectory() {
let formatted = noColoredFormatted("CreateBuildDirectory /Backyard-Birds/Build/Products/Debug/PackageFrameworks")
XCTAssertNil(formatted)
Expand Down

0 comments on commit eb263e2

Please sign in to comment.