Skip to content

[Incremental] Preserve old build record in order to pass dependencies-preservation-file.swift #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions Sources/SwiftDriver/Incremental Compilation/BuildRecordInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ struct JobResult {
/// `Jobs` must include all of the compilation jobs.
/// `Inputs` will hold all the primary inputs that were not compiled because of incremental compilation
func writeBuildRecord(_ jobs: [Job], _ skippedInputs: Set<TypedVirtualPath>? ) {
guard let absPath = buildRecordPath.absolutePath else {
diagnosticEngine.emit(
.warning_could_not_write_build_record_not_absolutePath(buildRecordPath))
return
}
preservePreviousBuildRecord(absPath)

let buildRecord = BuildRecord(
jobs: jobs,
finishedJobResults: finishedJobResults,
Expand All @@ -134,11 +141,6 @@ struct JobResult {
diagnosticEngine.emit(.warning_could_not_serialize_build_record(error))
return
}
guard let absPath = buildRecordPath.absolutePath else {
diagnosticEngine.emit(
.warning_could_not_write_build_record_not_absolutePath(buildRecordPath))
return
}
do {
try fileSystem.writeFileContents(absPath,
bytes: ByteString(encodingAsUTF8: contents))
Expand All @@ -149,6 +151,16 @@ struct JobResult {
}
}

/// Before writing to the dependencies file path, preserve any previous file
/// that may have been there. No error handling -- this is just a nicety, it
/// doesn't matter if it fails.
/// Added for the sake of compatibility with the legacy driver.
private func preservePreviousBuildRecord(_ oldPath: AbsolutePath) {
let newPath = oldPath.withTilde()
try? fileSystem.move(from: oldPath, to: newPath)
}


// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
func populateOutOfDateBuildRecord(
inputFiles: [TypedVirtualPath],
Expand Down Expand Up @@ -186,3 +198,9 @@ struct JobResult {
finishedJobResults.append(JobResult(job, result))
}
}

fileprivate extension AbsolutePath {
func withTilde() -> Self {
parentDirectory.appending(component: basename + "~")
}
}