Skip to content

Remove more appearences of deprecated 'AbsolutePath' and 'RelativePath' intitializers in source and tests #1450

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 1 commit into from
Sep 25, 2023
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
8 changes: 4 additions & 4 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ public struct Driver {
self.shouldUseInputFileList = inputFiles.count > fileListThreshold
if shouldUseInputFileList {
let swiftInputs = inputFiles.filter(\.type.isPartOfSwiftCompilation)
self.allSourcesFileList = VirtualPath.createUniqueFilelist(RelativePath("sources"),
.list(swiftInputs.map(\.file)))
self.allSourcesFileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "sources"),
.list(swiftInputs.map(\.file)))
} else {
self.allSourcesFileList = nil
}
Expand Down Expand Up @@ -2556,7 +2556,7 @@ extension Driver {
moduleOutputPath = try .init(path: moduleFilename)
}
} else {
moduleOutputPath = VirtualPath.createUniqueTemporaryFile(RelativePath(moduleName.appendingFileTypeExtension(.swiftModule)))
moduleOutputPath = try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: moduleName.appendingFileTypeExtension(.swiftModule)))
}

// Use working directory if specified
Expand Down Expand Up @@ -2759,7 +2759,7 @@ extension Driver {
if let outputDirectory = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
return try VirtualPath(path: outputDirectory).appending(component: pchFileName).intern()
} else {
return VirtualPath.createUniqueTemporaryFile(RelativePath(pchFileName)).intern()
return try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: pchFileName)).intern()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Driver/OutputFileMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct OutputFileMap: Hashable, Codable {
}

// Form the virtual path.
return VirtualPath.createUniqueTemporaryFile(RelativePath(inputFile.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
return try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: inputFile.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
}

public func existingOutput(inputFile: VirtualPath.Handle, outputType: FileType) throws -> VirtualPath.Handle? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
} else {
// Write JSON to a file and add the JSON artifacts to command-line and inputs.
let dependencyFile =
VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleId.moduleName)-dependencies.json"),
dependencyFileContent)
try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(moduleId.moduleName)-dependencies.json"),
dependencyFileContent)
commandLine.appendFlag("-explicit-swift-module-map-file")
commandLine.appendPath(dependencyFile)
inputs.append(TypedVirtualPath(file: dependencyFile.intern(),
Expand Down Expand Up @@ -457,8 +457,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
clangDependencyArtifacts: clangDependencyArtifacts)

let dependencyFile =
VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(mainModuleId.moduleName)-dependencies.json"),
dependencyFileContent)
try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(mainModuleId.moduleName)-dependencies.json"),
dependencyFileContent)
commandLine.appendFlag("-explicit-swift-module-map-file")
commandLine.appendPath(dependencyFile)
inputs.append(TypedVirtualPath(file: dependencyFile.intern(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public extension Driver {
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted]
let contents = try encoder.encode(placeholderArtifacts)
return VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleOutputInfo.name)-external-modules.json"),
contents)
return try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(moduleOutputInfo.name)-external-modules.json"),
contents)
}

/// Returns false if the lib is available and ready to use
Expand Down Expand Up @@ -418,8 +418,8 @@ public extension Driver {
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted]
let contents = try encoder.encode(moduleInfos)
return VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleOutputInfo.name)-batch-module-scan.json"),
contents)
return try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(moduleOutputInfo.name)-batch-module-scan.json"),
contents)
}

static func itemizedJobCommand(of job: Job, useResponseFiles: ResponseFileHandling,
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extension Driver {
let dir = firstInput.file.parentDirectory
// Go through a bit of extra rigmarole to keep the "./" out of the name for
// the sake of the tests.
let output: VirtualPath = dir == .temporary(RelativePath("."))
? VirtualPath.createUniqueTemporaryFile(RelativePath(outputBasename))
let output: VirtualPath = dir == .temporary(try RelativePath(validating: "."))
? try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: outputBasename))
: dir.appending(component: outputBasename)

commandLine.append(contentsOf: inputs.map { .path($0.file) })
Expand Down
16 changes: 8 additions & 8 deletions Sources/SwiftDriver/Jobs/CompileJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ extension Driver {
}

if !isTopLevel {
return TypedVirtualPath(file: VirtualPath.createUniqueTemporaryFile(.init(baseName.appendingFileTypeExtension(outputType))).intern(),
return TypedVirtualPath(file: try VirtualPath.createUniqueTemporaryFile(.init(validating: baseName.appendingFileTypeExtension(outputType))).intern(),
type: outputType)
}
return TypedVirtualPath(file: try useWorkingDirectory(.init(baseName.appendingFileTypeExtension(outputType))).intern(), type: outputType)
return TypedVirtualPath(file: try useWorkingDirectory(try .init(validating: baseName.appendingFileTypeExtension(outputType))).intern(), type: outputType)
}

/// Is this compile job top-level
Expand Down Expand Up @@ -125,8 +125,8 @@ extension Driver {
if usePrimaryInputFileList {
// primary file list
commandLine.appendFlag(.primaryFilelist)
let fileList = VirtualPath.createUniqueFilelist(RelativePath("primaryInputs"),
.list(primaryInputs.map(\.file)))
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "primaryInputs"),
.list(primaryInputs.map(\.file)))
commandLine.appendPath(fileList)
}

Expand Down Expand Up @@ -311,8 +311,8 @@ extension Driver {
// Add primary outputs.
if primaryOutputs.count > fileListThreshold {
commandLine.appendFlag(.outputFilelist)
let fileList = VirtualPath.createUniqueFilelist(RelativePath("outputs"),
.list(primaryOutputs.map { $0.file }))
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "outputs"),
.list(primaryOutputs.map { $0.file }))
commandLine.appendPath(fileList)
} else {
for primaryOutput in primaryOutputs {
Expand All @@ -325,8 +325,8 @@ extension Driver {
if !primaryIndexUnitOutputs.isEmpty {
if primaryIndexUnitOutputs.count > fileListThreshold {
commandLine.appendFlag(.indexUnitOutputPathFilelist)
let fileList = VirtualPath.createUniqueFilelist(RelativePath("index-unit-outputs"),
.list(primaryIndexUnitOutputs.map { $0.file }))
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "index-unit-outputs"),
.list(primaryIndexUnitOutputs.map { $0.file }))
commandLine.appendPath(fileList)
} else {
for primaryIndexUnitOutput in primaryIndexUnitOutputs {
Expand Down
30 changes: 15 additions & 15 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ extension DarwinToolchain {
// Same as an executable, but with the -dylib flag
linkerTool = .dynamicLinker
commandLine.appendFlag("-dynamiclib")
addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
commandLine: &commandLine,
inputs: inputs,
linkerOutputType: linkerOutputType)
try addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
commandLine: &commandLine,
inputs: inputs,
linkerOutputType: linkerOutputType)
try addDynamicLinkerFlags(targetInfo: targetInfo,
parsedOptions: &parsedOptions,
commandLine: &commandLine,
Expand All @@ -81,10 +81,10 @@ extension DarwinToolchain {

case .executable:
linkerTool = .dynamicLinker
addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
commandLine: &commandLine,
inputs: inputs,
linkerOutputType: linkerOutputType)
try addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
commandLine: &commandLine,
inputs: inputs,
linkerOutputType: linkerOutputType)
try addDynamicLinkerFlags(targetInfo: targetInfo,
parsedOptions: &parsedOptions,
commandLine: &commandLine,
Expand All @@ -95,10 +95,10 @@ extension DarwinToolchain {
case .staticLibrary:
linkerTool = .staticLinker(lto)
commandLine.appendFlag(.static)
addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
commandLine: &commandLine,
inputs: inputs,
linkerOutputType: linkerOutputType)
try addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
commandLine: &commandLine,
inputs: inputs,
linkerOutputType: linkerOutputType)
}

// Add the output
Expand All @@ -111,7 +111,7 @@ extension DarwinToolchain {
private func addLinkInputs(shouldUseInputFileList: Bool,
commandLine: inout [Job.ArgTemplate],
inputs: [TypedVirtualPath],
linkerOutputType: LinkOutputType) {
linkerOutputType: LinkOutputType) throws {
// inputs LinkFileList
if shouldUseInputFileList {
commandLine.appendFlag(.filelist)
Expand All @@ -129,8 +129,8 @@ extension DarwinToolchain {
inputPaths.append(input.file)
}
}
let fileList = VirtualPath.createUniqueFilelist(RelativePath("inputs.LinkFileList"),
.list(inputPaths))
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "inputs.LinkFileList"),
.list(inputPaths))
commandLine.appendPath(fileList)
if linkerOutputType != .staticLibrary {
for module in inputModules {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/EmitSupportedFeaturesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extension Toolchain {
// at least one so we fake it.
// FIXME: Teach -emit-supported-features to not expect any inputs, like -print-target-info does.
let dummyInputPath =
VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("dummyInput.swift"),
"".data(using: .utf8)!)
try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "dummyInput.swift"),
"".data(using: .utf8)!)
commandLine.appendPath(dummyInputPath)
inputs.append(TypedVirtualPath(file: dummyInputPath.intern(), type: .swift))

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ extension Driver {
// Alongside primary output
outputPath = try output.file.replacingExtension(with: outputType).intern()
} else {
outputPath = VirtualPath.createUniqueTemporaryFile(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
outputPath = try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
}

// Update the input-output file map.
Expand Down Expand Up @@ -591,7 +591,7 @@ extension Driver {
remapOutputPath = try output.file.replacingExtension(with: .remap)
} else {
remapOutputPath =
VirtualPath.createUniqueTemporaryFile(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(.remap)))
try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(.remap)))
}

flaggedInputOutputPairs.append((flag: "-emit-remap-file-path",
Expand Down Expand Up @@ -636,8 +636,8 @@ extension Driver {
entries[indexFilePath.fileHandle] = [.indexData: idxOutput.fileHandle]
}
let outputFileMap = OutputFileMap(entries: entries)
let fileList = VirtualPath.createUniqueFilelist(RelativePath("supplementaryOutputs"),
.outputFileMap(outputFileMap))
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "supplementaryOutputs"),
.outputFileMap(outputFileMap))
commandLine.appendFlag(.supplementaryOutputFileMap)
commandLine.appendPath(fileList)
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/GeneratePCHJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ extension Driver {
path = try VirtualPath(path: outputDirectory).appending(component: outputName.appendingFileTypeExtension(.diagnostics))
} else {
path =
VirtualPath.createUniqueTemporaryFile(
RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(.diagnostics)))
try VirtualPath.createUniqueTemporaryFile(
RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(.diagnostics)))
}
commandLine.appendPath(path)
outputs.append(.init(file: path.intern(), type: .diagnostics))
Expand Down
12 changes: 7 additions & 5 deletions Sources/SwiftDriver/Jobs/LinkJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import struct TSCBasic.RelativePath

extension Driver {
internal var relativeOutputFileForImage: RelativePath {
if inputFiles.count == 1 && moduleOutputInfo.nameIsFallback && inputFiles[0].file != .standardInput {
return RelativePath(inputFiles[0].file.basenameWithoutExt)
}
get throws {
if inputFiles.count == 1 && moduleOutputInfo.nameIsFallback && inputFiles[0].file != .standardInput {
return try RelativePath(validating: inputFiles[0].file.basenameWithoutExt)
}

let outputName =
let outputName =
toolchain.makeLinkerOutputFilename(moduleName: moduleOutputInfo.name,
type: linkerOutputType!)
return RelativePath(outputName)
return try RelativePath(validating: outputName)
}
}

/// Compute the output file for an image output.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/MergeModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension Driver {
// Input file list.
if shouldUseInputFileList {
commandLine.appendFlag(.filelist)
let fileList = VirtualPath.createUniqueFilelist(RelativePath("inputs"),
.list(inputsFromOutputs.map { $0.file }))
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "inputs"),
.list(inputsFromOutputs.map { $0.file }))
commandLine.appendPath(fileList)
inputs.append(contentsOf: inputsFromOutputs)

Expand Down
27 changes: 18 additions & 9 deletions Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,21 @@ typealias PrebuiltModuleOutput = PrebuiltModuleInput

public struct SDKPrebuiltModuleInputsCollector {
let sdkPath: AbsolutePath
let nonFrameworkDirs = [RelativePath("usr/lib/swift"),
RelativePath("System/iOSSupport/usr/lib/swift")]
let frameworkDirs = [RelativePath("System/Library/Frameworks"),
RelativePath("System/Library/PrivateFrameworks"),
RelativePath("System/iOSSupport/System/Library/Frameworks"),
RelativePath("System/iOSSupport/System/Library/PrivateFrameworks")]
var nonFrameworkDirs: [RelativePath] {
get throws {
try [RelativePath(validating: "usr/lib/swift"),
RelativePath(validating: "System/iOSSupport/usr/lib/swift")]
}
}
var frameworkDirs: [RelativePath] {
get throws {
try [RelativePath(validating: "System/Library/Frameworks"),
RelativePath(validating: "System/Library/PrivateFrameworks"),
RelativePath(validating: "System/iOSSupport/System/Library/Frameworks"),
RelativePath(validating: "System/iOSSupport/System/Library/PrivateFrameworks")]
}
}

let sdkInfo: DarwinToolchain.DarwinSDKInfo
let diagEngine: DiagnosticsEngine
public init(_ sdkPath: AbsolutePath, _ diagEngine: DiagnosticsEngine) {
Expand Down Expand Up @@ -482,7 +491,7 @@ public struct SDKPrebuiltModuleInputsCollector {
allSwiftAdopters.append(try! SwiftAdopter(moduleName, dir, hasInterface, hasModule))
}
// Search inside framework dirs in an SDK to find .swiftmodule directories.
for dir in frameworkDirs {
for dir in try frameworkDirs {
let frameDir = AbsolutePath(sdkPath, dir)
if !localFileSystem.exists(frameDir) {
continue
Expand All @@ -500,14 +509,14 @@ public struct SDKPrebuiltModuleInputsCollector {
}
}
// Search inside lib dirs in an SDK to find .swiftmodule directories.
for dir in nonFrameworkDirs {
for dir in try nonFrameworkDirs {
let swiftModuleDir = AbsolutePath(sdkPath, dir)
if !localFileSystem.exists(swiftModuleDir) {
continue
}
try localFileSystem.getDirectoryContents(swiftModuleDir).forEach {
if $0.hasSuffix(".swiftmodule") {
try updateResults(AbsolutePath(swiftModuleDir, $0))
try updateResults(try AbsolutePath(validating: $0, relativeTo: swiftModuleDir))
}
}
}
Expand Down
Loading