Files
swift-mirror/test/ScanDependencies/Inputs/BuildModulesFromGraph.swift
Xi Ge bd782be654 Front-end: add a new module loader that loads explicitly built Swift modules
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.
2020-06-03 18:59:18 -07:00

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)")
}