mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
To support -disable-implicit-swift-modules, the explicitly built modules are passed down as compiler arguments. We need this new module loader to handle these modules. This patch also stops ModuleInterfaceLoader from building module from interface when -disable-implicit-swift-modules is set.
49 lines
1.6 KiB
Swift
49 lines
1.6 KiB
Swift
//===--------------- BuildModulesFromGraph.swift --------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
import Foundation
|
|
|
|
let fileName = CommandLine.arguments[1]
|
|
let swiftPath = CommandLine.arguments[2]
|
|
let moduleName = CommandLine.arguments[3]
|
|
let data = try! Data(contentsOf: URL(fileURLWithPath: fileName))
|
|
|
|
let decoder = JSONDecoder()
|
|
let moduleDependencyGraph = try! decoder.decode(
|
|
ModuleDependencyGraph.self, from: data)
|
|
|
|
func findModuleBuildingCommand(_ moduleName: String) -> [String]? {
|
|
for (_, dep) in moduleDependencyGraph.modules {
|
|
if URL(fileURLWithPath: dep.modulePath).lastPathComponent == moduleName {
|
|
switch dep.details {
|
|
case .swift(let details):
|
|
return details.commandLine
|
|
case .clang(let details):
|
|
return details.commandLine
|
|
}
|
|
} else {
|
|
continue
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
if let command = findModuleBuildingCommand(moduleName) {
|
|
var result = swiftPath
|
|
command.forEach { result += " \($0)"}
|
|
// Pass down additional args to the Swift invocation.
|
|
CommandLine.arguments.dropFirst(4).forEach { result += " \($0)"}
|
|
print(result)
|
|
exit(0)
|
|
} else {
|
|
fatalError("cannot find module building commands for \(moduleName)")
|
|
}
|