Skip to content

Commit 3abe69f

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 00fa926 commit 3abe69f

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
}
@@ -3744,6 +3778,7 @@ extension Driver {
37443778
static func computeModuleDocOutputPath(
37453779
_ parsedOptions: inout ParsedOptions,
37463780
moduleOutputPath: VirtualPath.Handle?,
3781+
outputOption: Option,
37473782
compilerOutputType: FileType?,
37483783
compilerMode: CompilerMode,
37493784
outputFileMap: OutputFileMap?,
@@ -3753,7 +3788,7 @@ extension Driver {
37533788
moduleOutputPath: moduleOutputPath,
37543789
type: .swiftDocumentation,
37553790
isOutput: .emitModuleDoc,
3756-
outputPath: .emitModuleDocPath,
3791+
outputPath: outputOption,
37573792
compilerOutputType: compilerOutputType,
37583793
compilerMode: compilerMode,
37593794
outputFileMap: outputFileMap,
@@ -3764,6 +3799,7 @@ extension Driver {
37643799
static func computeModuleSourceInfoOutputPath(
37653800
_ parsedOptions: inout ParsedOptions,
37663801
moduleOutputPath: VirtualPath.Handle?,
3802+
outputOption: Option,
37673803
compilerOutputType: FileType?,
37683804
compilerMode: CompilerMode,
37693805
outputFileMap: OutputFileMap?,
@@ -3775,7 +3811,7 @@ extension Driver {
37753811
moduleOutputPath: moduleOutputPath,
37763812
type: .swiftSourceInfoFile,
37773813
isOutput: .emitModuleSourceInfo,
3778-
outputPath: .emitModuleSourceInfoPath,
3814+
outputPath: outputOption,
37793815
compilerOutputType: compilerOutputType,
37803816
compilerMode: compilerMode,
37813817
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")
@@ -926,10 +933,6 @@ extension Option {
926933
public static let Xlinker: Option = Option("-Xlinker", .separate, attributes: [.doesNotAffectIncrementalBuild], helpText: "Specifies an option which should be passed to the linker")
927934
public static let Xllvm: Option = Option("-Xllvm", .separate, attributes: [.helpHidden, .frontend], metaVar: "<arg>", helpText: "Pass <arg> to LLVM.")
928935
public static let DASHDASH: Option = Option("--", .remaining, attributes: [.frontend, .doesNotAffectIncrementalBuild])
929-
930-
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")
931-
public static let emitVariantModuleInterface: Option = Option("-emit-variant-module-interface", .flag, attributes: [.noInteractive, .supplementaryOutput], helpText: "Emit an importable module for the target variant")
932-
933936
}
934937

935938
extension Option {
@@ -1301,6 +1304,13 @@ extension Option {
13011304
Option.emitTbdPathEQ,
13021305
Option.emitTbdPath,
13031306
Option.emitTbd,
1307+
Option.emitVariantApiDescriptorPath,
1308+
Option.emitVariantModuleDocPath,
1309+
Option.emitVariantModuleInterfacePath,
1310+
Option.emitVariantModulePath,
1311+
Option.emitVariantModuleSourceInfoPath,
1312+
Option.emitVariantPackageModuleInterfacePath,
1313+
Option.emitVariantPrivateModuleInterfacePath,
13041314
Option.emitVerboseSil,
13051315
Option.emptyAbiDescriptor,
13061316
Option.emptyBaseline,
@@ -1843,8 +1853,6 @@ extension Option {
18431853
Option.Xlinker,
18441854
Option.Xllvm,
18451855
Option.DASHDASH,
1846-
Option.emitVariantModulePath,
1847-
Option.emitVariantModuleInterface,
18481856
]
18491857
}
18501858
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,6 +4147,32 @@ final class SwiftDriverTests: XCTestCase {
41474147
]))
41484148
}
41494149
}
4150+
4151+
do {
4152+
var driver = try Driver(args: ["swiftc",
4153+
"-target", "x86_64-apple-macosx10.14",
4154+
"-target-variant", "x86_64-apple-ios13.1-macabi",
4155+
"-emit-variant-module-path", "foo.swiftmodule/x86_64-apple-ios13.1-macabi.swiftmodule",
4156+
"-enable-library-evolution",
4157+
"-emit-module",
4158+
"-emit-api-descriptor-path", "foo.swiftmodule/target.api.json",
4159+
"-emit-variant-api-descriptor-path", "foo.swiftmodule/variant.api.json",
4160+
"foo.swift"])
4161+
4162+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
4163+
let targetModuleJob = plannedJobs[0]
4164+
let variantModuleJob = plannedJobs[1]
4165+
4166+
XCTAssert(targetModuleJob.commandLine.contains(subsequence: [
4167+
.flag("-emit-api-descriptor-path"),
4168+
.path(.relative(try .init(validating: "foo.swiftmodule/target.api.json")))
4169+
]))
4170+
4171+
XCTAssert(variantModuleJob.commandLine.contains(subsequence: [
4172+
.flag("-emit-api-descriptor-path"),
4173+
.path(.relative(try .init(validating: "foo.swiftmodule/variant.api.json")))
4174+
]))
4175+
}
41504176
#endif
41514177
}
41524178

0 commit comments

Comments
 (0)