Skip to content

Remove computeResourceDirPath and rely on the one reported by -print-target-info #354

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 3 commits into from
Nov 11, 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
30 changes: 21 additions & 9 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public struct Driver {
frontendTargetInfo.targetVariant?.triple
}

/// `true` if the driver should use the static resource directory.
let useStaticResourceDir: Bool

/// The kind of driver.
let driverKind: DriverKind

Expand Down Expand Up @@ -342,12 +345,21 @@ public struct Driver {
try Self.applyWorkingDirectory(workingDirectory, to: &self.parsedOptions)
}

let staticExecutable = parsedOptions.hasFlag(positive: .staticExecutable,
negative: .noStaticExecutable,
default: false)
let staticStdlib = parsedOptions.hasFlag(positive: .staticStdlib,
negative: .noStaticStdlib,
default: false)
self.useStaticResourceDir = staticExecutable || staticStdlib

// Build the toolchain and determine target information.
(self.toolchain, self.frontendTargetInfo, self.swiftCompilerPrefixArgs) =
try Self.computeToolchain(
&self.parsedOptions, diagnosticsEngine: diagnosticEngine,
compilerMode: self.compilerMode, env: env,
executor: self.executor, fileSystem: fileSystem)
executor: self.executor, fileSystem: fileSystem,
useStaticResourceDir: self.useStaticResourceDir)

// Classify and collect all of the input files.
let inputFiles = try Self.collectInputFiles(&self.parsedOptions)
Expand Down Expand Up @@ -439,10 +451,6 @@ public struct Driver {
parsedOptions: &parsedOptions,
showJobLifecycle: showJobLifecycle)

// Local variable to alias the target triple, because self.targetTriple
// is not available until the end of this initializer.
let targetTriple = self.frontendTargetInfo.target.triple

self.importedObjCHeader = try Self.computeImportedObjCHeader(&parsedOptions, compilerMode: compilerMode, diagnosticEngine: diagnosticEngine)
self.bridgingPrecompiledHeader = try Self.computeBridgingPrecompiledHeader(&parsedOptions,
compilerMode: compilerMode,
Expand All @@ -453,7 +461,7 @@ public struct Driver {
&parsedOptions,
diagnosticEngine: diagnosticEngine,
toolchain: toolchain,
targetTriple: targetTriple)
targetInfo: frontendTargetInfo)

// Supplemental outputs.
self.dependenciesFilePath = try Self.computeSupplementaryOutputPath(
Expand Down Expand Up @@ -1446,7 +1454,7 @@ extension Driver {
_ parsedOptions: inout ParsedOptions,
diagnosticEngine: DiagnosticsEngine,
toolchain: Toolchain,
targetTriple: Triple
targetInfo: FrontendTargetInfo
) throws -> Set<Sanitizer> {

var set = Set<Sanitizer>()
Expand All @@ -1459,6 +1467,8 @@ extension Driver {
if args.isEmpty {
return set
}

let targetTriple = targetInfo.target.triple
// Find the sanitizer kind.
for arg in args {
guard let sanitizer = Sanitizer(rawValue: arg) else {
Expand All @@ -1473,7 +1483,7 @@ extension Driver {
// enabled.
var sanitizerSupported = try toolchain.runtimeLibraryExists(
for: sanitizer,
targetTriple: targetTriple,
targetInfo: targetInfo,
parsedOptions: &parsedOptions,
isShared: sanitizer != .fuzzer
)
Expand Down Expand Up @@ -1935,7 +1945,8 @@ extension Driver {
compilerMode: CompilerMode,
env: [String: String],
executor: DriverExecutor,
fileSystem: FileSystem
fileSystem: FileSystem,
useStaticResourceDir: Bool
) throws -> (Toolchain, FrontendTargetInfo, [String]) {
let explicitTarget = (parsedOptions.getLastArgument(.target)?.asSingle)
.map {
Expand Down Expand Up @@ -1997,6 +2008,7 @@ extension Driver {
sdkPath: sdkPath, resourceDirPath: resourceDirPath,
runtimeCompatibilityVersion:
parsedOptions.getLastArgument(.runtimeCompatibilityVersion)?.asSingle,
useStaticResourceDir: useStaticResourceDir,
swiftCompilerPrefixArgs: swiftCompilerPrefixArgs
),
capturingJSONOutputAs: FrontendTargetInfo.self,
Expand Down
24 changes: 12 additions & 12 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension DarwinToolchain {
func addLinkRuntimeLibraryRPath(
to commandLine: inout [Job.ArgTemplate],
parsedOptions: inout ParsedOptions,
targetTriple: Triple,
targetInfo: FrontendTargetInfo,
darwinLibName: String
) throws {
// Adding the rpaths might negatively interact when other rpaths are involved,
Expand All @@ -66,7 +66,7 @@ extension DarwinToolchain {


let clangPath = try clangLibraryPath(
for: targetTriple,
for: targetInfo,
parsedOptions: &parsedOptions)
commandLine.appendFlag("-rpath")
commandLine.appendPath(clangPath)
Expand All @@ -75,7 +75,7 @@ extension DarwinToolchain {
func addLinkSanitizerLibArgsForDarwin(
to commandLine: inout [Job.ArgTemplate],
parsedOptions: inout ParsedOptions,
targetTriple: Triple,
targetInfo: FrontendTargetInfo,
sanitizer: Sanitizer,
isShared: Bool
) throws {
Expand All @@ -87,21 +87,21 @@ extension DarwinToolchain {

let sanitizerName = try runtimeLibraryName(
for: sanitizer,
targetTriple: targetTriple,
targetTriple: targetInfo.target.triple,
isShared: isShared
)
try addLinkRuntimeLibrary(
named: sanitizerName,
to: &commandLine,
for: targetTriple,
for: targetInfo,
parsedOptions: &parsedOptions
)

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

for runtime in targetTriple.darwinPlatform!.profileLibraryNameSuffixes {
for runtime in targetInfo.target.triple.darwinPlatform!.profileLibraryNameSuffixes {
let clangRTPath = clangPath
.appending(component: "libclang_rt.profile_\(runtime).a")
commandLine.appendPath(clangRTPath)
Expand Down Expand Up @@ -221,7 +221,7 @@ extension DarwinToolchain {
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
let compilerRTPath =
try clangLibraryPath(
for: targetTriple,
for: targetInfo,
parsedOptions: &parsedOptions)
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
if try fileSystem.exists(compilerRTPath) {
Expand All @@ -244,7 +244,7 @@ extension DarwinToolchain {
try addLinkSanitizerLibArgsForDarwin(
to: &commandLine,
parsedOptions: &parsedOptions,
targetTriple: targetTriple,
targetInfo: targetInfo,
sanitizer: sanitizer,
isShared: sanitizer != .fuzzer
)
Expand Down Expand Up @@ -282,7 +282,7 @@ extension DarwinToolchain {
try addProfileGenerationArgs(
to: &commandLine,
parsedOptions: &parsedOptions,
targetTriple: targetTriple
targetInfo: targetInfo
)

commandLine.appendFlags(
Expand Down
7 changes: 1 addition & 6 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,7 @@ extension Driver {
commandLine.appendFlag(.resourceDir)
commandLine.appendPath(frontendTargetInfo.runtimeResourcePath.path)

if parsedOptions.hasFlag(positive: .staticExecutable,
negative: .noStaticExecutable,
default: false) ||
parsedOptions.hasFlag(positive: .staticStdlib,
negative: .noStaticStdlib,
default: false) {
if self.useStaticResourceDir {
commandLine.appendFlag("-use-static-resource-dir")
}

Expand Down
24 changes: 8 additions & 16 deletions Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extension GenericUnixToolchain {
let hasRuntimeArgs = !(staticStdlib || staticExecutable)

let runtimePaths = try runtimeLibraryPaths(
for: targetTriple,
for: targetInfo,
parsedOptions: &parsedOptions,
sdkPath: targetInfo.sdkPath?.path,
isShared: hasRuntimeArgs
Expand All @@ -149,15 +149,11 @@ extension GenericUnixToolchain {
}
}

let sharedResourceDirPath = try computeResourceDirPath(
for: targetTriple,
parsedOptions: &parsedOptions,
isShared: true
)

let swiftrtPath = sharedResourceDirPath
let swiftrtPath = targetInfo.runtimeResourcePath.path
.appending(
components: String(majorArchitectureName(for: targetTriple)), "swiftrt.o"
components: targetTriple.platformName() ?? "",
String(majorArchitectureName(for: targetTriple)),
"swiftrt.o"
)
commandLine.appendPath(swiftrtPath)

Expand Down Expand Up @@ -199,11 +195,8 @@ extension GenericUnixToolchain {
// Link the standard library. In two paths, we do this using a .lnk file
// if we're going that route, we'll set `linkFilePath` to the path to that
// file.
var linkFilePath: VirtualPath? = try computeResourceDirPath(
for: targetTriple,
parsedOptions: &parsedOptions,
isShared: false
)
var linkFilePath: VirtualPath? = targetInfo.runtimeResourcePath.path
.appending(component: targetTriple.platformName() ?? "")

if staticExecutable {
linkFilePath = linkFilePath?.appending(component: "static-executable-args.lnk")
Expand Down Expand Up @@ -241,8 +234,7 @@ extension GenericUnixToolchain {
}

if parsedOptions.hasArgument(.profileGenerate) {
let libProfile = sharedResourceDirPath
.parentDirectory // remove platform name
let libProfile = targetInfo.runtimeResourcePath.path
.appending(components: "clang", "lib", targetTriple.osName,
"libclang_rt.profile-\(targetTriple.archName).a")
commandLine.appendPath(libProfile)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/InterpretJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension Driver {

let extraEnvironment = try toolchain.platformSpecificInterpreterEnvironmentVariables(
env: self.env, parsedOptions: &parsedOptions,
sdkPath: frontendTargetInfo.sdkPath?.path, targetTriple: self.targetTriple)
sdkPath: frontendTargetInfo.sdkPath?.path, targetInfo: self.frontendTargetInfo)

return Job(
moduleName: moduleOutputInfo.name,
Expand Down
9 changes: 0 additions & 9 deletions Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,6 @@ extension Driver {
if parsedOptions.hasArgument(.printTargetInfo) {
let sdkPath = try parsedOptions.getLastArgument(.sdk).map { try VirtualPath(path: $0.asSingle) }
let resourceDirPath = try parsedOptions.getLastArgument(.resourceDir).map { try VirtualPath(path: $0.asSingle) }
var useStaticResourceDir = false
if parsedOptions.hasFlag(positive: .staticExecutable,
negative: .noStaticExecutable,
default: false) ||
parsedOptions.hasFlag(positive: .staticStdlib,
negative: .noStaticStdlib,
default: false) {
useStaticResourceDir = true
}

return try toolchain.printTargetInfoJob(target: targetTriple,
targetVariant: targetVariantTriple,
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ extension SwiftVersion: Codable {
let librariesRequireRPath: Bool
}

struct Paths: Codable {
@_spi(Testing) public struct Paths: Codable {
/// The path to the SDK, if provided.
let sdkPath: TextualVirtualPath?
let runtimeLibraryPaths: [TextualVirtualPath]
let runtimeLibraryImportPaths: [TextualVirtualPath]
let runtimeResourcePath: TextualVirtualPath
public let sdkPath: TextualVirtualPath?
public let runtimeLibraryPaths: [TextualVirtualPath]
public let runtimeLibraryImportPaths: [TextualVirtualPath]
public let runtimeResourcePath: TextualVirtualPath
}

var compilerVersion: String
Expand All @@ -113,7 +113,7 @@ extension SwiftVersion: Codable {

// Make members of `FrontendTargetInfo.Paths` accessible on `FrontendTargetInfo`.
extension FrontendTargetInfo {
subscript<T>(dynamicMember dynamicMember: KeyPath<FrontendTargetInfo.Paths, T>) -> T {
@_spi(Testing) public subscript<T>(dynamicMember dynamicMember: KeyPath<FrontendTargetInfo.Paths, T>) -> T {
self.paths[keyPath: dynamicMember]
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftDriver/Jobs/Toolchain+InterpreterSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ extension DarwinToolchain {
env: [String : String],
parsedOptions: inout ParsedOptions,
sdkPath: VirtualPath?,
targetTriple: Triple) throws -> [String: String] {
targetInfo: FrontendTargetInfo) throws -> [String: String] {
var envVars: [String: String] = [:]

let runtimePaths = try runtimeLibraryPaths(
for: targetTriple,
for: targetInfo,
parsedOptions: &parsedOptions,
sdkPath: sdkPath,
isShared: true
Expand All @@ -63,11 +63,11 @@ extension GenericUnixToolchain {
env: [String : String],
parsedOptions: inout ParsedOptions,
sdkPath: VirtualPath?,
targetTriple: Triple) throws -> [String: String] {
targetInfo: FrontendTargetInfo) throws -> [String: String] {
var envVars: [String: String] = [:]

let runtimePaths = try runtimeLibraryPaths(
for: targetTriple,
for: targetInfo,
parsedOptions: &parsedOptions,
sdkPath: sdkPath,
isShared: true
Expand Down
Loading