Skip to content

Commit e1089b5

Browse files
authored
Merge pull request #149 from DougGregor/respect-driver-use-frontend-path
Respect -driver-use-frontend-path prior to executing -print-target-info.
2 parents c92abde + a4fe002 commit e1089b5

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -251,28 +251,10 @@ public struct Driver {
251251
self.optionTable = OptionTable()
252252
self.parsedOptions = try optionTable.parse(Array(args), for: self.driverKind)
253253

254-
(self.toolchain, self.frontendTargetInfo) = try Self.computeToolchain(
255-
&self.parsedOptions, diagnosticsEngine: diagnosticEngine, env: env,
256-
executor: self.executor, fileSystem: fileSystem)
257-
258-
// Local variable to alias the target triple, because self.targetTriple
259-
// is not available until the end of this initializer.
260-
let targetTriple = self.frontendTargetInfo.target.triple
261-
262-
// Find the Swift compiler executable.
263-
if let frontendPath = self.parsedOptions.getLastArgument(.driverUseFrontendPath) {
264-
var frontendCommandLine = frontendPath.asSingle.split(separator: ";").map { String($0) }
265-
if frontendCommandLine.isEmpty {
266-
self.diagnosticEngine.emit(.error_no_swift_frontend)
267-
self.swiftCompilerPrefixArgs = []
268-
} else {
269-
let frontendPath = frontendCommandLine.removeFirst()
270-
self.toolchain.overrideToolPath(.swiftCompiler, path: try AbsolutePath(validating: frontendPath))
271-
self.swiftCompilerPrefixArgs = frontendCommandLine
272-
}
273-
} else {
274-
self.swiftCompilerPrefixArgs = []
275-
}
254+
(self.toolchain, self.frontendTargetInfo, self.swiftCompilerPrefixArgs) =
255+
try Self.computeToolchain(
256+
&self.parsedOptions, diagnosticsEngine: diagnosticEngine, env: env,
257+
executor: self.executor, fileSystem: fileSystem)
276258

277259
// Compute the working directory.
278260
workingDirectory = try parsedOptions.getLastArgument(.workingDirectory).map { workingDirectoryArg in
@@ -348,6 +330,9 @@ public struct Driver {
348330
actualSwiftVersion: try? toolchain.swiftCompilerVersion()
349331
)
350332

333+
// Local variable to alias the target triple, because self.targetTriple
334+
// is not available until the end of this initializer.
335+
let targetTriple = self.frontendTargetInfo.target.triple
351336
self.sdkPath = Self.computeSDKPath(&parsedOptions, compilerMode: compilerMode, toolchain: toolchain, targetTriple: targetTriple,
352337
fileSystem: fileSystem, diagnosticsEngine: diagnosticEngine, env: env)
353338

@@ -1588,7 +1573,7 @@ extension Driver {
15881573
env: [String: String],
15891574
executor: DriverExecutor,
15901575
fileSystem: FileSystem
1591-
) throws -> (Toolchain, FrontendTargetInfo) {
1576+
) throws -> (Toolchain, FrontendTargetInfo, [String]) {
15921577
let explicitTarget = (parsedOptions.getLastArgument(.target)?.asSingle)
15931578
.map {
15941579
Triple($0, normalizing: true)
@@ -1606,6 +1591,25 @@ extension Driver {
16061591
defaultToolchainType
16071592
let toolchain = toolchainType.init(env: env, executor: executor, fileSystem: fileSystem)
16081593

1594+
// Find the Swift compiler executable.
1595+
let swiftCompilerPrefixArgs: [String]
1596+
if let frontendPath = parsedOptions.getLastArgument(.driverUseFrontendPath){
1597+
var frontendCommandLine =
1598+
frontendPath.asSingle.split(separator: ";").map { String($0) }
1599+
if frontendCommandLine.isEmpty {
1600+
diagnosticsEngine.emit(.error_no_swift_frontend)
1601+
swiftCompilerPrefixArgs = []
1602+
} else {
1603+
let frontendPath = frontendCommandLine.removeFirst()
1604+
toolchain.overrideToolPath(
1605+
.swiftCompiler, path: try AbsolutePath(validating: frontendPath))
1606+
swiftCompilerPrefixArgs = frontendCommandLine
1607+
}
1608+
} else {
1609+
swiftCompilerPrefixArgs = []
1610+
}
1611+
1612+
// Query the frontend to for target information.
16091613
var info = try executor.execute(
16101614
job: toolchain.printTargetInfoJob(
16111615
target: explicitTarget, targetVariant: explicitTargetVariant,
@@ -1629,7 +1633,7 @@ extension Driver {
16291633
}
16301634
}
16311635

1632-
return (toolchain, info)
1636+
return (toolchain, info, swiftCompilerPrefixArgs)
16331637
}
16341638
}
16351639

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ final class SwiftDriverTests: XCTestCase {
14061406

14071407
let expectedDefaultContents: String
14081408
#if os(macOS)
1409-
expectedDefaultContents = "x86_64-apple-"
1409+
expectedDefaultContents = "x86_64-apple-macosx"
14101410
#elseif os(Linux)
14111411
expectedDefaultContents = "-unknown-linux"
14121412
#else
@@ -2387,7 +2387,10 @@ final class SwiftDriverTests: XCTestCase {
23872387
// better override.
23882388
var env = ProcessEnv.vars
23892389
env["SWIFT_DRIVER_SWIFT_HELP_EXEC"] = "/usr/bin/nonexistent-swift-help"
2390-
var driver = try Driver(args: ["swiftc", "-help"], env: env)
2390+
env["SWIFT_DRIVER_CLANG_EXEC"] = "/usr/bin/clang"
2391+
var driver = try Driver(
2392+
args: ["swiftc", "-help"],
2393+
env: env)
23912394
let jobs = try driver.planBuild()
23922395
XCTAssert(jobs.count == 1)
23932396
XCTAssertEqual(jobs.first!.tool.name, "/usr/bin/nonexistent-swift-help")

0 commit comments

Comments
 (0)