|
12 | 12 |
|
13 | 13 | import TSCBasic
|
14 | 14 | import SwiftOptions
|
| 15 | +import Foundation |
15 | 16 |
|
16 | 17 | public enum PlanningError: Error, DiagnosticData {
|
17 | 18 | case replReceivedInput
|
@@ -438,6 +439,46 @@ extension Driver {
|
438 | 439 | return try mergeModuleJob(inputs: moduleInputs, inputsFromOutputs: moduleInputsFromJobOutputs)
|
439 | 440 | }
|
440 | 441 |
|
| 442 | + func getAdopterConfigPathFromXcodeDefaultToolchain() -> AbsolutePath? { |
| 443 | + let swiftPath = try? toolchain.resolvedTool(.swiftCompiler).path |
| 444 | + guard var swiftPath = swiftPath else { |
| 445 | + return nil |
| 446 | + } |
| 447 | + let toolchains = "Toolchains" |
| 448 | + guard swiftPath.components.contains(toolchains) else { |
| 449 | + return nil |
| 450 | + } |
| 451 | + while swiftPath.basename != toolchains { |
| 452 | + swiftPath = swiftPath.parentDirectory |
| 453 | + } |
| 454 | + assert(swiftPath.basename == toolchains) |
| 455 | + return swiftPath.appending(component: "XcodeDefault.xctoolchain") |
| 456 | + .appending(component: "usr") |
| 457 | + .appending(component: "local") |
| 458 | + .appending(component: "lib") |
| 459 | + .appending(component: "swift") |
| 460 | + .appending(component: "adopter_configs.json") |
| 461 | + } |
| 462 | + |
| 463 | + @_spi(Testing) public struct AdopterConfig: Decodable { |
| 464 | + public let key: String |
| 465 | + public let moduleNames: [String] |
| 466 | + } |
| 467 | + |
| 468 | + @_spi(Testing) public static func parseAdopterConfigs(_ config: AbsolutePath) -> [AdopterConfig] { |
| 469 | + let results = try? localFileSystem.readFileContents(config).withData { |
| 470 | + try JSONDecoder().decode([AdopterConfig].self, from: $0) |
| 471 | + } |
| 472 | + return results ?? [] |
| 473 | + } |
| 474 | + |
| 475 | + func getAdopterConfigsFromXcodeDefaultToolchain() -> [AdopterConfig] { |
| 476 | + if let config = getAdopterConfigPathFromXcodeDefaultToolchain() { |
| 477 | + return Driver.parseAdopterConfigs(config) |
| 478 | + } |
| 479 | + return [] |
| 480 | + } |
| 481 | + |
441 | 482 | private mutating func addVerifyJobs(emitModuleJob: Job, addJob: (Job) -> Void )
|
442 | 483 | throws {
|
443 | 484 | // Turn this flag on by default with the env var or for public frameworks.
|
|
0 commit comments