Skip to content

Commit 9afe294

Browse files
authored
Merge pull request #627 from nkcsgexi/pass-down-user-module-ver
Pass-down -user-module-version to compiler if the compiler supports it
2 parents 5156317 + 5027824 commit 9afe294

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ public struct Driver {
329329
.appending(component: "Frameworks")
330330
} ()
331331

332+
public func isFrontendArgSupported(_ opt: Option) -> Bool {
333+
var current = opt.spelling
334+
while(true) {
335+
if supportedFrontendFlags.contains(current) {
336+
return true
337+
}
338+
if current.starts(with: "-") {
339+
current = String(current.dropFirst())
340+
} else {
341+
return false
342+
}
343+
}
344+
}
345+
332346
/// Handler for emitting diagnostics to stderr.
333347
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
334348
stdErrQueue.sync {

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ extension Driver {
180180
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)
181181
try commandLine.appendAll(.coveragePrefixMap, from: &parsedOptions)
182182

183+
// Pass down -user-module-version if we are working with a compiler that
184+
// supports it.
185+
if let ver = parsedOptions.getLastArgument(.userModuleVersion)?.asSingle,
186+
isFrontendArgSupported(.userModuleVersion) {
187+
commandLine.appendFlag(.userModuleVersion)
188+
commandLine.appendFlag(ver)
189+
}
190+
183191
if let workingDirectory = workingDirectory {
184192
// Add -Xcc -working-directory before any other -Xcc options to ensure it is
185193
// overridden by an explicit -Xcc -working-directory, although having a

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,21 @@ final class SwiftDriverTests: XCTestCase {
36173617
}
36183618
}
36193619

3620+
func testUserModuleVersion() throws {
3621+
do {
3622+
var driver = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
3623+
"foo", "-user-module-version", "12.21"])
3624+
let plannedJobs = try driver.planBuild()
3625+
XCTAssertEqual(plannedJobs.count, 2)
3626+
let compileJob = plannedJobs[0]
3627+
let mergeJob = plannedJobs[1]
3628+
XCTAssertEqual(compileJob.kind, .compile)
3629+
XCTAssertEqual(mergeJob.kind, .mergeModule)
3630+
XCTAssertTrue(mergeJob.commandLine.contains(.flag("-user-module-version")))
3631+
XCTAssertTrue(mergeJob.commandLine.contains(.flag("12.21")))
3632+
}
3633+
}
3634+
36203635
func testVerifyEmittedInterfaceJob() throws {
36213636
// Evolution enabled
36223637
do {

0 commit comments

Comments
 (0)