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

Capture Unindented Clang Commands #333

Merged
merged 1 commit into from
Dec 21, 2024
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
17 changes: 17 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ struct ShellCommandCaptureGroup: CaptureGroup {
}
}

// FIXME: Refactor this type.
// Added to temporarily capture unwanted clang output.
// This type's regex conflicts with ShellCommandCaptureGroup and ProcessPchCommandCaptureGroup.
struct NonPCHClangCommandCaptureGroup: CaptureGroup {
static let outputType: OutputType = .task

static let regex = XCRegex(pattern: #"^\s{0,4}(.*\/usr\/bin\/clang) (?:(?!(?:pch)).)*$"#)

let xcodePath: String

init?(groups: [String]) {
assert(groups.count == 1)
guard let xcodePath = groups[safe: 0] else { return nil }
self.xcodePath = xcodePath
}
}

struct CleanRemoveCaptureGroup: 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 @@ -38,6 +38,8 @@ package struct Formatter {
return renderer.formatCheckDependencies()
case let group as CheckDependenciesErrorsCaptureGroup:
return renderer.formatError(group: group)
case let group as NonPCHClangCommandCaptureGroup:
return renderer.formatNonPCHClangCommand(group: group)
case let group as ClangErrorCaptureGroup:
return renderer.formatError(group: group)
case let group as CleanRemoveCaptureGroup:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ package final class Parser {
SwiftDriverCompilationTarget.self,
SwiftDriverCompilationRequirementsCaptureGroup.self,
MkDirCaptureGroup.self,
NonPCHClangCommandCaptureGroup.self,
]

// MARK: - Init
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 @@ -40,6 +40,7 @@ protocol OutputRendering {
func formatLinkerUndefinedSymbolLocation(group: LinkerUndefinedSymbolLocationCaptureGroup) -> String?
func formatLinkerUndefinedSymbolsError(group: LinkerUndefinedSymbolsCaptureGroup) -> String
func formatLinking(group: LinkingCaptureGroup) -> String
func formatNonPCHClangCommand(group: NonPCHClangCommandCaptureGroup) -> String?
func formatPackageCheckingOut(group: PackageCheckingOutCaptureGroup) -> String
func formatPackageEnd() -> String
func formatPackageFetching(group: PackageFetchingCaptureGroup) -> String
Expand Down Expand Up @@ -216,6 +217,10 @@ extension OutputRendering {
#endif
}

func formatNonPCHClangCommand(group: NonPCHClangCommandCaptureGroup) -> String? {
nil
}

func formatPackageCheckingOut(group: PackageCheckingOutCaptureGroup) -> String {
let version = group.version
let package = group.package
Expand Down
14 changes: 14 additions & 0 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ final class CaptureGroupTests: XCTestCase {
let input = "MkDir /Backyard-Birds/Build/Products/Debug/Widgets.appex/Contents (in target \'Widgets\' from project \'Backyard Birds\')"
XCTAssertNotNil(MkDirCaptureGroup.regex.captureGroups(for: input))
}

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))
XCTAssertEqual(groups.count, 1)
XCTAssertEqual(groups[0], "/Applications/Xcode-16.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang")
}

func testIndentedShellCommand() throws {
let input = #" /Applications/Xcode.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))
XCTAssertEqual(groups.count, 1)
XCTAssertEqual(groups[0], "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang")
}
}
Loading