Skip to content

Commit f25cce8

Browse files
author
David Ungar
committed
Factor out resolvedRelativePath
1 parent baedcc9 commit f25cce8

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

Sources/SwiftDriver/Driver/OutputFileMap.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,3 @@ extension String {
246246
return self + "." + ext
247247
}
248248
}
249-
250-
extension VirtualPath {
251-
fileprivate func resolvedRelativePath(base: AbsolutePath) -> VirtualPath {
252-
guard case let .relative(relPath) = self else { return self }
253-
return .absolute(.init(base, relPath))
254-
}
255-
}

Sources/SwiftDriver/Incremental Compilation/BuildRecordInfo.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ import SwiftOptions
9696
diagnosticEngine.emit(.warning_incremental_requires_build_record_entry)
9797
return nil
9898
}
99-
return partialBuildRecordPath.resolveRelativePath(workingDirectory)
99+
return workingDirectory
100+
.map(partialBuildRecordPath.resolvedRelativePath(base:))
101+
?? partialBuildRecordPath
100102
}
101103

102104
/// Write out the build record.
@@ -178,12 +180,3 @@ import SwiftOptions
178180
}
179181
}
180182
}
181-
182-
extension VirtualPath {
183-
fileprivate func resolveRelativePath(_ workingDirectory: AbsolutePath?) -> VirtualPath {
184-
switch (workingDirectory, self) {
185-
case let (wd?, .relative(relPath)): return .absolute(.init(wd, relPath))
186-
default: return self
187-
}
188-
}
189-
}

Sources/SwiftDriver/Utilities/VirtualPath.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ extension VirtualPath {
346346
}
347347
}
348348

349+
extension VirtualPath {
350+
/// Resolve a relative path into an absolute one, if possible.
351+
public func resolvedRelativePath(base: AbsolutePath) -> VirtualPath {
352+
guard case let .relative(relPath) = self else { return self }
353+
return .absolute(.init(base, relPath))
354+
}
355+
}
356+
349357
private extension String {
350358
func withoutExt(_ ext: String?) -> String {
351359
if let ext = ext {

0 commit comments

Comments
 (0)