Skip to content

Commit 9967641

Browse files
committed
Add paths from compiler arguments spelled with = to the diagnose bundle
Eg. if the crash contained `-fmodule-map-file=/path/to/module.modulemap`, we weren’t including `/path/to/module.modulemap` in the diagnose bundle.
1 parent 715796f commit 9967641

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Sources/Diagnose/ReproducerBundle.swift

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
import Foundation
1414
import SKCore
1515

16+
private func copyPathToBundleIfNecessary(_ path: String, bundlePath: URL) {
17+
guard !path.contains(".app"), !path.contains(".xctoolchain"), !path.contains("/usr/") else {
18+
// Don't include files in Xcode (.app), Xcode toolchains or usr because they are most likely binary files that
19+
// aren't user specific and would bloat the reproducer bundle.
20+
return
21+
}
22+
let dest = URL(fileURLWithPath: bundlePath.path + path)
23+
try? FileManager.default.createDirectory(at: dest.deletingLastPathComponent(), withIntermediateDirectories: true)
24+
try? FileManager.default.copyItem(at: URL(fileURLWithPath: path), to: dest)
25+
}
26+
1627
/// Create a folder that contains all files that should be necessary to reproduce a sourcekitd crash.
1728
/// - Parameters:
1829
/// - requestInfo: The reduced request info
@@ -47,14 +58,14 @@ func makeReproducerBundle(for requestInfo: RequestInfo, toolchain: Toolchain, bu
4758
)
4859
}
4960
for compilerArg in requestInfo.compilerArgs {
50-
// Copy all files from the compiler arguments into the reproducer bundle.
51-
// 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.
52-
if compilerArg.hasPrefix("/"), !compilerArg.contains(".app"), !compilerArg.contains(".xctoolchain"),
53-
!compilerArg.contains("/usr/")
54-
{
55-
let dest = URL(fileURLWithPath: bundlePath.path + compilerArg)
56-
try? FileManager.default.createDirectory(at: dest.deletingLastPathComponent(), withIntermediateDirectories: true)
57-
try? FileManager.default.copyItem(at: URL(fileURLWithPath: compilerArg), to: dest)
61+
if compilerArg.hasPrefix("/") {
62+
copyPathToBundleIfNecessary(compilerArg, bundlePath: bundlePath)
63+
} else if let firstEqual = compilerArg.firstIndex(of: "=") {
64+
// Copy files from eg. `-fmodule-map-file=/path/to/module.modulemap`
65+
let possiblePath = String(compilerArg[compilerArg.index(after: firstEqual)...])
66+
if possiblePath.hasPrefix("/") {
67+
copyPathToBundleIfNecessary(possiblePath, bundlePath: bundlePath)
68+
}
5869
}
5970
}
6071
}

0 commit comments

Comments
 (0)