|
| 1 | +//===------------------ FullDependencies.h - Swift Compiler ---------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_DEPENDENCY_FULL_DEPENDENCIES_H |
| 14 | +#define SWIFT_DEPENDENCY_FULL_DEPENDENCIES_H |
| 15 | + |
| 16 | +#include "swift/AST/ModuleDependencies.h" |
| 17 | +#include <set> |
| 18 | +#include <string> |
| 19 | +#include <unordered_map> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +// This file describes the format for in-memory dependency scanning result |
| 23 | +// produced by the Swift dependency scanner. |
| 24 | + |
| 25 | +namespace swift { |
| 26 | +namespace dependencies { |
| 27 | + |
| 28 | +/// Swift modules to be built from a module interface, may have a bridging |
| 29 | +/// header. |
| 30 | +struct SwiftTextualModuleDetails { |
| 31 | + /// The module interface from which this module was built, if any. |
| 32 | + std::string ModuleInterfacePath; |
| 33 | + |
| 34 | + /// The paths of potentially ready-to-use compiled modules for the interface. |
| 35 | + std::vector<std::string> CompiledModuleCandidates; |
| 36 | + |
| 37 | + /// The bridging header, if any. |
| 38 | + std::string BridgingHeaderPath; |
| 39 | + |
| 40 | + /// The source files referenced by the bridging header. |
| 41 | + std::vector<std::string> BridgingSourceFiles; |
| 42 | + |
| 43 | + /// (Clang) modules on which the bridging header depends. |
| 44 | + std::vector<std::string> BridgingModuleDependencies; |
| 45 | + |
| 46 | + /// Options to the compile command required to build this module interface |
| 47 | + std::vector<std::string> CommandLine; |
| 48 | + |
| 49 | + /// To build a PCM to be used by this Swift module, we need to append these |
| 50 | + /// arguments to the generic PCM build arguments reported from the dependency |
| 51 | + /// graph. |
| 52 | + std::vector<std::string> ExtraPcmArgs; |
| 53 | + |
| 54 | + /// The hash value that will be used for the generated module |
| 55 | + std::string ContextHash; |
| 56 | + |
| 57 | + /// A flag to indicate whether or not this module is a framework. |
| 58 | + bool IsFramework = false; |
| 59 | +}; |
| 60 | + |
| 61 | +/// Swift modules with only a binary module file. |
| 62 | +struct SwiftBinaryModuleDetails { |
| 63 | + /// The path to the pre-compiled binary module |
| 64 | + std::string CompiledModulePath; |
| 65 | + |
| 66 | + /// The path to the .swiftModuleDoc file. |
| 67 | + std::string ModuleDocPath; |
| 68 | + |
| 69 | + /// The path to the .swiftSourceInfo file. |
| 70 | + std::string ModuleSourceInfoPath; |
| 71 | +}; |
| 72 | + |
| 73 | +/// Swift placeholder modules carry additional details that specify their |
| 74 | +/// module doc path and source info paths. |
| 75 | +struct SwiftPlaceholderModuleDetails { |
| 76 | + /// The path to the pre-compiled binary module |
| 77 | + std::string CompiledModulePath; |
| 78 | + |
| 79 | + /// The path to the .swiftModuleDoc file. |
| 80 | + std::string ModuleDocPath; |
| 81 | + |
| 82 | + /// The path to the .swiftSourceInfo file. |
| 83 | + std::string ModuleSourceInfoPath; |
| 84 | +}; |
| 85 | + |
| 86 | +/// Clang modules are built from a module map file. |
| 87 | +struct ClangModuleDetails { |
| 88 | + /// The path to the module map used to build this module. |
| 89 | + std::string ModuleMapPath; |
| 90 | + |
| 91 | + /// Set of PCM Arguments of depending modules which |
| 92 | + /// are covered by the directDependencies info of this module |
| 93 | + // TODO: Should this be modeled here or in the clients? |
| 94 | + // const std::set<std::string> DependenciesCapturedPCMArgs; |
| 95 | + |
| 96 | + /// clang-generated context hash |
| 97 | + std::string ContextHash; |
| 98 | + |
| 99 | + /// Options to the compile command required to build this clang modulemap |
| 100 | + std::vector<std::string> CommandLine; |
| 101 | +}; |
| 102 | + |
| 103 | +struct ModuleDetails { |
| 104 | + ModuleDetails(SwiftTextualModuleDetails Details) |
| 105 | + : DetailsKind(ModuleDependenciesKind::SwiftTextual), Value(Details) {} |
| 106 | + ModuleDetails(SwiftBinaryModuleDetails Details) |
| 107 | + : DetailsKind(ModuleDependenciesKind::SwiftBinary), Value(Details) {} |
| 108 | + ModuleDetails(SwiftPlaceholderModuleDetails Details) |
| 109 | + : DetailsKind(ModuleDependenciesKind::SwiftPlaceholder), Value(Details) {} |
| 110 | + ModuleDetails(ClangModuleDetails Details) |
| 111 | + : DetailsKind(ModuleDependenciesKind::Clang), Value(Details) {} |
| 112 | + |
| 113 | + ~ModuleDetails() { |
| 114 | + switch (DetailsKind) { |
| 115 | + case ModuleDependenciesKind::SwiftTextual: |
| 116 | + (&Value.TextualDetails)->~SwiftTextualModuleDetails(); |
| 117 | + break; |
| 118 | + case ModuleDependenciesKind::SwiftBinary: |
| 119 | + (&Value.BinaryDetails)->~SwiftBinaryModuleDetails(); |
| 120 | + break; |
| 121 | + case ModuleDependenciesKind::SwiftPlaceholder: |
| 122 | + (&Value.PlaceholderDetails)->~SwiftPlaceholderModuleDetails(); |
| 123 | + break; |
| 124 | + case ModuleDependenciesKind::Clang: |
| 125 | + (&Value.ClangDetails)->~ClangModuleDetails(); |
| 126 | + break; |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + ModuleDetails(const ModuleDetails &src) : |
| 131 | + DetailsKind(src.DetailsKind) { |
| 132 | + switch (src.DetailsKind) { |
| 133 | + case ModuleDependenciesKind::SwiftBinary: |
| 134 | + new (&Value.BinaryDetails) auto(src.Value.BinaryDetails); |
| 135 | + break; |
| 136 | + case ModuleDependenciesKind::SwiftTextual: |
| 137 | + new (&Value.TextualDetails) auto(src.Value.TextualDetails); |
| 138 | + break; |
| 139 | + case ModuleDependenciesKind::SwiftPlaceholder: |
| 140 | + new (&Value.PlaceholderDetails) auto(src.Value.PlaceholderDetails); |
| 141 | + break; |
| 142 | + case ModuleDependenciesKind::Clang: |
| 143 | + new (&Value.ClangDetails) auto(src.Value.ClangDetails); |
| 144 | + break; |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + const SwiftTextualModuleDetails *getAsSwiftTextualModule() const { |
| 149 | + return DetailsKind == ModuleDependenciesKind::SwiftTextual |
| 150 | + ? &Value.TextualDetails |
| 151 | + : nullptr; |
| 152 | + } |
| 153 | + const SwiftPlaceholderModuleDetails * |
| 154 | + getAsPlaceholderDependencyModule() const { |
| 155 | + return DetailsKind == ModuleDependenciesKind::SwiftPlaceholder |
| 156 | + ? &Value.PlaceholderDetails |
| 157 | + : nullptr; |
| 158 | + } |
| 159 | + const SwiftBinaryModuleDetails *getAsSwiftBinaryModule() const { |
| 160 | + return DetailsKind == ModuleDependenciesKind::SwiftBinary |
| 161 | + ? &Value.BinaryDetails |
| 162 | + : nullptr; |
| 163 | + } |
| 164 | + const ClangModuleDetails *getAsClangModule() const { |
| 165 | + return DetailsKind == ModuleDependenciesKind::Clang ? &Value.ClangDetails |
| 166 | + : nullptr; |
| 167 | + } |
| 168 | + |
| 169 | +private: |
| 170 | + ModuleDependenciesKind DetailsKind; |
| 171 | + |
| 172 | + union ModuleDetailsValue { |
| 173 | + SwiftTextualModuleDetails TextualDetails; |
| 174 | + SwiftBinaryModuleDetails BinaryDetails; |
| 175 | + SwiftPlaceholderModuleDetails PlaceholderDetails; |
| 176 | + ClangModuleDetails ClangDetails; |
| 177 | + |
| 178 | + ModuleDetailsValue(SwiftTextualModuleDetails Details) |
| 179 | + : TextualDetails(Details) {} |
| 180 | + ModuleDetailsValue(SwiftBinaryModuleDetails Details) |
| 181 | + : BinaryDetails(Details) {} |
| 182 | + ModuleDetailsValue(SwiftPlaceholderModuleDetails Details) |
| 183 | + : PlaceholderDetails(Details) {} |
| 184 | + ModuleDetailsValue(ClangModuleDetails Details) : ClangDetails(Details) {} |
| 185 | + |
| 186 | + ModuleDetailsValue() {} |
| 187 | + ~ModuleDetailsValue() {} |
| 188 | + } Value; |
| 189 | +}; |
| 190 | + |
| 191 | +struct ModuleInfo { |
| 192 | + /// The ID of the module this info describes |
| 193 | + ModuleDependencyID ID; |
| 194 | + |
| 195 | + /// The path for the module. |
| 196 | + std::string ModulePath; |
| 197 | + |
| 198 | + /// The source files used to build this module. |
| 199 | + std::vector<std::string> SourceFiles; |
| 200 | + |
| 201 | + /// The set of direct module dependencies of this module. |
| 202 | + std::vector<ModuleDependencyID> DirectDependencies; |
| 203 | + |
| 204 | + /// Specific details of a particular kind of module. |
| 205 | + ModuleDetails Details; |
| 206 | +}; |
| 207 | + |
| 208 | +struct FullDependencies { |
| 209 | + /// The name of the main module for this dependency graph (root node) |
| 210 | + const std::string MainModuleName; |
| 211 | + |
| 212 | + /// The complete set of modules discovered |
| 213 | + std::vector<ModuleInfo> Modules; |
| 214 | + |
| 215 | + FullDependencies(std::string MainModuleName) |
| 216 | + : MainModuleName(MainModuleName), Modules() {} |
| 217 | +}; |
| 218 | +} // namespace dependencies |
| 219 | +} // namespace swift |
| 220 | + |
| 221 | +#endif // SWIFT_DEPENDENCY_FULL_DEPENDENCIES_H |
0 commit comments