@@ -259,6 +259,9 @@ public struct Driver {
259
259
/// The information about the module to produce.
260
260
@_spi ( Testing) public let moduleOutputInfo : ModuleOutputInfo
261
261
262
+ /// Information about the target variant module to produce if applicable
263
+ @_spi ( Testing) public let variantModuleOutputInfo : ModuleOutputInfo ?
264
+
262
265
/// Name of the package containing a target module or file.
263
266
@_spi ( Testing) public let packageName : String ?
264
267
@@ -494,6 +497,9 @@ public struct Driver {
494
497
/// Structure storing paths to supplemental outputs for the target module
495
498
let moduleOutputPaths : SupplementalModuleTargetOutputPaths
496
499
500
+ /// Structure storing paths to supplemental outputs for the target variant
501
+ let variantModuleOutputPaths : SupplementalModuleTargetOutputPaths ?
502
+
497
503
/// File type for the optimization record.
498
504
let optimizationRecordFileType : FileType ?
499
505
@@ -946,10 +952,24 @@ public struct Driver {
946
952
947
953
// Determine the module we're building and whether/how the module file itself will be emitted.
948
954
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,
951
962
workingDirectory: self . workingDirectory)
952
963
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
+
953
973
// Should we schedule a separate emit-module job?
954
974
self . emitModuleSeparately = Self . computeEmitModuleSeparately ( parsedOptions: & parsedOptions,
955
975
compilerMode: compilerMode,
@@ -1142,6 +1162,21 @@ public struct Driver {
1142
1162
outputFileMap: self . outputFileMap,
1143
1163
projectDirectory: projectDirectory)
1144
1164
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
+
1145
1180
self . digesterBaselinePath = try Self . computeDigesterBaselineOutputPath (
1146
1181
& parsedOptions,
1147
1182
moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
@@ -2673,9 +2708,37 @@ extension Driver {
2673
2708
return " "
2674
2709
}
2675
2710
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
+
2676
2738
/// Determine how the module will be emitted and the name of the module.
2677
2739
private static func computeModuleInfo(
2678
2740
_ parsedOptions: inout ParsedOptions ,
2741
+ modulePath: String ? ,
2679
2742
compilerOutputType: FileType ? ,
2680
2743
compilerMode: CompilerMode ,
2681
2744
linkerOutputType: LinkOutputType ? ,
@@ -2690,7 +2753,7 @@ extension Driver {
2690
2753
}
2691
2754
2692
2755
var moduleOutputKind : ModuleOutputKind ?
2693
- if parsedOptions. hasArgument ( . emitModule, . emitModulePath ) {
2756
+ if parsedOptions. hasArgument ( . emitModule) || modulePath != nil {
2694
2757
// The user has requested a module, so generate one and treat it as
2695
2758
// top-level output.
2696
2759
moduleOutputKind = . topLevel
@@ -2772,9 +2835,9 @@ extension Driver {
2772
2835
2773
2836
// FIXME: Look in the output file map. It looks like it is weirdly
2774
2837
// anchored to the first input?
2775
- if let modulePathArg = parsedOptions . getLastArgument ( . emitModulePath ) {
2838
+ if let modulePathArg = modulePath {
2776
2839
// The module path was specified.
2777
- moduleOutputPath = try VirtualPath ( path: modulePathArg. asSingle )
2840
+ moduleOutputPath = try VirtualPath ( path: modulePathArg)
2778
2841
} else if moduleOutputKind == . topLevel {
2779
2842
// FIXME: Logic to infer from primary outputs, etc.
2780
2843
let moduleFilename = moduleName. appendingFileTypeExtension ( . swiftModule)
0 commit comments