Skip to content

Commit

Permalink
Add SwiftMergeGeneratedHeadersCaptureGroup (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta authored Jan 21, 2025
1 parent d5a29fc commit ec343c7
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 4 deletions.
23 changes: 23 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,29 @@ struct SwiftDriverJobDiscoveryCompilingCaptureGroup: CaptureGroup {
}
}

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

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

// TODO: Split this into String array after requiring macOS 13+
// Requires: https://github.com/cpisciotta/xcbeautify/issues/358
let headerFilePaths: String
let target: String
let project: String

init?(groups: [String]) {
assert(groups.count == 3)
guard let headerFilePaths = groups[safe: 0], let target = groups[safe: 1], let project = groups[safe: 2] else { return nil }
// TODO: Split headerFilePaths by non-escaped whitespace
// Requires: https://github.com/cpisciotta/xcbeautify/issues/358
// assert(headerFilePaths.allSatisfy { $0.hasSuffix(".h") })
self.headerFilePaths = headerFilePaths
self.target = target
self.project = project
}
}

struct SwiftTestingRunStartedCaptureGroup: CaptureGroup {
static let outputType: OutputType = .result

Expand Down
2 changes: 2 additions & 0 deletions Sources/XcbeautifyLib/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ package struct Formatter {
return renderer.formatSwiftDriverJobDiscoveryCompiling(group: group)
case let group as SwiftEmitModuleCaptureGroup:
return renderer.formatSwiftEmitModule(group: group)
case let group as SwiftMergeGeneratedHeadersCaptureGroup:
return renderer.formatSwiftMergeGeneratedHeaders(group: group)
case let group as TestingStartedCaptureGroup:
return renderer.formatTestingStarted(group: group)
case let group as SwiftTestingRunStartedCaptureGroup:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ package final class Parser {
TestSuiteAllTestsFailedCaptureGroup.self,
TestingStartedCaptureGroup.self,
SwiftEmitModuleCaptureGroup.self,
SwiftMergeGeneratedHeadersCaptureGroup.self,
SwiftTestingRunStartedCaptureGroup.self,
SwiftTestingRunCompletionCaptureGroup.self,
SwiftTestingRunFailedCaptureGroup.self,
Expand Down
5 changes: 5 additions & 0 deletions Sources/XcbeautifyLib/Renderers/OutputRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protocol OutputRendering {
func formatTestingStarted(group: TestingStartedCaptureGroup) -> String
func formatSwiftDriverJobDiscoveryCompiling(group: SwiftDriverJobDiscoveryCompilingCaptureGroup) -> String?
func formatSwiftEmitModule(group: SwiftEmitModuleCaptureGroup) -> String?
func formatSwiftMergeGeneratedHeaders(group: SwiftMergeGeneratedHeadersCaptureGroup) -> String?
func formatSwiftTestingRunStarted(group: SwiftTestingRunStartedCaptureGroup) -> String
func formatSwiftTestingRunCompletion(group: SwiftTestingRunCompletionCaptureGroup) -> String
func formatSwiftTestingRunFailed(group: SwiftTestingRunFailedCaptureGroup) -> String
Expand Down Expand Up @@ -621,6 +622,10 @@ extension OutputRendering {
nil
}

func formatSwiftMergeGeneratedHeaders(group: SwiftMergeGeneratedHeadersCaptureGroup) -> String? {
nil
}

func formatSwiftTestingRunStarted(group: SwiftTestingRunStartedCaptureGroup) -> String {
colored ? group.message.s.Bold : group.message
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ final class CaptureGroupTests: XCTestCase {
XCTAssertEqual(groups[2], "Project")
}

func testSwiftMergeGeneratedHeadersCaptureGroupCaptureGroup() throws {
let input = #"SwiftMergeGeneratedHeaders /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/DerivedSources/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/arm64/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds-Swift.h (in target 'Backyard Birds Target' from project 'Backyard Birds Project')"#
let groups = try XCTUnwrap(SwiftMergeGeneratedHeadersCaptureGroup.regex.captureGroups(for: input))
XCTAssertEqual(groups.count, 3)
XCTAssertEqual(groups[0], #"/Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/DerivedSources/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/arm64/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds-Swift.h"#)
XCTAssertEqual(groups[1], "Backyard Birds Target")
XCTAssertEqual(groups[2], "Backyard Birds Project")
}

func testUnindentedShellCommand() throws {
let input = #"/Applications/Xcode-16.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target arm64-apple-macos14.0 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -O0 -L/Backyard-Birds/Build/Intermediates.noindex/EagerLinkingTBDs/Debug -L/Backyard-Birds/Build/Products/Debug -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F/Backyard-Birds/Build/Intermediates.noindex/EagerLinkingTBDs/Debug -F/Backyard-Birds/Build/Products/Debug/PackageFrameworks -F/Backyard-Birds/Build/Products/Debug -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -filelist /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData\ product.build/Objects-normal/arm64/BackyardBirdsData.LinkFileList -install_name @rpath/BackyardBirdsData.framework/Versions/A/BackyardBirdsData -Xlinker -rpath -Xlinker /Backyard-Birds/Build/Products/Debug/PackageFrameworks -Xlinker -object_path_lto -Xlinker /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData\ product.build/Objects-normal/arm64/BackyardBirdsData_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Wl,-no_warn_duplicate_libraries -Xlinker -dependency_info -Xlinker /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData\ product.build/Objects-normal/arm64/BackyardBirdsData_dependency_info.dat -o /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData\ product.build/Objects-normal/arm64/Binary/BackyardBirdsData -Xlinker -add_ast_path -Xlinker /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData.build/Objects-normal/arm64/BackyardBirdsData.swiftmodule"#
let groups = try XCTUnwrap(NonPCHClangCommandCaptureGroup.regex.captureGroups(for: input))
Expand Down
8 changes: 8 additions & 0 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ final class ParserTests: XCTestCase {
XCTAssertEqual(captureGroup.target, "BackyardBirdsData")
}

func testMatchSwiftDriverJobDiscoveryCompilingCaptureGroup() throws {
let input = #"SwiftMergeGeneratedHeaders /Backyard-Birds/Build/Intermediates.noindex/GeneratedModuleMaps/LayeredArtworkLibrary-Swift.h /Backyard-Birds/Build/Intermediates.noindex/LayeredArtworkLibrary.build/Debug/LayeredArtworkLibrary.build/Objects-normal/arm64/LayeredArtworkLibrary-Swift.h /Backyard-Birds/Build/Intermediates.noindex/LayeredArtworkLibrary.build/Debug/LayeredArtworkLibrary.build/Objects-normal/x86_64/LayeredArtworkLibrary-Swift.h (in target 'LayeredArtworkLibraryTarget' from project 'LayeredArtworkLibraryProject')"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftMergeGeneratedHeadersCaptureGroup)
XCTAssertEqual(captureGroup.headerFilePaths, "/Backyard-Birds/Build/Intermediates.noindex/GeneratedModuleMaps/LayeredArtworkLibrary-Swift.h /Backyard-Birds/Build/Intermediates.noindex/LayeredArtworkLibrary.build/Debug/LayeredArtworkLibrary.build/Objects-normal/arm64/LayeredArtworkLibrary-Swift.h /Backyard-Birds/Build/Intermediates.noindex/LayeredArtworkLibrary.build/Debug/LayeredArtworkLibrary.build/Objects-normal/x86_64/LayeredArtworkLibrary-Swift.h")
XCTAssertEqual(captureGroup.target, "LayeredArtworkLibraryTarget")
XCTAssertEqual(captureGroup.project, "LayeredArtworkLibraryProject")
}

func testMatchExplicitDependency() throws {
let input = #" ➜ Explicit dependency on target 'BackyardBirdsData_BackyardBirdsData' in project 'Backyard Birds Data'"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? ExplicitDependencyCaptureGroup)
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, 172)
XCTAssertEqual(uncapturedOutput, 167)
#else
XCTAssertEqual(uncapturedOutput, 188)
XCTAssertEqual(uncapturedOutput, 183)
#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, 5700)
XCTAssertEqual(uncapturedOutput, 5520)
#else
XCTAssertEqual(uncapturedOutput, 6268)
XCTAssertEqual(uncapturedOutput, 6088)
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
XCTAssertEqual(formatted, #"[Target] Signing Some+File.o"#)
}

func testSwiftMergeGeneratedHeaders() {
let formatted = logFormatted(#"SwiftMergeGeneratedHeaders /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/DerivedSources/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/arm64/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds-Swift.h (in target 'Backyard Birds' from project 'Backyard Birds')"#)
XCTAssertNil(formatted)
}

func testSwiftTestingRunCompletion() {
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let formatted = logFormatted(input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ final class GitHubActionsRendererTests: XCTestCase {
XCTAssertEqual(formatted, #"[Target] Signing Some+File.o"#)
}

func testSwiftMergeGeneratedHeaders() {
let formatted = logFormatted(#"SwiftMergeGeneratedHeaders /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/DerivedSources/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/arm64/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds-Swift.h (in target 'Backyard Birds' from project 'Backyard Birds')"#)
XCTAssertNil(formatted)
}

func testSwiftTestingRunCompletion() {
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let formatted = logFormatted(input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ final class TeamCityRendererTests: XCTestCase {
XCTAssertEqual(formatted, #"[Target] Signing Some+File.o"#)
}

func testSwiftMergeGeneratedHeaders() {
let formatted = noColoredFormatted(#"SwiftMergeGeneratedHeaders /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/DerivedSources/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/arm64/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds-Swift.h (in target 'Backyard Birds' from project 'Backyard Birds')"#)
XCTAssertNil(formatted)
}

func testSymbolReferencedFrom() {
let formatted = noColoredFormatted(" \"NetworkBusiness.ImageDownloadManager.saveImage(image: __C.UIImage, needWatermark: Swift.Bool, params: [Swift.String : Any], downloadHandler: (Swift.Bool) -> ()?) -> ()\", referenced from:")
XCTAssertEqual(formatted, "[x] \"NetworkBusiness.ImageDownloadManager.saveImage(image: __C.UIImage, needWatermark: Swift.Bool, params: [Swift.String : Any], downloadHandler: (Swift.Bool) -> ()?) -> ()\", referenced from:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ final class TerminalRendererTests: XCTestCase {
XCTAssertEqual(formatted, #"[Target] Signing Some+File.o"#)
}

func testSwiftMergeGeneratedHeaders() {
let formatted = noColoredFormatted(#"SwiftMergeGeneratedHeaders /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/DerivedSources/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/arm64/Backyard_Birds-Swift.h /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds-Swift.h (in target 'Backyard Birds' from project 'Backyard Birds')"#)
XCTAssertNil(formatted)
}

func testSwiftTestingRunStarted() {
let input = #"􀟈 Test run started."#
let output = "Test run started."
Expand Down

0 comments on commit ec343c7

Please sign in to comment.