Skip to content

Commit f882b3d

Browse files
committed
Wire up all the flags
This adds flags for setting the variant module doc path, source info path, api descriptor path, module interface path, private interface path, and package interface path.
1 parent 8ad234d commit f882b3d

File tree

3 files changed

+88
-18
lines changed

3 files changed

+88
-18
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,41 @@ public struct Driver {
409409
compilerMode: CompilerMode,
410410
emitModuleSeparately: Bool,
411411
outputFileMap: OutputFileMap?,
412-
projectDirectory: VirtualPath.Handle?) throws -> SupplementalModuleTargetOutputPaths {
412+
projectDirectory: VirtualPath.Handle?,
413+
apiDescriptorDirectory: VirtualPath?,
414+
target: FrontendTargetInfo.Target,
415+
isVariant: Bool) throws -> SupplementalModuleTargetOutputPaths {
416+
struct SupplementalPathOptions {
417+
let moduleDocPath: Option
418+
let sourceInfoPath: Option
419+
let apiDescriptorPath: Option
420+
let moduleInterfacePath: Option
421+
let privateInterfacePath: Option
422+
let packageInterfacePath: Option
423+
424+
static let targetPathOptions = SupplementalPathOptions(
425+
moduleDocPath: .emitModuleDocPath,
426+
sourceInfoPath: .emitModuleSourceInfoPath,
427+
apiDescriptorPath: .emitApiDescriptorPath,
428+
moduleInterfacePath: .emitModuleInterfacePath,
429+
privateInterfacePath: .emitPrivateModuleInterfacePath,
430+
packageInterfacePath: .emitPackageModuleInterfacePath)
431+
432+
static let variantTargetPathOptions = SupplementalPathOptions(
433+
moduleDocPath: .emitVariantModuleDocPath,
434+
sourceInfoPath: .emitVariantModuleSourceInfoPath,
435+
apiDescriptorPath: .emitVariantApiDescriptorPath,
436+
moduleInterfacePath: .emitVariantModuleInterfacePath,
437+
privateInterfacePath: .emitVariantPrivateModuleInterfacePath,
438+
packageInterfacePath: .emitVariantPackageModuleInterfacePath)
439+
}
440+
441+
let pathOptions: SupplementalPathOptions = isVariant ? .variantTargetPathOptions : .targetPathOptions
442+
413443
let moduleDocOutputPath = try Self.computeModuleDocOutputPath(
414444
&parsedOptions,
415445
moduleOutputPath: moduleOutputInfo.output?.outputPath,
446+
outputOption: pathOptions.moduleDocPath,
416447
compilerOutputType: compilerOutputType,
417448
compilerMode: compilerMode,
418449
outputFileMap: outputFileMap,
@@ -421,6 +452,7 @@ public struct Driver {
421452
let moduleSourceInfoPath = try Self.computeModuleSourceInfoOutputPath(
422453
&parsedOptions,
423454
moduleOutputPath: moduleOutputInfo.output?.outputPath,
455+
outputOption: pathOptions.sourceInfoPath,
424456
compilerOutputType: compilerOutputType,
425457
compilerMode: compilerMode,
426458
outputFileMap: outputFileMap,
@@ -437,7 +469,7 @@ public struct Driver {
437469
} else {
438470
apiDescriptorFilePath = try Self.computeSupplementaryOutputPath(
439471
&parsedOptions, type: .jsonAPIDescriptor, isOutputOptions: [],
440-
outputPath: .emitApiDescriptorPath,
472+
outputPath: pathOptions.apiDescriptorPath,
441473
compilerOutputType: compilerOutputType,
442474
compilerMode: compilerMode,
443475
emitModuleSeparately: emitModuleSeparately,
@@ -449,7 +481,7 @@ public struct Driver {
449481
// Swift interface paths
450482
let swiftInterfacePath = try Self.computeSupplementaryOutputPath(
451483
&parsedOptions, type: .swiftInterface, isOutputOptions: [.emitModuleInterface],
452-
outputPath: .emitModuleInterfacePath,
484+
outputPath: pathOptions.moduleInterfacePath,
453485
compilerOutputType: compilerOutputType,
454486
compilerMode: compilerMode,
455487
emitModuleSeparately: emitModuleSeparately,
@@ -458,15 +490,15 @@ public struct Driver {
458490

459491
let givenPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
460492
&parsedOptions, type: .privateSwiftInterface, isOutputOptions: [],
461-
outputPath: .emitPrivateModuleInterfacePath,
493+
outputPath: pathOptions.privateInterfacePath,
462494
compilerOutputType: compilerOutputType,
463495
compilerMode: compilerMode,
464496
emitModuleSeparately: emitModuleSeparately,
465497
outputFileMap: outputFileMap,
466498
moduleName: moduleOutputInfo.name)
467499
let givenPackageInterfacePath = try Self.computeSupplementaryOutputPath(
468500
&parsedOptions, type: .packageSwiftInterface, isOutputOptions: [],
469-
outputPath: .emitPackageModuleInterfacePath,
501+
outputPath: pathOptions.packageInterfacePath,
470502
compilerOutputType: compilerOutputType,
471503
compilerMode: compilerMode,
472504
emitModuleSeparately: emitModuleSeparately,
@@ -512,7 +544,7 @@ public struct Driver {
512544
swiftInterfacePath: swiftInterfacePath,
513545
swiftPrivateInterfacePath: swiftPrivateInterfacePath,
514546
swiftPackageInterfacePath: swiftPackageInterfacePath,
515-
moduleSourceInfoPath: moduleSourceInfoPath)
547+
moduleSourceInfoPath: moduleSourceInfoPath,
516548
apiDescriptorFilePath: apiDescriptorFilePath)
517549
}
518550

@@ -1187,11 +1219,12 @@ public struct Driver {
11871219
compilerMode: compilerMode,
11881220
emitModuleSeparately: emitModuleSeparately,
11891221
outputFileMap: self.outputFileMap,
1190-
projectDirectory: projectDirectory)
1222+
projectDirectory: projectDirectory,
11911223
apiDescriptorDirectory: apiDescriptorDirectory,
1192-
target: frontendTargetInfo.target)
1224+
target: frontendTargetInfo.target,
1225+
isVariant: false)
11931226

1194-
if let variantModuleOutputInfo = self.variantModuleOutputInfo {
1227+
if let variantModuleOutputInfo = self.variantModuleOutputInfo,
11951228
let targetVariant = self.frontendTargetInfo.targetVariant {
11961229
self.variantModuleOutputPaths = try Self.computeModuleOutputPaths(
11971230
&parsedOptions,
@@ -1204,7 +1237,8 @@ public struct Driver {
12041237
outputFileMap: self.outputFileMap,
12051238
projectDirectory: projectDirectory,
12061239
apiDescriptorDirectory: apiDescriptorDirectory,
1207-
target: targetVariant)
1240+
target: targetVariant,
1241+
isVariant: true)
12081242
} else {
12091243
self.variantModuleOutputPaths = nil
12101244
}
@@ -3779,6 +3813,7 @@ extension Driver {
37793813
static func computeModuleDocOutputPath(
37803814
_ parsedOptions: inout ParsedOptions,
37813815
moduleOutputPath: VirtualPath.Handle?,
3816+
outputOption: Option,
37823817
compilerOutputType: FileType?,
37833818
compilerMode: CompilerMode,
37843819
outputFileMap: OutputFileMap?,
@@ -3788,7 +3823,7 @@ extension Driver {
37883823
moduleOutputPath: moduleOutputPath,
37893824
type: .swiftDocumentation,
37903825
isOutput: .emitModuleDoc,
3791-
outputPath: .emitModuleDocPath,
3826+
outputPath: outputOption,
37923827
compilerOutputType: compilerOutputType,
37933828
compilerMode: compilerMode,
37943829
outputFileMap: outputFileMap,
@@ -3799,6 +3834,7 @@ extension Driver {
37993834
static func computeModuleSourceInfoOutputPath(
38003835
_ parsedOptions: inout ParsedOptions,
38013836
moduleOutputPath: VirtualPath.Handle?,
3837+
outputOption: Option,
38023838
compilerOutputType: FileType?,
38033839
compilerMode: CompilerMode,
38043840
outputFileMap: OutputFileMap?,
@@ -3810,7 +3846,7 @@ extension Driver {
38103846
moduleOutputPath: moduleOutputPath,
38113847
type: .swiftSourceInfoFile,
38123848
isOutput: .emitModuleSourceInfo,
3813-
outputPath: .emitModuleSourceInfoPath,
3849+
outputPath: outputOption,
38143850
compilerOutputType: compilerOutputType,
38153851
compilerMode: compilerMode,
38163852
outputFileMap: outputFileMap,

Sources/SwiftOptions/Options.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,13 @@ extension Option {
384384
public static let emitTbdPathEQ: Option = Option("-emit-tbd-path=", .joined, alias: Option.emitTbdPath, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant])
385385
public static let emitTbdPath: Option = Option("-emit-tbd-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "<path>", helpText: "Emit the TBD file to <path>")
386386
public static let emitTbd: Option = Option("-emit-tbd", .flag, attributes: [.frontend, .noInteractive, .supplementaryOutput], helpText: "Emit a TBD file")
387+
public static let emitVariantApiDescriptorPath: Option = Option("-emit-variant-api-descriptor-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "<path>", helpText: "Output a JSON file describing the target variant module's API to <path>")
388+
public static let emitVariantModuleDocPath: Option = Option("-emit-variant-module-doc-path", .separate, attributes: [.frontend, .noDriver, .cacheInvariant], metaVar: "<path>", helpText: "Output module documentation file for the target variant to <path>")
389+
public static let emitVariantModuleInterfacePath: Option = Option("-emit-variant-module-interface-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "<path>", helpText: "Output module interface file for the target variant to <path>")
390+
public static let emitVariantModulePath: Option = Option("-emit-variant-module-path", .separate, attributes: [.noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "<path>", helpText: "Emit an importable module for the target variant at the specified path")
391+
public static let emitVariantModuleSourceInfoPath: Option = Option("-emit-variant-module-source-info-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput], metaVar: "<path>", helpText: "Output module source info file for the target variant to <path>")
392+
public static let emitVariantPackageModuleInterfacePath: Option = Option("-emit-variant-package-module-interface-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "<path>", helpText: "Output package module interface file for the target variant to <path>")
393+
public static let emitVariantPrivateModuleInterfacePath: Option = Option("-emit-variant-private-module-interface-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "<path>", helpText: "Output private module interface file for the target variant to <path>")
387394
public static let emitVerboseSil: Option = Option("-emit-verbose-sil", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Emit locations during SIL emission")
388395
public static let emptyAbiDescriptor: Option = Option("-empty-abi-descriptor", .flag, attributes: [.frontend, .noDriver], helpText: "Avoid printing actual module content into ABI descriptor file")
389396
public static let emptyBaseline: Option = Option("-empty-baseline", .flag, attributes: [.noDriver], helpText: "Use empty baseline for diagnostics")
@@ -923,10 +930,6 @@ extension Option {
923930
public static let Xlinker: Option = Option("-Xlinker", .separate, attributes: [.doesNotAffectIncrementalBuild], helpText: "Specifies an option which should be passed to the linker")
924931
public static let Xllvm: Option = Option("-Xllvm", .separate, attributes: [.helpHidden, .frontend], metaVar: "<arg>", helpText: "Pass <arg> to LLVM.")
925932
public static let DASHDASH: Option = Option("--", .remaining, attributes: [.frontend, .doesNotAffectIncrementalBuild])
926-
927-
public static let emitVariantModulePath: Option = Option("-emit-variant-module-path", .separate, attributes: [.noInteractive, .supplementaryOutput, .argumentIsPath], helpText: "Emit an importable module for the target variant at the specified path")
928-
public static let emitVariantModuleInterface: Option = Option("-emit-variant-module-interface", .flag, attributes: [.noInteractive, .supplementaryOutput], helpText: "Emit an importable module for the target variant")
929-
930933
}
931934

932935
extension Option {
@@ -1298,6 +1301,13 @@ extension Option {
12981301
Option.emitTbdPathEQ,
12991302
Option.emitTbdPath,
13001303
Option.emitTbd,
1304+
Option.emitVariantApiDescriptorPath,
1305+
Option.emitVariantModuleDocPath,
1306+
Option.emitVariantModuleInterfacePath,
1307+
Option.emitVariantModulePath,
1308+
Option.emitVariantModuleSourceInfoPath,
1309+
Option.emitVariantPackageModuleInterfacePath,
1310+
Option.emitVariantPrivateModuleInterfacePath,
13011311
Option.emitVerboseSil,
13021312
Option.emptyAbiDescriptor,
13031313
Option.emptyBaseline,
@@ -1836,8 +1846,6 @@ extension Option {
18361846
Option.Xlinker,
18371847
Option.Xllvm,
18381848
Option.DASHDASH,
1839-
Option.emitVariantModulePath,
1840-
Option.emitVariantModuleInterface,
18411849
]
18421850
}
18431851
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,6 +4125,32 @@ final class SwiftDriverTests: XCTestCase {
41254125
]))
41264126
}
41274127
}
4128+
4129+
do {
4130+
var driver = try Driver(args: ["swiftc",
4131+
"-target", "x86_64-apple-macosx10.14",
4132+
"-target-variant", "x86_64-apple-ios13.1-macabi",
4133+
"-emit-variant-module-path", "foo.swiftmodule/x86_64-apple-ios13.1-macabi.swiftmodule",
4134+
"-enable-library-evolution",
4135+
"-emit-module",
4136+
"-emit-api-descriptor-path", "foo.swiftmodule/target.api.json",
4137+
"-emit-variant-api-descriptor-path", "foo.swiftmodule/variant.api.json",
4138+
"foo.swift"])
4139+
4140+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
4141+
let targetModuleJob = plannedJobs[0]
4142+
let variantModuleJob = plannedJobs[1]
4143+
4144+
XCTAssert(targetModuleJob.commandLine.contains(subsequence: [
4145+
.flag("-emit-api-descriptor-path"),
4146+
.path(.relative(try .init(validating: "foo.swiftmodule/target.api.json")))
4147+
]))
4148+
4149+
XCTAssert(variantModuleJob.commandLine.contains(subsequence: [
4150+
.flag("-emit-api-descriptor-path"),
4151+
.path(.relative(try .init(validating: "foo.swiftmodule/variant.api.json")))
4152+
]))
4153+
}
41284154
#endif
41294155
}
41304156

0 commit comments

Comments
 (0)