Skip to content

Read and Write The Driver's Dependency Graph For Cross-Module Builds #467

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
Feb 5, 2021
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ public struct Driver {
/// Only used for reading when compiling incrementally.
let buildRecordInfo: BuildRecordInfo?

/// A build-record-relative path to the location of a serialized copy of the
/// driver's dependency graph.
///
/// FIXME: This is a little ridiculous. We could probably just replace the
/// build record outright with a serialized format.
var driverDependencyGraphPath: VirtualPath? {
guard let recordInfo = self.buildRecordInfo else {
return nil
}
let filename = recordInfo.buildRecordPath.basenameWithoutExt
return recordInfo
.buildRecordPath
.parentDirectory
.appending(component: filename + ".priors")
}

/// Code & data for incremental compilation. Nil if not running in incremental mode.
/// Set during planning because needs the jobs to look at outputs.
@_spi(Testing) public private(set) var incrementalCompilationState: IncrementalCompilationState? = nil
Expand Down Expand Up @@ -910,6 +926,7 @@ extension Driver {
if !childJobs.isEmpty {
do {
defer {
self.incrementalCompilationState?.writeDependencyGraph()
buildRecordInfo?.writeBuildRecord(
jobs,
incrementalCompilationState?.skippedCompilationInputs)
Expand Down
15 changes: 9 additions & 6 deletions Sources/SwiftDriver/IncrementalCompilation/BuildRecordInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwiftOptions
/// compilation record).
///
/// This info is always written, but only read for incremental compilation.
final class BuildRecordInfo {
@_spi(Testing) public final class BuildRecordInfo {
/// A pair of a `Job` and the `ProcessResult` corresponding to the outcome of
/// its execution during this compilation session.
struct JobResult {
Expand Down Expand Up @@ -122,16 +122,19 @@ final class BuildRecordInfo {
}

/// Write out the build record.
/// `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>? ) {
///
/// - Parameters:
/// - jobs: All compilation jobs formed during this build.
/// - skippedInputs: All primary inputs that were not compiled because the
/// incremental build plan determined they could be
/// skipped.
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 = self.confinementQueue.sync {
BuildRecord(
Expand All @@ -155,7 +158,7 @@ final class BuildRecordInfo {
} catch {
diagnosticEngine.emit(.warning_could_not_write_build_record(absPath))
}
}
}

/// 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
Expand Down
Loading