Skip to content

Commit 6d72507

Browse files
author
David Ungar
committed
Preserve old build record in order to pass dependencies-preservation-fine.swift.
1 parent aa97a35 commit 6d72507

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],
@@ -186,3 +198,9 @@ struct JobResult {
186198
finishedJobResults.append(JobResult(job, result))
187199
}
188200
}
201+
202+
fileprivate extension AbsolutePath {
203+
func withTilde() -> Self {
204+
parentDirectory.appending(component: basename + "~")
205+
}
206+
}

0 commit comments

Comments
 (0)