From 9677a005c1a5c83251bf1ed153d017ef0c1f2c9c Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 28 May 2024 14:35:15 -0700 Subject: [PATCH] Add paths from compiler arguments spelled with `=` to the diagnose bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eg. if the crash contained `-fmodule-map-file=/path/to/module.modulemap`, we weren’t including `/path/to/module.modulemap` in the diagnose bundle. --- Sources/Diagnose/ReproducerBundle.swift | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Sources/Diagnose/ReproducerBundle.swift b/Sources/Diagnose/ReproducerBundle.swift index 3095e6da6..c3f160214 100644 --- a/Sources/Diagnose/ReproducerBundle.swift +++ b/Sources/Diagnose/ReproducerBundle.swift @@ -47,14 +47,20 @@ func makeReproducerBundle(for requestInfo: RequestInfo, toolchain: Toolchain, bu ) } for compilerArg in requestInfo.compilerArgs { - // Copy all files from the compiler arguments into the reproducer bundle. - // Don't include files in Xcode (.app), Xcode toolchains or usr because they are most likely binary files that aren't user specific and would bloat the reproducer bundle. - if compilerArg.hasPrefix("/"), !compilerArg.contains(".app"), !compilerArg.contains(".xctoolchain"), - !compilerArg.contains("/usr/") - { - let dest = URL(fileURLWithPath: bundlePath.path + compilerArg) - try? FileManager.default.createDirectory(at: dest.deletingLastPathComponent(), withIntermediateDirectories: true) - try? FileManager.default.copyItem(at: URL(fileURLWithPath: compilerArg), to: dest) + // Find the first slash so we are also able to copy files from eg. + // `-fmodule-map-file=/path/to/module.modulemap` + // `-I/foo/bar` + guard let firstSlash = compilerArg.firstIndex(of: "/") else { + continue } + let path = compilerArg[firstSlash...] + guard !path.contains(".app"), !path.contains(".xctoolchain"), !path.contains("/usr/") else { + // Don't include files in Xcode (.app), Xcode toolchains or usr because they are most likely binary files that + // aren't user specific and would bloat the reproducer bundle. + continue + } + let dest = URL(fileURLWithPath: bundlePath.path + path) + try? FileManager.default.createDirectory(at: dest.deletingLastPathComponent(), withIntermediateDirectories: true) + try? FileManager.default.copyItem(at: URL(fileURLWithPath: String(path)), to: dest) } }