|
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,14 @@ 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 | + 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 | + } |
58 | 69 | }
|
59 | 70 | }
|
60 | 71 | }
|
0 commit comments