@@ -259,6 +259,9 @@ public struct Driver {
259259 /// The information about the module to produce.
260260 @_spi ( Testing) public let moduleOutputInfo : ModuleOutputInfo
261261
262+ /// Information about the target variant module to produce if applicable
263+ @_spi ( Testing) public let variantModuleOutputInfo : ModuleOutputInfo ?
264+
262265 /// Name of the package containing a target module or file.
263266 @_spi ( Testing) public let packageName : String ?
264267
@@ -494,6 +497,9 @@ public struct Driver {
494497 /// Structure storing paths to supplemental outputs for the target module
495498 let moduleOutputPaths : SupplementalModuleTargetOutputPaths
496499
500+ /// Structure storing paths to supplemental outputs for the target variant
501+ let variantModuleOutputPaths : SupplementalModuleTargetOutputPaths ?
502+
497503 /// File type for the optimization record.
498504 let optimizationRecordFileType : FileType ?
499505
@@ -946,10 +952,24 @@ public struct Driver {
946952
947953 // Determine the module we're building and whether/how the module file itself will be emitted.
948954 self . moduleOutputInfo = try Self . computeModuleInfo (
949- & parsedOptions, compilerOutputType: compilerOutputType, compilerMode: compilerMode, linkerOutputType: linkerOutputType,
950- debugInfoLevel: debugInfo. level, diagnosticsEngine: diagnosticEngine,
955+ & parsedOptions,
956+ modulePath: parsedOptions. getLastArgument ( . emitModulePath) ? . asSingle,
957+ compilerOutputType: compilerOutputType,
958+ compilerMode: compilerMode,
959+ linkerOutputType: linkerOutputType,
960+ debugInfoLevel: debugInfo. level,
961+ diagnosticsEngine: diagnosticEngine,
951962 workingDirectory: self . workingDirectory)
952963
964+ self . variantModuleOutputInfo = try Self . computeVariantModuleInfo (
965+ & parsedOptions,
966+ compilerOutputType: compilerOutputType,
967+ compilerMode: compilerMode,
968+ linkerOutputType: linkerOutputType,
969+ debugInfoLevel: debugInfo. level,
970+ diagnosticsEngine: diagnosticsEngine,
971+ workingDirectory: workingDirectory)
972+
953973 // Should we schedule a separate emit-module job?
954974 self . emitModuleSeparately = Self . computeEmitModuleSeparately ( parsedOptions: & parsedOptions,
955975 compilerMode: compilerMode,
@@ -1142,6 +1162,21 @@ public struct Driver {
11421162 outputFileMap: self . outputFileMap,
11431163 projectDirectory: projectDirectory)
11441164
1165+ if let variantModuleOutputInfo = self . variantModuleOutputInfo {
1166+ self . variantModuleOutputPaths = try Self . computeModuleOutputPaths (
1167+ & parsedOptions,
1168+ moduleName: variantModuleOutputInfo. name,
1169+ packageName: self . packageName,
1170+ moduleOutputInfo: variantModuleOutputInfo,
1171+ compilerOutputType: compilerOutputType,
1172+ compilerMode: compilerMode,
1173+ emitModuleSeparately: true , // variant module is always independent
1174+ outputFileMap: self . outputFileMap,
1175+ projectDirectory: projectDirectory)
1176+ } else {
1177+ self . variantModuleOutputPaths = nil
1178+ }
1179+
11451180 self . digesterBaselinePath = try Self . computeDigesterBaselineOutputPath (
11461181 & parsedOptions,
11471182 moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
@@ -2673,9 +2708,37 @@ extension Driver {
26732708 return " "
26742709 }
26752710
2711+ private static func computeVariantModuleInfo(
2712+ _ parsedOptions: inout ParsedOptions ,
2713+ compilerOutputType: FileType ? ,
2714+ compilerMode: CompilerMode ,
2715+ linkerOutputType: LinkOutputType ? ,
2716+ debugInfoLevel: DebugInfo . Level ? ,
2717+ diagnosticsEngine: DiagnosticsEngine ,
2718+ workingDirectory: AbsolutePath ?
2719+ ) throws -> ModuleOutputInfo ? {
2720+ // If there is no target variant, then there is no target variant module.
2721+ // If there is no emit-variant-module, then there is not target variant
2722+ // module.
2723+ guard let variantModulePath = parsedOptions. getLastArgument ( . emitVariantModulePath) ,
2724+ parsedOptions. hasArgument ( . targetVariant) else {
2725+ return nil
2726+ }
2727+ return try computeModuleInfo ( & parsedOptions,
2728+ modulePath: variantModulePath. asSingle,
2729+ compilerOutputType: compilerOutputType,
2730+ compilerMode: compilerMode,
2731+ linkerOutputType: linkerOutputType,
2732+ debugInfoLevel: debugInfoLevel,
2733+ diagnosticsEngine: diagnosticsEngine,
2734+ workingDirectory: workingDirectory)
2735+ return nil
2736+ }
2737+
26762738 /// Determine how the module will be emitted and the name of the module.
26772739 private static func computeModuleInfo(
26782740 _ parsedOptions: inout ParsedOptions ,
2741+ modulePath: String ? ,
26792742 compilerOutputType: FileType ? ,
26802743 compilerMode: CompilerMode ,
26812744 linkerOutputType: LinkOutputType ? ,
@@ -2690,7 +2753,7 @@ extension Driver {
26902753 }
26912754
26922755 var moduleOutputKind : ModuleOutputKind ?
2693- if parsedOptions. hasArgument ( . emitModule, . emitModulePath ) {
2756+ if parsedOptions. hasArgument ( . emitModule) || modulePath != nil {
26942757 // The user has requested a module, so generate one and treat it as
26952758 // top-level output.
26962759 moduleOutputKind = . topLevel
@@ -2772,9 +2835,9 @@ extension Driver {
27722835
27732836 // FIXME: Look in the output file map. It looks like it is weirdly
27742837 // anchored to the first input?
2775- if let modulePathArg = parsedOptions . getLastArgument ( . emitModulePath ) {
2838+ if let modulePathArg = modulePath {
27762839 // The module path was specified.
2777- moduleOutputPath = try VirtualPath ( path: modulePathArg. asSingle )
2840+ moduleOutputPath = try VirtualPath ( path: modulePathArg)
27782841 } else if moduleOutputKind == . topLevel {
27792842 // FIXME: Logic to infer from primary outputs, etc.
27802843 let moduleFilename = moduleName. appendingFileTypeExtension ( . swiftModule)
0 commit comments