Skip to content

Commit 93d710a

Browse files
committed
Use VirtualPaths To Write Module Dependency Graph
1 parent df4f19b commit 93d710a

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ public struct Driver {
206206
///
207207
/// FIXME: This is a little ridiculous. We could probably just replace the
208208
/// build record outright with a serialized format.
209-
var driverDependencyGraphPath: AbsolutePath? {
210-
guard
211-
let recordInfo = self.buildRecordInfo,
212-
let recordPath = recordInfo.buildRecordPath.absolutePath
213-
else {
209+
var driverDependencyGraphPath: VirtualPath? {
210+
guard let recordInfo = self.buildRecordInfo else {
214211
return nil
215212
}
216-
let filename = recordPath.basenameWithoutExt
217-
return recordPath.parentDirectory.appending(component: filename + ".priors")
213+
let filename = recordInfo.buildRecordPath.basenameWithoutExt
214+
return recordInfo
215+
.buildRecordPath
216+
.parentDirectory
217+
.appending(component: filename + ".priors")
218218
}
219219

220220
/// Code & data for incremental compilation. Nil if not running in incremental mode.

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ extension ModuleDependencyGraph {
457457
/// - Throws: An error describing any failures to read the graph from the given file.
458458
/// - Returns: A fully deserialized ModuleDependencyGraph.
459459
static func read(
460-
from path: AbsolutePath,
460+
from path: VirtualPath,
461461
on fileSystem: FileSystem,
462462
diagnosticEngine: DiagnosticsEngine,
463463
reporter: IncrementalCompilationState.Reporter?,
@@ -648,7 +648,7 @@ extension ModuleDependencyGraph {
648648
/// - compilerVersion: A string containing version information for the
649649
/// driver used to create this file.
650650
func write(
651-
to path: AbsolutePath,
651+
to path: VirtualPath,
652652
on fileSystem: FileSystem,
653653
compilerVersion: String
654654
) {
@@ -1038,7 +1038,7 @@ fileprivate extension DependencyKey.Designator {
10381038

10391039
extension Diagnostic.Message {
10401040
fileprivate static func error_could_not_write_dep_graph(
1041-
to path: AbsolutePath
1041+
to path: VirtualPath
10421042
) -> Diagnostic.Message {
10431043
.error("could not write driver dependency graph to \(path)")
10441044
}

Sources/SwiftDriver/Utilities/VirtualPath.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,13 @@ extension TSCBasic.FileSystem {
410410
try resolvingVirtualPath(path, apply: readFileContents)
411411
}
412412

413+
func writeFileContents(_ path: VirtualPath, bytes: ByteString, atomically: Bool) throws {
414+
try resolvingVirtualPath(path) { absolutePath in
415+
try self.writeFileContents(absolutePath, bytes: bytes, atomically: atomically)
416+
}
417+
}
418+
419+
413420
func getFileInfo(_ path: VirtualPath) throws -> TSCBasic.FileInfo {
414421
try resolvingVirtualPath(path, apply: getFileInfo)
415422
}

Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import TSCBasic
1616

1717
class DependencyGraphSerializationTests: XCTestCase {
1818
func roundTrip(_ graph: ModuleDependencyGraph) throws {
19-
let mockPath = AbsolutePath("/module-dependency-graph")
19+
let mockPath = VirtualPath.absolute(AbsolutePath("/module-dependency-graph"))
2020
let de = DiagnosticsEngine()
2121
let fs = InMemoryFileSystem()
2222
graph.write(to: mockPath, on: fs, compilerVersion: "Swift 99")

0 commit comments

Comments
 (0)