From 2f399445f88c34e7377596f83fbb45dda7b50e8f Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Tue, 14 Nov 2023 13:19:02 -0800 Subject: [PATCH] Add fallback to auxiliary legacy driver executable on '--disallow-use-new-driver' With the swift-driver executable becoming the default target of 'swift' and 'swiftc' sumlinks, we need to allow for the prior mechanism afforded by this flag --- Sources/swift-driver/main.swift | 14 ++++++++++++++ Tests/SwiftDriverTests/IntegrationTests.swift | 1 + 2 files changed, 15 insertions(+) diff --git a/Sources/swift-driver/main.swift b/Sources/swift-driver/main.swift index 69448fed5..f16055ede 100644 --- a/Sources/swift-driver/main.swift +++ b/Sources/swift-driver/main.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import SwiftDriverExecution import SwiftDriver +import SwiftOptions #if os(Windows) import CRT #elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS) @@ -65,6 +66,19 @@ do { } interruptSignalSource.resume() + // Fallback to legacy driver if forced to + if CommandLine.arguments.contains(Option.disallowForwardingDriver.spelling) || + ProcessEnv.vars["SWIFT_USE_OLD_DRIVER"] != nil { + if let legacyExecutablePath = Process.findExecutable(CommandLine.arguments[0] + "-legacy-driver"), + localFileSystem.exists(legacyExecutablePath) { + let legacyDriverCommand = [legacyExecutablePath.pathString] + + CommandLine.arguments[1...] + try exec(path: legacyExecutablePath.pathString, args: legacyDriverCommand) + } else { + throw Driver.Error.unknownOrMissingSubcommand(CommandLine.arguments[0] + "-legacy-driver") + } + } + if ProcessEnv.vars["SWIFT_ENABLE_EXPLICIT_MODULE"] != nil { CommandLine.arguments.append("-explicit-module-build") } diff --git a/Tests/SwiftDriverTests/IntegrationTests.swift b/Tests/SwiftDriverTests/IntegrationTests.swift index 414d888d5..17be025c4 100644 --- a/Tests/SwiftDriverTests/IntegrationTests.swift +++ b/Tests/SwiftDriverTests/IntegrationTests.swift @@ -224,6 +224,7 @@ final class IntegrationTests: IntegrationTestCase { let extraEnv = [ "SWIFT": swift.pathString, "SWIFTC": swiftc.pathString, + "SWIFT_FORCE_TEST_NEW_DRIVER": "1", "SWIFT_DRIVER_SWIFT_EXEC": swiftFile.pathString, "SWIFT_DRIVER_SWIFT_FRONTEND_EXEC": frontendFile.pathString, "LC_ALL": "en_US.UTF-8"