@@ -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,
@@ -2708,9 +2743,37 @@ extension Driver {
2708
2743
return " "
2709
2744
}
2710
2745
2746
+ private static func computeVariantModuleInfo(
2747
+ _ parsedOptions: inout ParsedOptions ,
2748
+ compilerOutputType: FileType ? ,
2749
+ compilerMode: CompilerMode ,
2750
+ linkerOutputType: LinkOutputType ? ,
2751
+ debugInfoLevel: DebugInfo . Level ? ,
2752
+ diagnosticsEngine: DiagnosticsEngine ,
2753
+ workingDirectory: AbsolutePath ?
2754
+ ) throws -> ModuleOutputInfo ? {
2755
+ // If there is no target variant, then there is no target variant module.
2756
+ // If there is no emit-variant-module, then there is not target variant
2757
+ // module.
2758
+ guard let variantModulePath = parsedOptions. getLastArgument ( . emitVariantModulePath) ,
2759
+ parsedOptions. hasArgument ( . targetVariant) else {
2760
+ return nil
2761
+ }
2762
+ return try computeModuleInfo ( & parsedOptions,
2763
+ modulePath: variantModulePath. asSingle,
2764
+ compilerOutputType: compilerOutputType,
2765
+ compilerMode: compilerMode,
2766
+ linkerOutputType: linkerOutputType,
2767
+ debugInfoLevel: debugInfoLevel,
2768
+ diagnosticsEngine: diagnosticsEngine,
2769
+ workingDirectory: workingDirectory)
2770
+ return nil
2771
+ }
2772
+
2711
2773
/// Determine how the module will be emitted and the name of the module.
2712
2774
private static func computeModuleInfo(
2713
2775
_ parsedOptions: inout ParsedOptions ,
2776
+ modulePath: String ? ,
2714
2777
compilerOutputType: FileType ? ,
2715
2778
compilerMode: CompilerMode ,
2716
2779
linkerOutputType: LinkOutputType ? ,
@@ -2725,7 +2788,7 @@ extension Driver {
2725
2788
}
2726
2789
2727
2790
var moduleOutputKind : ModuleOutputKind ?
2728
- if parsedOptions. hasArgument ( . emitModule, . emitModulePath ) {
2791
+ if parsedOptions. hasArgument ( . emitModule) || modulePath != nil {
2729
2792
// The user has requested a module, so generate one and treat it as
2730
2793
// top-level output.
2731
2794
moduleOutputKind = . topLevel
@@ -2807,9 +2870,9 @@ extension Driver {
2807
2870
2808
2871
// FIXME: Look in the output file map. It looks like it is weirdly
2809
2872
// anchored to the first input?
2810
- if let modulePathArg = parsedOptions . getLastArgument ( . emitModulePath ) {
2873
+ if let modulePathArg = modulePath {
2811
2874
// The module path was specified.
2812
- moduleOutputPath = try VirtualPath ( path: modulePathArg. asSingle )
2875
+ moduleOutputPath = try VirtualPath ( path: modulePathArg)
2813
2876
} else if moduleOutputKind == . topLevel {
2814
2877
// FIXME: Logic to infer from primary outputs, etc.
2815
2878
let moduleFilename = moduleName. appendingFileTypeExtension ( . swiftModule)
0 commit comments