Skip to content

Commit e864a4e

Browse files
committed
Remove more appearences of deprecated 'AbsolutePath' and 'RelativePath' intitializers in source and tests
1 parent 775df46 commit e864a4e

23 files changed

+446
-439
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ public struct Driver {
677677
self.shouldUseInputFileList = inputFiles.count > fileListThreshold
678678
if shouldUseInputFileList {
679679
let swiftInputs = inputFiles.filter(\.type.isPartOfSwiftCompilation)
680-
self.allSourcesFileList = VirtualPath.createUniqueFilelist(RelativePath("sources"),
681-
.list(swiftInputs.map(\.file)))
680+
self.allSourcesFileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "sources"),
681+
.list(swiftInputs.map(\.file)))
682682
} else {
683683
self.allSourcesFileList = nil
684684
}
@@ -2556,7 +2556,7 @@ extension Driver {
25562556
moduleOutputPath = try .init(path: moduleFilename)
25572557
}
25582558
} else {
2559-
moduleOutputPath = VirtualPath.createUniqueTemporaryFile(RelativePath(moduleName.appendingFileTypeExtension(.swiftModule)))
2559+
moduleOutputPath = try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: moduleName.appendingFileTypeExtension(.swiftModule)))
25602560
}
25612561

25622562
// Use working directory if specified
@@ -2759,7 +2759,7 @@ extension Driver {
27592759
if let outputDirectory = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
27602760
return try VirtualPath(path: outputDirectory).appending(component: pchFileName).intern()
27612761
} else {
2762-
return VirtualPath.createUniqueTemporaryFile(RelativePath(pchFileName)).intern()
2762+
return try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: pchFileName)).intern()
27632763
}
27642764
}
27652765
}

Sources/SwiftDriver/Driver/OutputFileMap.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public struct OutputFileMap: Hashable, Codable {
4747
}
4848

4949
// Form the virtual path.
50-
return VirtualPath.createUniqueTemporaryFile(RelativePath(inputFile.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
50+
return try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: inputFile.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
5151
}
5252

5353
public func existingOutput(inputFile: VirtualPath.Handle, outputType: FileType) throws -> VirtualPath.Handle? {

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
285285
} else {
286286
// Write JSON to a file and add the JSON artifacts to command-line and inputs.
287287
let dependencyFile =
288-
VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleId.moduleName)-dependencies.json"),
289-
dependencyFileContent)
288+
try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(moduleId.moduleName)-dependencies.json"),
289+
dependencyFileContent)
290290
commandLine.appendFlag("-explicit-swift-module-map-file")
291291
commandLine.appendPath(dependencyFile)
292292
inputs.append(TypedVirtualPath(file: dependencyFile.intern(),
@@ -457,8 +457,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
457457
clangDependencyArtifacts: clangDependencyArtifacts)
458458

459459
let dependencyFile =
460-
VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(mainModuleId.moduleName)-dependencies.json"),
461-
dependencyFileContent)
460+
try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(mainModuleId.moduleName)-dependencies.json"),
461+
dependencyFileContent)
462462
commandLine.appendFlag("-explicit-swift-module-map-file")
463463
commandLine.appendPath(dependencyFile)
464464
inputs.append(TypedVirtualPath(file: dependencyFile.intern(),

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public extension Driver {
143143
let encoder = JSONEncoder()
144144
encoder.outputFormatting = [.prettyPrinted]
145145
let contents = try encoder.encode(placeholderArtifacts)
146-
return VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleOutputInfo.name)-external-modules.json"),
147-
contents)
146+
return try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(moduleOutputInfo.name)-external-modules.json"),
147+
contents)
148148
}
149149

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

425425
static func itemizedJobCommand(of job: Job, useResponseFiles: ResponseFileHandling,

Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ extension Driver {
3333
let dir = firstInput.file.parentDirectory
3434
// Go through a bit of extra rigmarole to keep the "./" out of the name for
3535
// the sake of the tests.
36-
let output: VirtualPath = dir == .temporary(RelativePath("."))
37-
? VirtualPath.createUniqueTemporaryFile(RelativePath(outputBasename))
36+
let output: VirtualPath = dir == .temporary(try RelativePath(validating: "."))
37+
? try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: outputBasename))
3838
: dir.appending(component: outputBasename)
3939

4040
commandLine.append(contentsOf: inputs.map { .path($0.file) })

Sources/SwiftDriver/Jobs/CompileJob.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ extension Driver {
6666
}
6767

6868
if !isTopLevel {
69-
return TypedVirtualPath(file: VirtualPath.createUniqueTemporaryFile(.init(baseName.appendingFileTypeExtension(outputType))).intern(),
69+
return TypedVirtualPath(file: try VirtualPath.createUniqueTemporaryFile(.init(validating: baseName.appendingFileTypeExtension(outputType))).intern(),
7070
type: outputType)
7171
}
72-
return TypedVirtualPath(file: try useWorkingDirectory(.init(baseName.appendingFileTypeExtension(outputType))).intern(), type: outputType)
72+
return TypedVirtualPath(file: try useWorkingDirectory(try .init(validating: baseName.appendingFileTypeExtension(outputType))).intern(), type: outputType)
7373
}
7474

7575
/// Is this compile job top-level
@@ -125,8 +125,8 @@ extension Driver {
125125
if usePrimaryInputFileList {
126126
// primary file list
127127
commandLine.appendFlag(.primaryFilelist)
128-
let fileList = VirtualPath.createUniqueFilelist(RelativePath("primaryInputs"),
129-
.list(primaryInputs.map(\.file)))
128+
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "primaryInputs"),
129+
.list(primaryInputs.map(\.file)))
130130
commandLine.appendPath(fileList)
131131
}
132132

@@ -311,8 +311,8 @@ extension Driver {
311311
// Add primary outputs.
312312
if primaryOutputs.count > fileListThreshold {
313313
commandLine.appendFlag(.outputFilelist)
314-
let fileList = VirtualPath.createUniqueFilelist(RelativePath("outputs"),
315-
.list(primaryOutputs.map { $0.file }))
314+
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "outputs"),
315+
.list(primaryOutputs.map { $0.file }))
316316
commandLine.appendPath(fileList)
317317
} else {
318318
for primaryOutput in primaryOutputs {
@@ -325,8 +325,8 @@ extension Driver {
325325
if !primaryIndexUnitOutputs.isEmpty {
326326
if primaryIndexUnitOutputs.count > fileListThreshold {
327327
commandLine.appendFlag(.indexUnitOutputPathFilelist)
328-
let fileList = VirtualPath.createUniqueFilelist(RelativePath("index-unit-outputs"),
329-
.list(primaryIndexUnitOutputs.map { $0.file }))
328+
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "index-unit-outputs"),
329+
.list(primaryIndexUnitOutputs.map { $0.file }))
330330
commandLine.appendPath(fileList)
331331
} else {
332332
for primaryIndexUnitOutput in primaryIndexUnitOutputs {

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ extension DarwinToolchain {
6868
// Same as an executable, but with the -dylib flag
6969
linkerTool = .dynamicLinker
7070
commandLine.appendFlag("-dynamiclib")
71-
addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
72-
commandLine: &commandLine,
73-
inputs: inputs,
74-
linkerOutputType: linkerOutputType)
71+
try addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
72+
commandLine: &commandLine,
73+
inputs: inputs,
74+
linkerOutputType: linkerOutputType)
7575
try addDynamicLinkerFlags(targetInfo: targetInfo,
7676
parsedOptions: &parsedOptions,
7777
commandLine: &commandLine,
@@ -81,10 +81,10 @@ extension DarwinToolchain {
8181

8282
case .executable:
8383
linkerTool = .dynamicLinker
84-
addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
85-
commandLine: &commandLine,
86-
inputs: inputs,
87-
linkerOutputType: linkerOutputType)
84+
try addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
85+
commandLine: &commandLine,
86+
inputs: inputs,
87+
linkerOutputType: linkerOutputType)
8888
try addDynamicLinkerFlags(targetInfo: targetInfo,
8989
parsedOptions: &parsedOptions,
9090
commandLine: &commandLine,
@@ -95,10 +95,10 @@ extension DarwinToolchain {
9595
case .staticLibrary:
9696
linkerTool = .staticLinker(lto)
9797
commandLine.appendFlag(.static)
98-
addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
99-
commandLine: &commandLine,
100-
inputs: inputs,
101-
linkerOutputType: linkerOutputType)
98+
try addLinkInputs(shouldUseInputFileList: shouldUseInputFileList,
99+
commandLine: &commandLine,
100+
inputs: inputs,
101+
linkerOutputType: linkerOutputType)
102102
}
103103

104104
// Add the output
@@ -111,7 +111,7 @@ extension DarwinToolchain {
111111
private func addLinkInputs(shouldUseInputFileList: Bool,
112112
commandLine: inout [Job.ArgTemplate],
113113
inputs: [TypedVirtualPath],
114-
linkerOutputType: LinkOutputType) {
114+
linkerOutputType: LinkOutputType) throws {
115115
// inputs LinkFileList
116116
if shouldUseInputFileList {
117117
commandLine.appendFlag(.filelist)
@@ -129,8 +129,8 @@ extension DarwinToolchain {
129129
inputPaths.append(input.file)
130130
}
131131
}
132-
let fileList = VirtualPath.createUniqueFilelist(RelativePath("inputs.LinkFileList"),
133-
.list(inputPaths))
132+
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "inputs.LinkFileList"),
133+
.list(inputPaths))
134134
commandLine.appendPath(fileList)
135135
if linkerOutputType != .staticLibrary {
136136
for module in inputModules {

Sources/SwiftDriver/Jobs/EmitSupportedFeaturesJob.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ extension Toolchain {
3737
// at least one so we fake it.
3838
// FIXME: Teach -emit-supported-features to not expect any inputs, like -print-target-info does.
3939
let dummyInputPath =
40-
VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("dummyInput.swift"),
41-
"".data(using: .utf8)!)
40+
try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "dummyInput.swift"),
41+
"".data(using: .utf8)!)
4242
commandLine.appendPath(dummyInputPath)
4343
inputs.append(TypedVirtualPath(file: dummyInputPath.intern(), type: .swift))
4444

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ extension Driver {
464464
// Alongside primary output
465465
outputPath = try output.file.replacingExtension(with: outputType).intern()
466466
} else {
467-
outputPath = VirtualPath.createUniqueTemporaryFile(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
467+
outputPath = try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
468468
}
469469

470470
// Update the input-output file map.
@@ -591,7 +591,7 @@ extension Driver {
591591
remapOutputPath = try output.file.replacingExtension(with: .remap)
592592
} else {
593593
remapOutputPath =
594-
VirtualPath.createUniqueTemporaryFile(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(.remap)))
594+
try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(.remap)))
595595
}
596596

597597
flaggedInputOutputPairs.append((flag: "-emit-remap-file-path",
@@ -636,8 +636,8 @@ extension Driver {
636636
entries[indexFilePath.fileHandle] = [.indexData: idxOutput.fileHandle]
637637
}
638638
let outputFileMap = OutputFileMap(entries: entries)
639-
let fileList = VirtualPath.createUniqueFilelist(RelativePath("supplementaryOutputs"),
640-
.outputFileMap(outputFileMap))
639+
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "supplementaryOutputs"),
640+
.outputFileMap(outputFileMap))
641641
commandLine.appendFlag(.supplementaryOutputFileMap)
642642
commandLine.appendPath(fileList)
643643
} else {

Sources/SwiftDriver/Jobs/GeneratePCHJob.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ extension Driver {
4949
path = try VirtualPath(path: outputDirectory).appending(component: outputName.appendingFileTypeExtension(.diagnostics))
5050
} else {
5151
path =
52-
VirtualPath.createUniqueTemporaryFile(
53-
RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(.diagnostics)))
52+
try VirtualPath.createUniqueTemporaryFile(
53+
RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(.diagnostics)))
5454
}
5555
commandLine.appendPath(path)
5656
outputs.append(.init(file: path.intern(), type: .diagnostics))

Sources/SwiftDriver/Jobs/LinkJob.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import struct TSCBasic.RelativePath
1515

1616
extension Driver {
1717
internal var relativeOutputFileForImage: RelativePath {
18-
if inputFiles.count == 1 && moduleOutputInfo.nameIsFallback && inputFiles[0].file != .standardInput {
19-
return RelativePath(inputFiles[0].file.basenameWithoutExt)
20-
}
18+
get throws {
19+
if inputFiles.count == 1 && moduleOutputInfo.nameIsFallback && inputFiles[0].file != .standardInput {
20+
return try RelativePath(validating: inputFiles[0].file.basenameWithoutExt)
21+
}
2122

22-
let outputName =
23+
let outputName =
2324
toolchain.makeLinkerOutputFilename(moduleName: moduleOutputInfo.name,
2425
type: linkerOutputType!)
25-
return RelativePath(outputName)
26+
return try RelativePath(validating: outputName)
27+
}
2628
}
2729

2830
/// Compute the output file for an image output.

Sources/SwiftDriver/Jobs/MergeModuleJob.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extension Driver {
2626
// Input file list.
2727
if shouldUseInputFileList {
2828
commandLine.appendFlag(.filelist)
29-
let fileList = VirtualPath.createUniqueFilelist(RelativePath("inputs"),
30-
.list(inputsFromOutputs.map { $0.file }))
29+
let fileList = try VirtualPath.createUniqueFilelist(RelativePath(validating: "inputs"),
30+
.list(inputsFromOutputs.map { $0.file }))
3131
commandLine.appendPath(fileList)
3232
inputs.append(contentsOf: inputsFromOutputs)
3333

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

+18-9
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,21 @@ typealias PrebuiltModuleOutput = PrebuiltModuleInput
392392

393393
public struct SDKPrebuiltModuleInputsCollector {
394394
let sdkPath: AbsolutePath
395-
let nonFrameworkDirs = [RelativePath("usr/lib/swift"),
396-
RelativePath("System/iOSSupport/usr/lib/swift")]
397-
let frameworkDirs = [RelativePath("System/Library/Frameworks"),
398-
RelativePath("System/Library/PrivateFrameworks"),
399-
RelativePath("System/iOSSupport/System/Library/Frameworks"),
400-
RelativePath("System/iOSSupport/System/Library/PrivateFrameworks")]
395+
var nonFrameworkDirs: [RelativePath] {
396+
get throws {
397+
try [RelativePath(validating: "usr/lib/swift"),
398+
RelativePath(validating: "System/iOSSupport/usr/lib/swift")]
399+
}
400+
}
401+
var frameworkDirs: [RelativePath] {
402+
get throws {
403+
try [RelativePath(validating: "System/Library/Frameworks"),
404+
RelativePath(validating: "System/Library/PrivateFrameworks"),
405+
RelativePath(validating: "System/iOSSupport/System/Library/Frameworks"),
406+
RelativePath(validating: "System/iOSSupport/System/Library/PrivateFrameworks")]
407+
}
408+
}
409+
401410
let sdkInfo: DarwinToolchain.DarwinSDKInfo
402411
let diagEngine: DiagnosticsEngine
403412
public init(_ sdkPath: AbsolutePath, _ diagEngine: DiagnosticsEngine) {
@@ -482,7 +491,7 @@ public struct SDKPrebuiltModuleInputsCollector {
482491
allSwiftAdopters.append(try! SwiftAdopter(moduleName, dir, hasInterface, hasModule))
483492
}
484493
// Search inside framework dirs in an SDK to find .swiftmodule directories.
485-
for dir in frameworkDirs {
494+
for dir in try frameworkDirs {
486495
let frameDir = AbsolutePath(sdkPath, dir)
487496
if !localFileSystem.exists(frameDir) {
488497
continue
@@ -500,14 +509,14 @@ public struct SDKPrebuiltModuleInputsCollector {
500509
}
501510
}
502511
// Search inside lib dirs in an SDK to find .swiftmodule directories.
503-
for dir in nonFrameworkDirs {
512+
for dir in try nonFrameworkDirs {
504513
let swiftModuleDir = AbsolutePath(sdkPath, dir)
505514
if !localFileSystem.exists(swiftModuleDir) {
506515
continue
507516
}
508517
try localFileSystem.getDirectoryContents(swiftModuleDir).forEach {
509518
if $0.hasSuffix(".swiftmodule") {
510-
try updateResults(AbsolutePath(swiftModuleDir, $0))
519+
try updateResults(try AbsolutePath(validating: $0, relativeTo: swiftModuleDir))
511520
}
512521
}
513522
}

0 commit comments

Comments
 (0)