Skip to content

Respect -driver-use-frontend-path throughout job creation #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public struct Driver {
case invalidDriverName(String)
case invalidInput(String)
case subcommandPassedToDriver
case relativeFrontendPath(String)
}

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

/// The Swift compiler executable.
public let swiftCompiler: VirtualPath
public let swiftCompiler: AbsolutePath

/// Extra command-line arguments to pass to the Swift compiler.
public let swiftCompilerPrefixArgs: [String]
Expand Down Expand Up @@ -224,13 +225,13 @@ public struct Driver {
let frontendCommandLine = frontendPath.asSingle.split(separator: ";").map { String($0) }
if frontendCommandLine.isEmpty {
self.diagnosticEngine.emit(.error_no_swift_frontend)
self.swiftCompiler = .absolute(try self.toolchain.getToolPath(.swiftCompiler))
self.swiftCompiler = try self.toolchain.getToolPath(.swiftCompiler)
} else {
self.swiftCompiler = try VirtualPath(path: frontendCommandLine.first!)
self.swiftCompiler = try AbsolutePath(validating: frontendCommandLine.first!)
}
self.swiftCompilerPrefixArgs = Array(frontendCommandLine.dropFirst())
} else {
self.swiftCompiler = .absolute(try self.toolchain.getToolPath(.swiftCompiler))
self.swiftCompiler = try self.toolchain.getToolPath(.swiftCompiler)
self.swiftCompilerPrefixArgs = []
}

Expand Down Expand Up @@ -286,7 +287,8 @@ public struct Driver {
moduleOutput: self.moduleOutput,
inputFiles: inputFiles,
diagnosticEngine: diagnosticEngine,
actualSwiftVersion: try? toolchain.swiftCompilerVersion()
actualSwiftVersion:
try? toolchain.swiftCompilerVersion(self.swiftCompiler)
)

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

self.enabledSanitizers = try Self.parseSanitizerArgValues(&parsedOptions, diagnosticEngine: diagnosticEngine, toolchain: toolchain, targetTriple: targetTriple)
self.enabledSanitizers = try Self.parseSanitizerArgValues(
&parsedOptions, diagnosticEngine: diagnosticEngine,
toolchain: toolchain, targetTriple: targetTriple,
swiftCompiler: swiftCompiler)

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

Expand Down Expand Up @@ -603,12 +607,6 @@ extension Driver {
try jobExecutor.execute(env: env)
}

/// Returns the path to the Swift binary.
func getSwiftCompilerPath() throws -> AbsolutePath {
// FIXME: This is very preliminary. Need to figure out how to get the actual Swift executable path.
try toolchain.getToolPath(.swiftCompiler)
}

public mutating func createToolExecutionDelegate() -> ToolExecutionDelegate {
var mode: ToolExecutionDelegate.Mode = .regular

Expand Down Expand Up @@ -1018,7 +1016,8 @@ extension Driver {
_ parsedOptions: inout ParsedOptions,
diagnosticEngine: DiagnosticsEngine,
toolchain: Toolchain,
targetTriple: Triple
targetTriple: Triple,
swiftCompiler: AbsolutePath
) throws -> Set<Sanitizer> {

var set = Set<Sanitizer>()
Expand All @@ -1043,6 +1042,7 @@ extension Driver {
for: sanitizer,
targetTriple: targetTriple,
parsedOptions: &parsedOptions,
swiftCompiler: swiftCompiler,
isShared: sanitizer != .fuzzer
)

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/CompileJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ extension Driver {

return Job(
kind: .compile,
tool: swiftCompiler,
tool: .absolute(swiftCompiler),
commandLine: commandLine,
displayInputs: primaryInputs,
inputs: inputs,
Expand Down
37 changes: 27 additions & 10 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import TSCBasic

extension DarwinToolchain {
private func findARCLiteLibPath() throws -> AbsolutePath? {
let path = try getToolPath(.swiftCompiler)
private func findARCLiteLibPath(swiftCompiler: AbsolutePath) throws
-> AbsolutePath? {
let path = swiftCompiler
.parentDirectory // 'swift'
.parentDirectory // 'bin'
.appending(components: "lib", "arc")
Expand All @@ -35,6 +36,7 @@ extension DarwinToolchain {
to commandLine: inout [Job.ArgTemplate],
parsedOptions: inout ParsedOptions,
targetTriple: Triple,
swiftCompiler: AbsolutePath,
darwinLibName: String
) throws {
// Adding the rpaths might negatively interact when other rpaths are involved,
Expand All @@ -52,7 +54,9 @@ extension DarwinToolchain {
// from the default location without copying.


let clangPath = try clangLibraryPath(for: targetTriple, parsedOptions: &parsedOptions)
let clangPath = try clangLibraryPath(
for: targetTriple, swiftCompiler: swiftCompiler,
parsedOptions: &parsedOptions)
commandLine.appendFlag("-rpath")
commandLine.appendPath(clangPath)
}
Expand All @@ -61,6 +65,7 @@ extension DarwinToolchain {
to commandLine: inout [Job.ArgTemplate],
parsedOptions: inout ParsedOptions,
targetTriple: Triple,
swiftCompiler: AbsolutePath,
sanitizer: Sanitizer,
isShared: Bool
) throws {
Expand All @@ -79,14 +84,16 @@ extension DarwinToolchain {
named: sanitizerName,
to: &commandLine,
for: targetTriple,
parsedOptions: &parsedOptions
parsedOptions: &parsedOptions,
swiftCompiler: swiftCompiler
)

if isShared {
try addLinkRuntimeLibraryRPath(
to: &commandLine,
parsedOptions: &parsedOptions,
targetTriple: targetTriple,
swiftCompiler: swiftCompiler,
darwinLibName: sanitizerName
)
}
Expand All @@ -95,10 +102,12 @@ extension DarwinToolchain {
private func addProfileGenerationArgs(
to commandLine: inout [Job.ArgTemplate],
parsedOptions: inout ParsedOptions,
targetTriple: Triple
targetTriple: Triple,
swiftCompiler: AbsolutePath
) throws {
guard parsedOptions.hasArgument(.profileGenerate) else { return }
let clangPath = try clangLibraryPath(for: targetTriple,
swiftCompiler: swiftCompiler,
parsedOptions: &parsedOptions)

let runtime = targetTriple.darwinPlatform!.libraryNameSuffix
Expand Down Expand Up @@ -141,6 +150,7 @@ extension DarwinToolchain {
private func addArgsToLinkARCLite(
to commandLine: inout [Job.ArgTemplate],
parsedOptions: inout ParsedOptions,
swiftCompiler: AbsolutePath,
targetTriple: Triple
) throws {
guard parsedOptions.hasFlag(
Expand All @@ -151,7 +161,8 @@ extension DarwinToolchain {
return
}

guard let arcLiteLibPath = try findARCLiteLibPath(),
guard let arcLiteLibPath = try findARCLiteLibPath(
swiftCompiler: swiftCompiler),
let platformName = targetTriple.platformName() else {
return
}
Expand All @@ -176,7 +187,8 @@ extension DarwinToolchain {
outputFile: VirtualPath,
sdkPath: String?,
sanitizers: Set<Sanitizer>,
targetTriple: Triple
targetTriple: Triple,
swiftCompiler: AbsolutePath
) throws -> AbsolutePath {

// FIXME: If we used Clang as a linker instead of going straight to ld,
Expand All @@ -192,7 +204,8 @@ extension DarwinToolchain {
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
let compilerRTPath =
try clangLibraryPath(
for: targetTriple, parsedOptions: &parsedOptions)
for: targetTriple, swiftCompiler: swiftCompiler,
parsedOptions: &parsedOptions)
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
if localFileSystem.exists(compilerRTPath) {
commandLine.append(.path(.absolute(compilerRTPath)))
Expand Down Expand Up @@ -224,6 +237,7 @@ extension DarwinToolchain {
to: &commandLine,
parsedOptions: &parsedOptions,
targetTriple: targetTriple,
swiftCompiler: swiftCompiler,
sanitizer: sanitizer,
isShared: sanitizer != .fuzzer
)
Expand All @@ -236,7 +250,8 @@ extension DarwinToolchain {
to: &commandLine,
parsedOptions: &parsedOptions,
sdkPath: sdkPath,
targetTriple: targetTriple
targetTriple: targetTriple,
swiftCompiler: swiftCompiler
)

// These custom arguments should be right before the object file at the
Expand All @@ -255,6 +270,7 @@ extension DarwinToolchain {
try addArgsToLinkARCLite(
to: &commandLine,
parsedOptions: &parsedOptions,
swiftCompiler: swiftCompiler,
targetTriple: targetTriple
)
addDeploymentTargetArgs(
Expand All @@ -264,7 +280,8 @@ extension DarwinToolchain {
try addProfileGenerationArgs(
to: &commandLine,
parsedOptions: &parsedOptions,
targetTriple: targetTriple
targetTriple: targetTriple,
swiftCompiler: swiftCompiler
)

commandLine.appendFlags(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/EmitModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension Driver {

return Job(
kind: .emitModule,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: .absolute(swiftCompiler),
commandLine: commandLine,
inputs: inputs,
outputs: outputs
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/GeneratePCHJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension Driver {

return Job(
kind: .generatePCH,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: .absolute(swiftCompiler),
commandLine: commandLine,
displayInputs: [],
inputs: inputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ extension GenericUnixToolchain {
outputFile: VirtualPath,
sdkPath: String?,
sanitizers: Set<Sanitizer>,
targetTriple: Triple
targetTriple: Triple,
swiftCompiler: AbsolutePath
) throws -> AbsolutePath {
switch linkerOutputType {
case .dynamicLibrary:
Expand Down Expand Up @@ -129,7 +130,7 @@ extension GenericUnixToolchain {
let runtimePaths = try runtimeLibraryPaths(
for: targetTriple,
parsedOptions: &parsedOptions,
sdkPath: sdkPath,
sdkPath: sdkPath, swiftCompiler: swiftCompiler,
isShared: hasRuntimeArgs
)

Expand All @@ -147,6 +148,7 @@ extension GenericUnixToolchain {
let sharedResourceDirPath = try computeResourceDirPath(
for: targetTriple,
parsedOptions: &parsedOptions,
swiftCompiler: swiftCompiler,
isShared: true
)

Expand Down Expand Up @@ -192,6 +194,7 @@ extension GenericUnixToolchain {
var linkFilePath: AbsolutePath? = try computeResourceDirPath(
for: targetTriple,
parsedOptions: &parsedOptions,
swiftCompiler: swiftCompiler,
isShared: false
)

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/InterpretJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ extension Driver {

let extraEnvironment = try toolchain.platformSpecificInterpreterEnvironmentVariables(
env: self.env, parsedOptions: &parsedOptions, sdkPath: self.sdkPath,
targetTriple: self.targetTriple)
targetTriple: self.targetTriple, swiftCompiler: self.swiftCompiler)

return Job(
kind: .interpret,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: .absolute(swiftCompiler),
commandLine: commandLine,
inputs:inputs,
outputs: [],
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Jobs/LinkJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ extension Driver {
outputFile: outputFile,
sdkPath: sdkPath,
sanitizers: enabledSanitizers,
targetTriple: targetTriple
targetTriple: targetTriple,
swiftCompiler: swiftCompiler
)

return Job(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/MergeModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension Driver {

return Job(
kind: .mergeModule,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: .absolute(swiftCompiler),
commandLine: commandLine,
inputs: inputs,
outputs: outputs
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/ReplJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension Driver {
commandLine.appendFlags("-module-name", moduleName)
return Job(
kind: .repl,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: .absolute(swiftCompiler),
commandLine: commandLine,
inputs: [],
outputs: [],
Expand Down
10 changes: 7 additions & 3 deletions Sources/SwiftDriver/Jobs/Toolchain+InterpreterSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//
//
import TSCBasic

extension Toolchain {
func addPathEnvironmentVariableIfNeeded(
Expand All @@ -33,13 +34,14 @@ extension DarwinToolchain {
env: [String : String],
parsedOptions: inout ParsedOptions,
sdkPath: String?,
targetTriple: Triple) throws -> [String: String] {
targetTriple: Triple,
swiftCompiler: AbsolutePath) throws -> [String: String] {
var envVars: [String: String] = [:]

let runtimePaths = try runtimeLibraryPaths(
for: targetTriple,
parsedOptions: &parsedOptions,
sdkPath: sdkPath,
sdkPath: sdkPath, swiftCompiler: swiftCompiler,
isShared: true
).map { $0.pathString }

Expand All @@ -61,13 +63,15 @@ extension GenericUnixToolchain {
env: [String : String],
parsedOptions: inout ParsedOptions,
sdkPath: String?,
targetTriple: Triple) throws -> [String: String] {
targetTriple: Triple,
swiftCompiler: AbsolutePath) throws -> [String: String] {
var envVars: [String: String] = [:]

let runtimePaths = try runtimeLibraryPaths(
for: targetTriple,
parsedOptions: &parsedOptions,
sdkPath: sdkPath,
swiftCompiler: swiftCompiler,
isShared: true
).map { $0.pathString }

Expand Down
Loading