Skip to content

Create FileSystemPath (Absolute or Relative path) #83

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

Closed
Closed
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
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public struct Driver {
self.swiftCompilerPrefixArgs = []
} else {
let frontendPath = frontendCommandLine.removeFirst()
self.toolchain.overrideToolPath(.swiftCompiler, path: try AbsolutePath(validating: frontendPath))
self.toolchain.overrideToolPath(.swiftCompiler, path: try FileSystemPath(path: frontendPath))
self.swiftCompilerPrefixArgs = frontendCommandLine
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Execution/JobExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct ArgsResolver {
}

public func resolveArgumentList(for job: Job, forceResponseFiles: Bool) throws -> ([String], usingResponseFile: Bool) {
let tool = try resolve(.path(job.tool))
let tool = try resolve(.path(job.tool.virtualPath))
var arguments = [tool] + (try job.commandLine.map { try resolve($0) })
let usingResponseFile = try createResponseFileIfNeeded(for: job, resolvedArguments: &arguments,
forceResponseFiles: forceResponseFiles)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Driver {

return Job(
kind: .autolinkExtract,
tool: .absolute(try toolchain.getToolPath(.swiftAutolinkExtract)),
tool: try toolchain.getToolPath(.swiftAutolinkExtract),
commandLine: commandLine,
inputs: inputs,
outputs: [.init(file: output, type: .autolink)],
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftDriver/Jobs/CommandLineArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ extension Array where Element == Job.ArgTemplate {
append(.path(path))
}

/// Append a FileSystemPath to the command line arguments.
mutating func appendPath(_ path: FileSystemPath) {
append(.path(path.virtualPath))
}

/// Append an absolute path to the command line arguments.
mutating func appendPath(_ path: AbsolutePath) {
append(.path(.absolute(path)))
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 @@ -196,7 +196,7 @@ extension Driver {

return Job(
kind: .compile,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
displayInputs: primaryInputs,
inputs: inputs,
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import TSCBasic
import SwiftOptions

extension DarwinToolchain {
private func findARCLiteLibPath() throws -> AbsolutePath? {
private func findARCLiteLibPath() throws -> FileSystemPath? {
let path = try getToolPath(.swiftCompiler)
.parentDirectory // 'swift'
.parentDirectory // 'bin'
Expand Down Expand Up @@ -198,7 +198,7 @@ extension DarwinToolchain {
sanitizers: Set<Sanitizer>,
targetTriple: Triple,
targetVariantTriple: Triple?
) throws -> AbsolutePath {
) throws -> FileSystemPath {

// FIXME: If we used Clang as a linker instead of going straight to ld,
// we wouldn't have to replicate a bunch of Clang's logic here.
Expand All @@ -217,7 +217,7 @@ extension DarwinToolchain {
parsedOptions: &parsedOptions)
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
if localFileSystem.exists(compilerRTPath) {
commandLine.append(.path(.absolute(compilerRTPath)))
commandLine.appendPath(compilerRTPath)
}

// Set up for linking.
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: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
inputs: inputs,
outputs: outputs
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extension Driver {
commandLine.appendFlag(.Xcc)
commandLine.appendFlag(.workingDirectory)
commandLine.appendFlag(.Xcc)
commandLine.appendPath(.absolute(workingDirectory))
commandLine.appendPath(workingDirectory)
}

// -g implies -enable-anonymous-context-mangled-names, because the extra
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/GenerateDSYMJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension Driver {

return Job(
kind: .generateDSYM,
tool: .absolute(try toolchain.getToolPath(.dsymutil)),
tool: try toolchain.getToolPath(.dsymutil),
commandLine: commandLine,
displayInputs: [],
inputs: inputs,
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 @@ -63,7 +63,7 @@ extension Driver {

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

return Job(
kind: .generatePCM,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
displayInputs: [],
inputs: inputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension GenericUnixToolchain {
sanitizers: Set<Sanitizer>,
targetTriple: Triple,
targetVariantTriple: Triple?
) throws -> AbsolutePath {
) throws -> FileSystemPath {
switch linkerOutputType {
case .dynamicLibrary:
// Same options as an executable, just with '-shared'
Expand Down Expand Up @@ -107,7 +107,7 @@ extension GenericUnixToolchain {

// If there is a clang in the toolchain folder, use that instead.
if let tool = lookupExecutablePath(filename: "clang", searchPaths: [toolsDir]) {
clangPath = tool
clangPath = .absolute(tool)
}

// Look for binutils in the toolchain folder.
Expand Down Expand Up @@ -191,7 +191,7 @@ 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: AbsolutePath? = try computeResourceDirPath(
var linkFilePath: FileSystemPath? = try computeResourceDirPath(
for: targetTriple,
parsedOptions: &parsedOptions,
isShared: false
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 @@ -42,7 +42,7 @@ extension Driver {

return Job(
kind: .interpret,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
inputs:inputs,
outputs: [],
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftDriver/Jobs/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public struct Job: Codable, Equatable, Hashable {
}

public enum ArgTemplate: Equatable, Hashable {
/// Represents a command-line flag that is substitued as-is.
/// Represents a command-line flag that is substituted as-is.
case flag(String)

/// Represents a virtual path on disk.
case path(VirtualPath)
}

/// The tool to invoke.
public var tool: VirtualPath
public var tool: FileSystemPath

/// The command-line arguments of the job.
public var commandLine: [ArgTemplate]
Expand Down Expand Up @@ -70,7 +70,7 @@ public struct Job: Codable, Equatable, Hashable {

public init(
kind: Kind,
tool: VirtualPath,
tool: FileSystemPath,
commandLine: [ArgTemplate],
displayInputs: [TypedVirtualPath]? = nil,
inputs: [TypedVirtualPath],
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/LinkJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Driver {
// TODO: some, but not all, linkers support response files.
return Job(
kind: .link,
tool: .absolute(toolPath),
tool: toolPath,
commandLine: commandLine,
inputs: inputs,
outputs: [.init(file: outputFile, type: .object)]
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: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
inputs: inputs,
outputs: outputs,
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ extension Driver {
try commandLine.appendLast(.sdk, from: &parsedOptions)
try commandLine.appendLast(.resourceDir, from: &parsedOptions)
return Job(kind: .printTargetInfo,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
inputs: [],
outputs: [],
Expand All @@ -185,7 +185,7 @@ extension Driver {

if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
return Job(kind: .versionRequest,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: try toolchain.getToolPath(.swiftCompiler),
commandLine: [.flag("--version")],
inputs: [],
outputs: [],
Expand All @@ -198,7 +198,7 @@ extension Driver {
commandLine.append(.flag("-show-hidden"))
}
return Job(kind: .help,
tool: .absolute(try toolchain.getToolPath(.swiftHelp)),
tool: try toolchain.getToolPath(.swiftHelp),
commandLine: commandLine,
inputs: [],
outputs: [],
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/ReplJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Driver {
let lldbArg = "--repl=\(commandLine.joinedArguments)"
return Job(
kind: .repl,
tool: .absolute(try toolchain.getToolPath(.lldb)),
tool: try toolchain.getToolPath(.lldb),
commandLine: [Job.ArgTemplate.flag(lldbArg)],
inputs: [],
outputs: [],
Expand All @@ -41,7 +41,7 @@ extension Driver {
commandLine.appendFlags("-module-name", moduleName)
return Job(
kind: .repl,
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
tool: try toolchain.getToolPath(.swiftCompiler),
commandLine: commandLine,
inputs: [],
outputs: [],
Expand Down
23 changes: 11 additions & 12 deletions Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ extension Toolchain {
for triple: Triple,
parsedOptions: inout ParsedOptions,
isShared: Bool
) throws -> AbsolutePath {
// FIXME: This almost certainly won't be an absolute path in practice...
let resourceDirBase: AbsolutePath
) throws -> FileSystemPath {
let resourceDirBase: FileSystemPath
if let resourceDir = parsedOptions.getLastArgument(.resourceDir) {
resourceDirBase = try AbsolutePath(validating: resourceDir.asSingle)
resourceDirBase = try FileSystemPath(path: resourceDir.asSingle)
} else if let sdk = parsedOptions.getLastArgument(.sdk),
let sdkPath = try? AbsolutePath(validating: sdk.asSingle) {
let sdkPath = try? FileSystemPath(path: sdk.asSingle) {
resourceDirBase = sdkPath
.appending(components: "usr", "lib",
isShared ? "swift" : "swift_static")
Expand All @@ -38,15 +37,15 @@ extension Toolchain {
return resourceDirBase.appending(components: triple.platformName() ?? "")
}

func computeSecondaryResourceDirPath(for triple: Triple, primaryPath: AbsolutePath) -> AbsolutePath? {
func computeSecondaryResourceDirPath(for triple: Triple, primaryPath: FileSystemPath) -> FileSystemPath? {
guard triple.isMacCatalyst else { return nil }
return primaryPath.parentDirectory.appending(component: "macosx")
}

func clangLibraryPath(
for triple: Triple,
parsedOptions: inout ParsedOptions
) throws -> AbsolutePath {
) throws -> FileSystemPath {
return try computeResourceDirPath(for: triple,
parsedOptions: &parsedOptions,
isShared: true)
Expand All @@ -60,7 +59,7 @@ extension Toolchain {
parsedOptions: inout ParsedOptions,
sdkPath: String?,
isShared: Bool
) throws -> [AbsolutePath] {
) throws -> [FileSystemPath] {
let resourceDirPath = try computeResourceDirPath(
for: triple,
parsedOptions: &parsedOptions,
Expand All @@ -73,13 +72,13 @@ extension Toolchain {
}

if let path = sdkPath {
let sdkPath = AbsolutePath(path)
let sdkPath = try FileSystemPath(path: path)
// If we added the secondary resource dir, we also need the iOSSupport directory.
if secondaryResourceDir != nil {
result.append(sdkPath.appending(components: "System", "iOSSupport", "usr", "lib", "swift"))
}

result.append(sdkPath.appending(RelativePath("usr/lib/swift")))
result.append(sdkPath.appending(components: "usr", "lib", "swift"))
}

return result
Expand Down Expand Up @@ -263,12 +262,12 @@ extension DarwinToolchain {
}
}

func paths(runtimeLibraryPaths: [AbsolutePath]) -> [AbsolutePath] {
func paths(runtimeLibraryPaths: [FileSystemPath]) -> [FileSystemPath] {
switch self {
case .toolchain:
return runtimeLibraryPaths
case .os:
return [AbsolutePath("/usr/lib/swift")]
return [.absolute(AbsolutePath("/usr/lib/swift"))]
case .none:
return []
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/VerifyDebugInfoJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Driver {

return Job(
kind: .verifyDebugInfo,
tool: .absolute(try toolchain.getToolPath(.dwarfdump)),
tool: try toolchain.getToolPath(.dwarfdump),
commandLine: commandLine,
displayInputs: [],
inputs: inputs,
Expand Down
Loading