@@ -376,27 +376,130 @@ public struct Driver {
376
376
/// Path to the TBD file (text-based dylib).
377
377
let tbdPath : VirtualPath . Handle ?
378
378
379
- /// Path to the module documentation file.
380
- let moduleDocOutputPath : VirtualPath . Handle ?
379
+ /// Target-specific supplemental output file paths
380
+ struct SupplementalModuleTargetOutputPaths {
381
+ /// Path to the module documentation file.
382
+ let moduleDocOutputPath : VirtualPath . Handle ?
381
383
382
- /// Path to the Swift interface file.
383
- let swiftInterfacePath : VirtualPath . Handle ?
384
+ /// Path to the Swift interface file.
385
+ let swiftInterfacePath : VirtualPath . Handle ?
384
386
385
- /// Path to the Swift private interface file.
386
- let swiftPrivateInterfacePath : VirtualPath . Handle ?
387
+ /// Path to the Swift private interface file.
388
+ let swiftPrivateInterfacePath : VirtualPath . Handle ?
387
389
388
- /// Path to the Swift package interface file.
389
- let swiftPackageInterfacePath : VirtualPath . Handle ?
390
+ /// Path to the Swift package interface file.
391
+ let swiftPackageInterfacePath : VirtualPath . Handle ?
392
+
393
+ /// Path to the Swift module source information file.
394
+ let moduleSourceInfoPath : VirtualPath . Handle ?
395
+ }
396
+
397
+ private static func computeModuleOutputPaths(
398
+ _ parsedOptions: inout ParsedOptions ,
399
+ moduleName: String ,
400
+ packageName: String ? ,
401
+ moduleOutputInfo: ModuleOutputInfo ,
402
+ compilerOutputType: FileType ? ,
403
+ compilerMode: CompilerMode ,
404
+ emitModuleSeparately: Bool ,
405
+ outputFileMap: OutputFileMap ? ,
406
+ projectDirectory: VirtualPath . Handle ? ) throws -> SupplementalModuleTargetOutputPaths {
407
+ let moduleDocOutputPath = try Self . computeModuleDocOutputPath (
408
+ & parsedOptions,
409
+ moduleOutputPath: moduleOutputInfo. output? . outputPath,
410
+ compilerOutputType: compilerOutputType,
411
+ compilerMode: compilerMode,
412
+ outputFileMap: outputFileMap,
413
+ moduleName: moduleOutputInfo. name)
414
+
415
+ let moduleSourceInfoPath = try Self . computeModuleSourceInfoOutputPath (
416
+ & parsedOptions,
417
+ moduleOutputPath: moduleOutputInfo. output? . outputPath,
418
+ compilerOutputType: compilerOutputType,
419
+ compilerMode: compilerMode,
420
+ outputFileMap: outputFileMap,
421
+ moduleName: moduleOutputInfo. name,
422
+ projectDirectory: projectDirectory)
423
+
424
+ // ---------------------
425
+ // Swift interface paths
426
+ let swiftInterfacePath = try Self . computeSupplementaryOutputPath (
427
+ & parsedOptions, type: . swiftInterface, isOutputOptions: [ . emitModuleInterface] ,
428
+ outputPath: . emitModuleInterfacePath,
429
+ compilerOutputType: compilerOutputType,
430
+ compilerMode: compilerMode,
431
+ emitModuleSeparately: emitModuleSeparately,
432
+ outputFileMap: outputFileMap,
433
+ moduleName: moduleOutputInfo. name)
434
+
435
+ let givenPrivateInterfacePath = try Self . computeSupplementaryOutputPath (
436
+ & parsedOptions, type: . privateSwiftInterface, isOutputOptions: [ ] ,
437
+ outputPath: . emitPrivateModuleInterfacePath,
438
+ compilerOutputType: compilerOutputType,
439
+ compilerMode: compilerMode,
440
+ emitModuleSeparately: emitModuleSeparately,
441
+ outputFileMap: outputFileMap,
442
+ moduleName: moduleOutputInfo. name)
443
+ let givenPackageInterfacePath = try Self . computeSupplementaryOutputPath (
444
+ & parsedOptions, type: . packageSwiftInterface, isOutputOptions: [ ] ,
445
+ outputPath: . emitPackageModuleInterfacePath,
446
+ compilerOutputType: compilerOutputType,
447
+ compilerMode: compilerMode,
448
+ emitModuleSeparately: emitModuleSeparately,
449
+ outputFileMap: outputFileMap,
450
+ moduleName: moduleOutputInfo. name)
451
+
452
+ // Always emit the private swift interface if a public interface is emitted.
453
+ // With the introduction of features like @_spi_available, we may print
454
+ // public and private interfaces differently even from the same codebase.
455
+ // For this reason, we should always print private interfaces so that we
456
+ // don’t mix the public interfaces with private Clang modules.
457
+ let swiftPrivateInterfacePath : VirtualPath . Handle ?
458
+ if let privateInterfacePath = givenPrivateInterfacePath {
459
+ swiftPrivateInterfacePath = privateInterfacePath
460
+ } else if let swiftInterfacePath = swiftInterfacePath {
461
+ swiftPrivateInterfacePath = try VirtualPath . lookup ( swiftInterfacePath)
462
+ . replacingExtension ( with: . privateSwiftInterface) . intern ( )
463
+ } else {
464
+ swiftPrivateInterfacePath = nil
465
+ }
466
+
467
+ let swiftPackageInterfacePath : VirtualPath . Handle ?
468
+ if let packageName = packageName,
469
+ !packageName. isEmpty {
470
+ // Generate a package interface if built with -package-name required for
471
+ // decls with the `package` access level. The `.package.swiftinterface`
472
+ // contains package decls as well as SPI and public decls (superset of a
473
+ // private interface).
474
+ if let givenPackageInterfacePath = givenPackageInterfacePath {
475
+ swiftPackageInterfacePath = givenPackageInterfacePath
476
+ } else if let swiftInterfacePath = swiftInterfacePath {
477
+ swiftPackageInterfacePath = try VirtualPath . lookup ( swiftInterfacePath)
478
+ . replacingExtension ( with: . packageSwiftInterface) . intern ( )
479
+ } else {
480
+ swiftPackageInterfacePath = nil
481
+ }
482
+ } else {
483
+ swiftPackageInterfacePath = nil
484
+ }
485
+
486
+ return SupplementalModuleTargetOutputPaths (
487
+ moduleDocOutputPath: moduleDocOutputPath,
488
+ swiftInterfacePath: swiftInterfacePath,
489
+ swiftPrivateInterfacePath: swiftPrivateInterfacePath,
490
+ swiftPackageInterfacePath: swiftPackageInterfacePath,
491
+ moduleSourceInfoPath: moduleSourceInfoPath)
492
+ }
493
+
494
+ /// Structure storing paths to supplemental outputs for the target module
495
+ let moduleOutputPaths : SupplementalModuleTargetOutputPaths
390
496
391
497
/// File type for the optimization record.
392
498
let optimizationRecordFileType : FileType ?
393
499
394
500
/// Path to the optimization record.
395
501
let optimizationRecordPath : VirtualPath . Handle ?
396
502
397
- /// Path to the Swift module source information file.
398
- let moduleSourceInfoPath : VirtualPath . Handle ?
399
-
400
503
/// Path to the module's digester baseline file.
401
504
let digesterBaselinePath : VirtualPath . Handle ?
402
505
@@ -1023,24 +1126,22 @@ public struct Driver {
1023
1126
emitModuleSeparately: emitModuleSeparately,
1024
1127
outputFileMap: self . outputFileMap,
1025
1128
moduleName: moduleOutputInfo. name)
1026
- self . moduleDocOutputPath = try Self . computeModuleDocOutputPath (
1027
- & parsedOptions, moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
1028
- compilerOutputType: compilerOutputType,
1029
- compilerMode: compilerMode,
1030
- outputFileMap: self . outputFileMap,
1031
- moduleName: moduleOutputInfo. name)
1032
1129
1033
1130
let projectDirectory = Self . computeProjectDirectoryPath (
1034
- moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
1131
+ moduleOutputPath: moduleOutputInfo. output? . outputPath,
1035
1132
fileSystem: self . fileSystem)
1036
- self . moduleSourceInfoPath = try Self . computeModuleSourceInfoOutputPath (
1037
- & parsedOptions,
1038
- moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
1039
- compilerOutputType: compilerOutputType,
1040
- compilerMode: compilerMode,
1041
- outputFileMap: self . outputFileMap,
1042
- moduleName: moduleOutputInfo. name,
1043
- projectDirectory: projectDirectory)
1133
+
1134
+ self . moduleOutputPaths = try Self . computeModuleOutputPaths (
1135
+ & parsedOptions,
1136
+ moduleName: moduleOutputInfo. name,
1137
+ packageName: self . packageName,
1138
+ moduleOutputInfo: self . moduleOutputInfo,
1139
+ compilerOutputType: compilerOutputType,
1140
+ compilerMode: compilerMode,
1141
+ emitModuleSeparately: emitModuleSeparately,
1142
+ outputFileMap: self . outputFileMap,
1143
+ projectDirectory: projectDirectory)
1144
+
1044
1145
self . digesterBaselinePath = try Self . computeDigesterBaselineOutputPath (
1045
1146
& parsedOptions,
1046
1147
moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
@@ -1050,59 +1151,6 @@ public struct Driver {
1050
1151
outputFileMap: self . outputFileMap,
1051
1152
moduleName: moduleOutputInfo. name,
1052
1153
projectDirectory: projectDirectory)
1053
- self . swiftInterfacePath = try Self . computeSupplementaryOutputPath (
1054
- & parsedOptions, type: . swiftInterface, isOutputOptions: [ . emitModuleInterface] ,
1055
- outputPath: . emitModuleInterfacePath,
1056
- compilerOutputType: compilerOutputType,
1057
- compilerMode: compilerMode,
1058
- emitModuleSeparately: emitModuleSeparately,
1059
- outputFileMap: self . outputFileMap,
1060
- moduleName: moduleOutputInfo. name)
1061
- let givenPrivateInterfacePath = try Self . computeSupplementaryOutputPath (
1062
- & parsedOptions, type: . privateSwiftInterface, isOutputOptions: [ ] ,
1063
- outputPath: . emitPrivateModuleInterfacePath,
1064
- compilerOutputType: compilerOutputType,
1065
- compilerMode: compilerMode,
1066
- emitModuleSeparately: emitModuleSeparately,
1067
- outputFileMap: self . outputFileMap,
1068
- moduleName: moduleOutputInfo. name)
1069
- let givenPackageInterfacePath = try Self . computeSupplementaryOutputPath (
1070
- & parsedOptions, type: . packageSwiftInterface, isOutputOptions: [ ] ,
1071
- outputPath: . emitPackageModuleInterfacePath,
1072
- compilerOutputType: compilerOutputType,
1073
- compilerMode: compilerMode,
1074
- emitModuleSeparately: emitModuleSeparately,
1075
- outputFileMap: self . outputFileMap,
1076
- moduleName: moduleOutputInfo. name)
1077
-
1078
- // Always emitting private swift interfaces if public interfaces are emitted.'
1079
- // With the introduction of features like @_spi_available, we may print public
1080
- // and private interfaces differently even from the same codebase. For this reason,
1081
- // we should always print private interfaces so that we don’t mix the public interfaces
1082
- // with private Clang modules.
1083
- if let swiftInterfacePath = self . swiftInterfacePath,
1084
- givenPrivateInterfacePath == nil {
1085
- self . swiftPrivateInterfacePath = try VirtualPath . lookup ( swiftInterfacePath)
1086
- . replacingExtension ( with: . privateSwiftInterface) . intern ( )
1087
- } else {
1088
- self . swiftPrivateInterfacePath = givenPrivateInterfacePath
1089
- }
1090
-
1091
- if let packageNameInput = parsedOptions. getLastArgument ( Option . packageName) ,
1092
- !packageNameInput. asSingle. isEmpty {
1093
- // Generate a package interface if built with `-package-name` required for decls
1094
- // with the `package` access level. The .package.swiftinterface contains package
1095
- // decls as well as SPI and public decls (superset of a private interface).
1096
- if let publicInterfacePath = self . swiftInterfacePath,
1097
- givenPackageInterfacePath == nil {
1098
- self . swiftPackageInterfacePath = try VirtualPath . lookup ( publicInterfacePath)
1099
- . replacingExtension ( with: . packageSwiftInterface) . intern ( )
1100
- } else {
1101
- self . swiftPackageInterfacePath = givenPackageInterfacePath
1102
- }
1103
- } else {
1104
- self . swiftPackageInterfacePath = nil
1105
- }
1106
1154
1107
1155
var optimizationRecordFileType = FileType . yamlOptimizationRecord
1108
1156
if let argument = parsedOptions. getLastArgument ( . saveOptimizationRecordEQ) ? . asSingle {
@@ -1151,7 +1199,7 @@ public struct Driver {
1151
1199
Self . validateDigesterArgs ( & parsedOptions,
1152
1200
moduleOutputInfo: moduleOutputInfo,
1153
1201
digesterMode: self . digesterMode,
1154
- swiftInterfacePath: self . swiftInterfacePath,
1202
+ swiftInterfacePath: self . moduleOutputPaths . swiftInterfacePath,
1155
1203
diagnosticEngine: diagnosticsEngine)
1156
1204
1157
1205
try verifyOutputOptions ( )
0 commit comments