1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
//===--------------- SwiftModuleArtifacts.swift ---------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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
//
//===----------------------------------------------------------------------===//
/// Describes a given Swift module's pre-built module artifacts:
/// - Swift Module (name)
/// - Swift Module Path
/// - Swift Doc Path
/// - Swift Source Info Path
@_spi(Testing) public struct SwiftModuleArtifactInfo: Codable, Hashable {
/// The module's name
public let moduleName: String
/// The path for the module's .swiftmodule file
public let modulePath: TextualVirtualPath
/// The path for the module's .swiftdoc file
public let docPath: TextualVirtualPath?
/// The path for the module's .swiftsourceinfo file
public let sourceInfoPath: TextualVirtualPath?
/// Header dependencies of this module
public let prebuiltHeaderDependencyPaths: [TextualVirtualPath]?
/// A flag to indicate whether this module is a framework
public let isFramework: Bool
/// The cache key for the module.
public let moduleCacheKey: String?
init(name: String, modulePath: TextualVirtualPath, docPath: TextualVirtualPath? = nil,
sourceInfoPath: TextualVirtualPath? = nil, headerDependencies: [TextualVirtualPath]? = nil,
isFramework: Bool = false, moduleCacheKey: String? = nil) {
self.moduleName = name
self.modulePath = modulePath
self.docPath = docPath
self.sourceInfoPath = sourceInfoPath
self.prebuiltHeaderDependencyPaths = headerDependencies
self.isFramework = isFramework
self.moduleCacheKey = moduleCacheKey
}
}
/// Describes a given Clang module's pre-built module artifacts:
/// - Clang Module (name)
/// - Clang Module (PCM) Path
/// - Clang Module Map Path
@_spi(Testing) public struct ClangModuleArtifactInfo: Codable, Hashable {
/// The module's name
public let moduleName: String
/// The path for the module's .pcm file
public let clangModulePath: TextualVirtualPath
/// The path for this module's .modulemap file
public let clangModuleMapPath: TextualVirtualPath
/// A flag to indicate whether this module is a framework
public let isFramework: Bool
/// A flag to indicate whether this module is a dependency
/// of the main module's bridging header
public let isBridgingHeaderDependency: Bool
/// The cache key for the module.
public let clangModuleCacheKey: String?
init(name: String, modulePath: TextualVirtualPath, moduleMapPath: TextualVirtualPath,
moduleCacheKey: String? = nil, isBridgingHeaderDependency: Bool = true) {
self.moduleName = name
self.clangModulePath = modulePath
self.clangModuleMapPath = moduleMapPath
self.isFramework = false
self.isBridgingHeaderDependency = isBridgingHeaderDependency
self.clangModuleCacheKey = moduleCacheKey
}
}
@_spi(Testing) public enum ModuleDependencyArtifactInfo: Codable {
case clang(ClangModuleArtifactInfo)
case swift(SwiftModuleArtifactInfo)
@_spi(Testing) public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .swift(let swiftInfo):
try container.encode(swiftInfo)
case .clang(let clangInfo):
try container.encode(clangInfo)
}
}
@_spi(Testing) public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
do {
let thing = try container.decode(SwiftModuleArtifactInfo.self)
self = .swift(thing)
} catch {
let thing = try container.decode(ClangModuleArtifactInfo.self)
self = .clang(thing)
}
}
}
/// Describes a given module's batch dependency scanning input info
/// - Module Name
/// - Extra PCM build arguments (for Clang modules only)
/// - Dependency graph output path
public enum BatchScanModuleInfo: Encodable {
case swift(BatchScanSwiftModuleInfo)
case clang(BatchScanClangModuleInfo)
}
public struct BatchScanSwiftModuleInfo: Encodable {
var swiftModuleName: String
var output: String
init(moduleName: String, outputPath: String) {
self.swiftModuleName = moduleName
self.output = outputPath
}
}
public struct BatchScanClangModuleInfo: Encodable {
var clangModuleName: String
var arguments: String
var output: String
init(moduleName: String, pcmArgs: String, outputPath: String) {
self.clangModuleName = moduleName
self.arguments = pcmArgs
self.output = outputPath
}
}
public extension BatchScanModuleInfo {
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .swift(let swiftInfo):
try container.encode(swiftInfo)
case .clang(let clangInfo):
try container.encode(clangInfo)
}
}
}
extension SwiftModuleArtifactInfo: Comparable {
public static func < (lhs: SwiftModuleArtifactInfo, rhs: SwiftModuleArtifactInfo) -> Bool {
return lhs.moduleName < rhs.moduleName
}
}
extension ClangModuleArtifactInfo: Comparable {
public static func < (lhs: ClangModuleArtifactInfo, rhs: ClangModuleArtifactInfo) -> Bool {
return lhs.moduleName < rhs.moduleName
}
}
|