Skip to content

Commit 4200941

Browse files
author
David Ungar
authored
Merge pull request #411 from davidungar/preserve-deps
[Incremental] Preserve old build record in order to pass dependencies-preservation-file.swift
2 parents 3812ddd + 62de5e3 commit 4200941

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

Sources/SwiftDriver/Incremental Compilation/BuildRecordInfo.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ struct JobResult {
114114
/// `Jobs` must include all of the compilation jobs.
115115
/// `Inputs` will hold all the primary inputs that were not compiled because of incremental compilation
116116
func writeBuildRecord(_ jobs: [Job], _ skippedInputs: Set<TypedVirtualPath>? ) {
117+
guard let absPath = buildRecordPath.absolutePath else {
118+
diagnosticEngine.emit(
119+
.warning_could_not_write_build_record_not_absolutePath(buildRecordPath))
120+
return
121+
}
122+
preservePreviousBuildRecord(absPath)
123+
117124
let buildRecord = BuildRecord(
118125
jobs: jobs,
119126
finishedJobResults: finishedJobResults,
@@ -134,11 +141,6 @@ struct JobResult {
134141
diagnosticEngine.emit(.warning_could_not_serialize_build_record(error))
135142
return
136143
}
137-
guard let absPath = buildRecordPath.absolutePath else {
138-
diagnosticEngine.emit(
139-
.warning_could_not_write_build_record_not_absolutePath(buildRecordPath))
140-
return
141-
}
142144
do {
143145
try fileSystem.writeFileContents(absPath,
144146
bytes: ByteString(encodingAsUTF8: contents))
@@ -149,6 +151,16 @@ struct JobResult {
149151
}
150152
}
151153

154+
/// Before writing to the dependencies file path, preserve any previous file
155+
/// that may have been there. No error handling -- this is just a nicety, it
156+
/// doesn't matter if it fails.
157+
/// Added for the sake of compatibility with the legacy driver.
158+
private func preservePreviousBuildRecord(_ oldPath: AbsolutePath) {
159+
let newPath = oldPath.withTilde()
160+
try? fileSystem.move(from: oldPath, to: newPath)
161+
}
162+
163+
152164
// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
153165
func populateOutOfDateBuildRecord(
154166
inputFiles: [TypedVirtualPath],
@@ -188,3 +200,9 @@ struct JobResult {
188200
finishedJobResults.append(JobResult(job, result))
189201
}
190202
}
203+
204+
fileprivate extension AbsolutePath {
205+
func withTilde() -> Self {
206+
parentDirectory.appending(component: basename + "~")
207+
}
208+
}

0 commit comments

Comments
 (0)