Skip to content

Commit c356d50

Browse files
authored
Merge pull request #50 from DougGregor/driver-use-frontend-path
Respect -driver-use-frontend-path throughout job creation
2 parents 52eff70 + 6b0a92b commit c356d50

14 files changed

+92
-48
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public struct Driver {
4444
case invalidDriverName(String)
4545
case invalidInput(String)
4646
case subcommandPassedToDriver
47+
case relativeFrontendPath(String)
4748
}
4849

4950
/// The set of environment variables that are visible to the driver and
@@ -70,7 +71,7 @@ public struct Driver {
7071
var parsedOptions: ParsedOptions
7172

7273
/// The Swift compiler executable.
73-
public let swiftCompiler: VirtualPath
74+
public let swiftCompiler: AbsolutePath
7475

7576
/// Extra command-line arguments to pass to the Swift compiler.
7677
public let swiftCompilerPrefixArgs: [String]
@@ -224,13 +225,13 @@ public struct Driver {
224225
let frontendCommandLine = frontendPath.asSingle.split(separator: ";").map { String($0) }
225226
if frontendCommandLine.isEmpty {
226227
self.diagnosticEngine.emit(.error_no_swift_frontend)
227-
self.swiftCompiler = .absolute(try self.toolchain.getToolPath(.swiftCompiler))
228+
self.swiftCompiler = try self.toolchain.getToolPath(.swiftCompiler)
228229
} else {
229-
self.swiftCompiler = try VirtualPath(path: frontendCommandLine.first!)
230+
self.swiftCompiler = try AbsolutePath(validating: frontendCommandLine.first!)
230231
}
231232
self.swiftCompilerPrefixArgs = Array(frontendCommandLine.dropFirst())
232233
} else {
233-
self.swiftCompiler = .absolute(try self.toolchain.getToolPath(.swiftCompiler))
234+
self.swiftCompiler = try self.toolchain.getToolPath(.swiftCompiler)
234235
self.swiftCompilerPrefixArgs = []
235236
}
236237

@@ -286,7 +287,8 @@ public struct Driver {
286287
moduleOutput: self.moduleOutput,
287288
inputFiles: inputFiles,
288289
diagnosticEngine: diagnosticEngine,
289-
actualSwiftVersion: try? toolchain.swiftCompilerVersion()
290+
actualSwiftVersion:
291+
try? toolchain.swiftCompilerVersion(self.swiftCompiler)
290292
)
291293

292294
self.sdkPath = Self.computeSDKPath(&parsedOptions, compilerMode: compilerMode, toolchain: toolchain, diagnosticsEngine: diagnosticEngine, env: env)
@@ -296,7 +298,10 @@ public struct Driver {
296298
importedObjCHeader: importedObjCHeader,
297299
outputFileMap: outputFileMap)
298300

299-
self.enabledSanitizers = try Self.parseSanitizerArgValues(&parsedOptions, diagnosticEngine: diagnosticEngine, toolchain: toolchain, targetTriple: targetTriple)
301+
self.enabledSanitizers = try Self.parseSanitizerArgValues(
302+
&parsedOptions, diagnosticEngine: diagnosticEngine,
303+
toolchain: toolchain, targetTriple: targetTriple,
304+
swiftCompiler: swiftCompiler)
300305

301306
// Supplemental outputs.
302307
self.dependenciesFilePath = try Self.computeSupplementaryOutputPath(
@@ -557,7 +562,6 @@ extension Driver {
557562
) throws {
558563
// We just need to invoke the corresponding tool if the kind isn't Swift compiler.
559564
guard driverKind.isSwiftCompiler else {
560-
let swiftCompiler = try getSwiftCompilerPath()
561565
return try exec(path: swiftCompiler.pathString, args: driverKind.usageArgs + parsedOptions.commandLine)
562566
}
563567

@@ -603,12 +607,6 @@ extension Driver {
603607
try jobExecutor.execute(env: env)
604608
}
605609

606-
/// Returns the path to the Swift binary.
607-
func getSwiftCompilerPath() throws -> AbsolutePath {
608-
// FIXME: This is very preliminary. Need to figure out how to get the actual Swift executable path.
609-
try toolchain.getToolPath(.swiftCompiler)
610-
}
611-
612610
public mutating func createToolExecutionDelegate() -> ToolExecutionDelegate {
613611
var mode: ToolExecutionDelegate.Mode = .regular
614612

@@ -1018,7 +1016,8 @@ extension Driver {
10181016
_ parsedOptions: inout ParsedOptions,
10191017
diagnosticEngine: DiagnosticsEngine,
10201018
toolchain: Toolchain,
1021-
targetTriple: Triple
1019+
targetTriple: Triple,
1020+
swiftCompiler: AbsolutePath
10221021
) throws -> Set<Sanitizer> {
10231022

10241023
var set = Set<Sanitizer>()
@@ -1043,6 +1042,7 @@ extension Driver {
10431042
for: sanitizer,
10441043
targetTriple: targetTriple,
10451044
parsedOptions: &parsedOptions,
1045+
swiftCompiler: swiftCompiler,
10461046
isShared: sanitizer != .fuzzer
10471047
)
10481048

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extension Driver {
154154

155155
return Job(
156156
kind: .compile,
157-
tool: swiftCompiler,
157+
tool: .absolute(swiftCompiler),
158158
commandLine: commandLine,
159159
displayInputs: primaryInputs,
160160
inputs: inputs,

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import TSCBasic
1313

1414
extension DarwinToolchain {
15-
private func findARCLiteLibPath() throws -> AbsolutePath? {
16-
let path = try getToolPath(.swiftCompiler)
15+
private func findARCLiteLibPath(swiftCompiler: AbsolutePath) throws
16+
-> AbsolutePath? {
17+
let path = swiftCompiler
1718
.parentDirectory // 'swift'
1819
.parentDirectory // 'bin'
1920
.appending(components: "lib", "arc")
@@ -35,6 +36,7 @@ extension DarwinToolchain {
3536
to commandLine: inout [Job.ArgTemplate],
3637
parsedOptions: inout ParsedOptions,
3738
targetTriple: Triple,
39+
swiftCompiler: AbsolutePath,
3840
darwinLibName: String
3941
) throws {
4042
// Adding the rpaths might negatively interact when other rpaths are involved,
@@ -52,7 +54,9 @@ extension DarwinToolchain {
5254
// from the default location without copying.
5355

5456

55-
let clangPath = try clangLibraryPath(for: targetTriple, parsedOptions: &parsedOptions)
57+
let clangPath = try clangLibraryPath(
58+
for: targetTriple, swiftCompiler: swiftCompiler,
59+
parsedOptions: &parsedOptions)
5660
commandLine.appendFlag("-rpath")
5761
commandLine.appendPath(clangPath)
5862
}
@@ -61,6 +65,7 @@ extension DarwinToolchain {
6165
to commandLine: inout [Job.ArgTemplate],
6266
parsedOptions: inout ParsedOptions,
6367
targetTriple: Triple,
68+
swiftCompiler: AbsolutePath,
6469
sanitizer: Sanitizer,
6570
isShared: Bool
6671
) throws {
@@ -79,14 +84,16 @@ extension DarwinToolchain {
7984
named: sanitizerName,
8085
to: &commandLine,
8186
for: targetTriple,
82-
parsedOptions: &parsedOptions
87+
parsedOptions: &parsedOptions,
88+
swiftCompiler: swiftCompiler
8389
)
8490

8591
if isShared {
8692
try addLinkRuntimeLibraryRPath(
8793
to: &commandLine,
8894
parsedOptions: &parsedOptions,
8995
targetTriple: targetTriple,
96+
swiftCompiler: swiftCompiler,
9097
darwinLibName: sanitizerName
9198
)
9299
}
@@ -95,10 +102,12 @@ extension DarwinToolchain {
95102
private func addProfileGenerationArgs(
96103
to commandLine: inout [Job.ArgTemplate],
97104
parsedOptions: inout ParsedOptions,
98-
targetTriple: Triple
105+
targetTriple: Triple,
106+
swiftCompiler: AbsolutePath
99107
) throws {
100108
guard parsedOptions.hasArgument(.profileGenerate) else { return }
101109
let clangPath = try clangLibraryPath(for: targetTriple,
110+
swiftCompiler: swiftCompiler,
102111
parsedOptions: &parsedOptions)
103112

104113
let runtime = targetTriple.darwinPlatform!.libraryNameSuffix
@@ -141,6 +150,7 @@ extension DarwinToolchain {
141150
private func addArgsToLinkARCLite(
142151
to commandLine: inout [Job.ArgTemplate],
143152
parsedOptions: inout ParsedOptions,
153+
swiftCompiler: AbsolutePath,
144154
targetTriple: Triple
145155
) throws {
146156
guard parsedOptions.hasFlag(
@@ -151,7 +161,8 @@ extension DarwinToolchain {
151161
return
152162
}
153163

154-
guard let arcLiteLibPath = try findARCLiteLibPath(),
164+
guard let arcLiteLibPath = try findARCLiteLibPath(
165+
swiftCompiler: swiftCompiler),
155166
let platformName = targetTriple.platformName() else {
156167
return
157168
}
@@ -176,7 +187,8 @@ extension DarwinToolchain {
176187
outputFile: VirtualPath,
177188
sdkPath: String?,
178189
sanitizers: Set<Sanitizer>,
179-
targetTriple: Triple
190+
targetTriple: Triple,
191+
swiftCompiler: AbsolutePath
180192
) throws -> AbsolutePath {
181193

182194
// FIXME: If we used Clang as a linker instead of going straight to ld,
@@ -192,7 +204,8 @@ extension DarwinToolchain {
192204
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
193205
let compilerRTPath =
194206
try clangLibraryPath(
195-
for: targetTriple, parsedOptions: &parsedOptions)
207+
for: targetTriple, swiftCompiler: swiftCompiler,
208+
parsedOptions: &parsedOptions)
196209
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
197210
if localFileSystem.exists(compilerRTPath) {
198211
commandLine.append(.path(.absolute(compilerRTPath)))
@@ -224,6 +237,7 @@ extension DarwinToolchain {
224237
to: &commandLine,
225238
parsedOptions: &parsedOptions,
226239
targetTriple: targetTriple,
240+
swiftCompiler: swiftCompiler,
227241
sanitizer: sanitizer,
228242
isShared: sanitizer != .fuzzer
229243
)
@@ -236,7 +250,8 @@ extension DarwinToolchain {
236250
to: &commandLine,
237251
parsedOptions: &parsedOptions,
238252
sdkPath: sdkPath,
239-
targetTriple: targetTriple
253+
targetTriple: targetTriple,
254+
swiftCompiler: swiftCompiler
240255
)
241256

242257
// These custom arguments should be right before the object file at the
@@ -255,6 +270,7 @@ extension DarwinToolchain {
255270
try addArgsToLinkARCLite(
256271
to: &commandLine,
257272
parsedOptions: &parsedOptions,
273+
swiftCompiler: swiftCompiler,
258274
targetTriple: targetTriple
259275
)
260276
addDeploymentTargetArgs(
@@ -264,7 +280,8 @@ extension DarwinToolchain {
264280
try addProfileGenerationArgs(
265281
to: &commandLine,
266282
parsedOptions: &parsedOptions,
267-
targetTriple: targetTriple
283+
targetTriple: targetTriple,
284+
swiftCompiler: swiftCompiler
268285
)
269286

270287
commandLine.appendFlags(

Sources/SwiftDriver/Jobs/EmitModuleJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension Driver {
7070

7171
return Job(
7272
kind: .emitModule,
73-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
73+
tool: .absolute(swiftCompiler),
7474
commandLine: commandLine,
7575
inputs: inputs,
7676
outputs: outputs

Sources/SwiftDriver/Jobs/GeneratePCHJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension Driver {
5858

5959
return Job(
6060
kind: .generatePCH,
61-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
61+
tool: .absolute(swiftCompiler),
6262
commandLine: commandLine,
6363
displayInputs: [],
6464
inputs: inputs,

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ extension GenericUnixToolchain {
5050
outputFile: VirtualPath,
5151
sdkPath: String?,
5252
sanitizers: Set<Sanitizer>,
53-
targetTriple: Triple
53+
targetTriple: Triple,
54+
swiftCompiler: AbsolutePath
5455
) throws -> AbsolutePath {
5556
switch linkerOutputType {
5657
case .dynamicLibrary:
@@ -129,7 +130,7 @@ extension GenericUnixToolchain {
129130
let runtimePaths = try runtimeLibraryPaths(
130131
for: targetTriple,
131132
parsedOptions: &parsedOptions,
132-
sdkPath: sdkPath,
133+
sdkPath: sdkPath, swiftCompiler: swiftCompiler,
133134
isShared: hasRuntimeArgs
134135
)
135136

@@ -147,6 +148,7 @@ extension GenericUnixToolchain {
147148
let sharedResourceDirPath = try computeResourceDirPath(
148149
for: targetTriple,
149150
parsedOptions: &parsedOptions,
151+
swiftCompiler: swiftCompiler,
150152
isShared: true
151153
)
152154

@@ -192,6 +194,7 @@ extension GenericUnixToolchain {
192194
var linkFilePath: AbsolutePath? = try computeResourceDirPath(
193195
for: targetTriple,
194196
parsedOptions: &parsedOptions,
197+
swiftCompiler: swiftCompiler,
195198
isShared: false
196199
)
197200

Sources/SwiftDriver/Jobs/InterpretJob.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ extension Driver {
3838

3939
let extraEnvironment = try toolchain.platformSpecificInterpreterEnvironmentVariables(
4040
env: self.env, parsedOptions: &parsedOptions, sdkPath: self.sdkPath,
41-
targetTriple: self.targetTriple)
41+
targetTriple: self.targetTriple, swiftCompiler: self.swiftCompiler)
4242

4343
return Job(
4444
kind: .interpret,
45-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
45+
tool: .absolute(swiftCompiler),
4646
commandLine: commandLine,
4747
inputs:inputs,
4848
outputs: [],

Sources/SwiftDriver/Jobs/LinkJob.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ extension Driver {
4848
outputFile: outputFile,
4949
sdkPath: sdkPath,
5050
sanitizers: enabledSanitizers,
51-
targetTriple: targetTriple
51+
targetTriple: targetTriple,
52+
swiftCompiler: swiftCompiler
5253
)
5354

5455
return Job(

Sources/SwiftDriver/Jobs/MergeModuleJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension Driver {
5151

5252
return Job(
5353
kind: .mergeModule,
54-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
54+
tool: .absolute(swiftCompiler),
5555
commandLine: commandLine,
5656
inputs: inputs,
5757
outputs: outputs

Sources/SwiftDriver/Jobs/ReplJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension Driver {
4141
commandLine.appendFlags("-module-name", moduleName)
4242
return Job(
4343
kind: .repl,
44-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
44+
tool: .absolute(swiftCompiler),
4545
commandLine: commandLine,
4646
inputs: [],
4747
outputs: [],

Sources/SwiftDriver/Jobs/Toolchain+InterpreterSupport.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13+
import TSCBasic
1314

1415
extension Toolchain {
1516
func addPathEnvironmentVariableIfNeeded(
@@ -33,13 +34,14 @@ extension DarwinToolchain {
3334
env: [String : String],
3435
parsedOptions: inout ParsedOptions,
3536
sdkPath: String?,
36-
targetTriple: Triple) throws -> [String: String] {
37+
targetTriple: Triple,
38+
swiftCompiler: AbsolutePath) throws -> [String: String] {
3739
var envVars: [String: String] = [:]
3840

3941
let runtimePaths = try runtimeLibraryPaths(
4042
for: targetTriple,
4143
parsedOptions: &parsedOptions,
42-
sdkPath: sdkPath,
44+
sdkPath: sdkPath, swiftCompiler: swiftCompiler,
4345
isShared: true
4446
).map { $0.pathString }
4547

@@ -61,13 +63,15 @@ extension GenericUnixToolchain {
6163
env: [String : String],
6264
parsedOptions: inout ParsedOptions,
6365
sdkPath: String?,
64-
targetTriple: Triple) throws -> [String: String] {
66+
targetTriple: Triple,
67+
swiftCompiler: AbsolutePath) throws -> [String: String] {
6568
var envVars: [String: String] = [:]
6669

6770
let runtimePaths = try runtimeLibraryPaths(
6871
for: targetTriple,
6972
parsedOptions: &parsedOptions,
7073
sdkPath: sdkPath,
74+
swiftCompiler: swiftCompiler,
7175
isShared: true
7276
).map { $0.pathString }
7377

0 commit comments

Comments
 (0)