Repository: cpisciotta/xcbeautify (swift)

Issue:
ProcessPCH and ProcessPCH++ patterns are too strict
Not all precompile headers necessarily end in the `.pch` suffix.

For example, precompiled headers generated by CMake are of the form `cmake_pch.h|xx` (https://cmake.org/cmake/help/latest/command/target_precompile_headers.html)

For a pure ObjC CMake target, the generated PCH could also be `cmake_pch.objc.h`

This causes the ProcessPCH line to get swallowed, which is unfortunate especially for projects with large precompiled headers that take a while to compile

Pull request:
Fixes #74

Patch:
diff --git a/Sources/XcbeautifyLib/Pattern.swift b/Sources/XcbeautifyLib/Pattern.swift
index b733669f..81744226 100644
--- a/Sources/XcbeautifyLib/Pattern.swift
+++ b/Sources/XcbeautifyLib/Pattern.swift
@@ -239,11 +239,11 @@ enum Pattern: String {
     /// Regular expression captured groups:
     /// $1 = file
     /// $2 = build target
-    case processPch = #"ProcessPCH(?:\+\+)?\s.*\s\/.*\/(.*.pch) normal .* .* .* \((in target: (.*)|in target '(.*)' from project '.*')\)"#
+    case processPch = #"ProcessPCH(?:\+\+)?\s.*\s\/.*\/(.*) normal .* .* .* \((in target: (.*)|in target '(.*)' from project '.*')\)"#
 
     /// Regular expression captured groups:
     /// $1 file path
-    case processPchCommand = #"\s*.*\/usr\/bin\/clang\s.*\s\-c\s(.*.pch)\s.*\-o\s.*"#
+    case processPchCommand = #"\s*.*\/usr\/bin\/clang\s.*\s\-c\s(.*?)(?<!\\)\s.*\-o\s.*\.gch"#
 
     /// Regular expression captured groups:
     /// $1 = file


Test patch:
diff --git a/Tests/XcbeautifyLibTests/XcbeautifyLibTests.swift b/Tests/XcbeautifyLibTests/XcbeautifyLibTests.swift
index 6142a9bb..7ce4a727 100644
--- a/Tests/XcbeautifyLibTests/XcbeautifyLibTests.swift
+++ b/Tests/XcbeautifyLibTests/XcbeautifyLibTests.swift
@@ -357,11 +357,21 @@ final class XcbeautifyLibTests: XCTestCase {
         XCTAssertEqual(formatted, "Preprocessing /path/to/my.pch")
     }
 
+    func testProcessPchCommandArbitraryExtension() {
+        let formatted = noColoredFormatted(#"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++-header -target x86_64-apple-macos12.3 -c /path/with\ space/cmake_pch.hxx -o /path/with\ space/build/SharedPrecompiledHeaders/SharedPrecompiledHeaders/2304651503107189736/cmake_pch.hxx.gch --serialize-diagnostics /path/with\ space/build/SharedPrecompiledHeaders/SharedPrecompiledHeaders/2304651503107189736/cmake_pch.hxx.dia"#)
+        XCTAssertEqual(formatted, #"Preprocessing /path/with\ space/cmake_pch.hxx"#)
+    }
+
     func testProcessPch() {
         let formatted = noColoredFormatted("ProcessPCH /Users/admin/Library/Developer/Xcode/DerivedData/Lumberjack-abcd/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/5872309797734264511/CocoaLumberjack-Prefix.pch.gch /Users/admin/CocoaLumberjack/Framework/Lumberjack/CocoaLumberjack-Prefix.pch normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.analyzer (in target: CocoaLumberjack)")
         XCTAssertEqual(formatted, "[CocoaLumberjack] Processing CocoaLumberjack-Prefix.pch")
     }
 
+    func testProcessPchArbitraryExtension() {
+        let formatted = noColoredFormatted(#"ProcessPCH++ /Users/admin/src/Test\ Folder/_builds/SharedPrecompiledHeaders/SharedPrecompiledHeaders/2304651503107189736/cmake_pch.hxx.gch /Users/admin/src/Test\ Folder/_builds/CMakeFiles/foo.dir/Debug/cmake_pch.hxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'foo' from project 'foo')"#)
+        XCTAssertEqual(formatted, "[foo] Processing cmake_pch.hxx")
+    }
+
     func testProcessPchPlusPlus() {
         let formatted = noColoredFormatted("ProcessPCH++ /Users/admin/Library/Developer/Xcode/DerivedData/Lumberjack-abcd/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/5872309797734264511/CocoaLumberjack-Prefix.pch.gch /Users/admin/CocoaLumberjack/Framework/Lumberjack/CocoaLumberjack-Prefix.pch normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.analyzer (in target: CocoaLumberjack)")
         XCTAssertEqual(formatted, "[CocoaLumberjack] Processing CocoaLumberjack-Prefix.pch")