@@ -114,6 +114,13 @@ struct JobResult {
114
114
/// `Jobs` must include all of the compilation jobs.
115
115
/// `Inputs` will hold all the primary inputs that were not compiled because of incremental compilation
116
116
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
+
117
124
let buildRecord = BuildRecord (
118
125
jobs: jobs,
119
126
finishedJobResults: finishedJobResults,
@@ -134,11 +141,6 @@ struct JobResult {
134
141
diagnosticEngine. emit ( . warning_could_not_serialize_build_record( error) )
135
142
return
136
143
}
137
- guard let absPath = buildRecordPath. absolutePath else {
138
- diagnosticEngine. emit (
139
- . warning_could_not_write_build_record_not_absolutePath( buildRecordPath) )
140
- return
141
- }
142
144
do {
143
145
try fileSystem. writeFileContents ( absPath,
144
146
bytes: ByteString ( encodingAsUTF8: contents) )
@@ -149,6 +151,16 @@ struct JobResult {
149
151
}
150
152
}
151
153
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
+
152
164
// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
153
165
func populateOutOfDateBuildRecord(
154
166
inputFiles: [ TypedVirtualPath ] ,
@@ -188,3 +200,9 @@ struct JobResult {
188
200
finishedJobResults. append ( JobResult ( job, result) )
189
201
}
190
202
}
203
+
204
+ fileprivate extension AbsolutePath {
205
+ func withTilde( ) -> Self {
206
+ parentDirectory. appending ( component: basename + " ~ " )
207
+ }
208
+ }
0 commit comments