Skip to content

Commit fccf1eb

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 fccf1eb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Sources/Diagnose/ReproducerBundle.swift

Lines changed: 18 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,13 @@ 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+
// Find the first slash so we are also able to copy files from eg.
62+
// `-fmodule-map-file=/path/to/module.modulemap`
63+
// `-I/foo/bar`
64+
guard let firstSlash = compilerArg.firstIndex(of: "/") else {
65+
continue
5866
}
67+
let possiblePath = String(compilerArg[firstSlash...])
68+
copyPathToBundleIfNecessary(possiblePath, bundlePath: bundlePath)
5969
}
6070
}

0 commit comments

Comments
 (0)