|
13 | 13 | import Foundation
|
14 | 14 | import SKCore
|
15 | 15 |
|
| 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 | + |
16 | 27 | /// Create a folder that contains all files that should be necessary to reproduce a sourcekitd crash.
|
17 | 28 | /// - Parameters:
|
18 | 29 | /// - requestInfo: The reduced request info
|
@@ -47,14 +58,13 @@ func makeReproducerBundle(for requestInfo: RequestInfo, toolchain: Toolchain, bu
|
47 | 58 | )
|
48 | 59 | }
|
49 | 60 | 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 |
58 | 66 | }
|
| 67 | + let possiblePath = String(compilerArg[firstSlash...]) |
| 68 | + copyPathToBundleIfNecessary(possiblePath, bundlePath: bundlePath) |
59 | 69 | }
|
60 | 70 | }
|
0 commit comments