File tree Expand file tree Collapse file tree 4 files changed +35
-11
lines changed Expand file tree Collapse file tree 4 files changed +35
-11
lines changed Original file line number Diff line number Diff line change @@ -988,10 +988,7 @@ extension Driver {
988
988
if !childJobs. isEmpty {
989
989
do {
990
990
defer {
991
- self . incrementalCompilationState? . writeDependencyGraph ( )
992
- buildRecordInfo? . writeBuildRecord (
993
- jobs,
994
- incrementalCompilationState? . skippedCompilationInputs)
991
+ writeIncrementalBuildInformation ( jobs)
995
992
}
996
993
try performTheBuild ( allJobs: childJobs,
997
994
jobExecutionDelegate: toolExecutionDelegate,
@@ -1055,6 +1052,20 @@ extension Driver {
1055
1052
recordedInputModificationDates: recordedInputModificationDates)
1056
1053
}
1057
1054
1055
+ private func writeIncrementalBuildInformation( _ jobs: [ Job ] ) {
1056
+ if let incrementalCompilationState = self . incrementalCompilationState {
1057
+ let hadError = incrementalCompilationState. writeDependencyGraph ( )
1058
+ /// Ensure that a bogus dependency graph is not used next time
1059
+ guard !hadError else {
1060
+ buildRecordInfo? . removeBuildRecord ( )
1061
+ return
1062
+ }
1063
+ }
1064
+ buildRecordInfo? . writeBuildRecord (
1065
+ jobs,
1066
+ incrementalCompilationState? . skippedCompilationInputs)
1067
+ }
1068
+
1058
1069
private func printBindings( _ job: Job ) {
1059
1070
stdoutStream <<< #"# ""# <<< targetTriple. triple
1060
1071
stdoutStream <<< #"" - ""# <<< job. tool. basename
Original file line number Diff line number Diff line change @@ -184,6 +184,13 @@ import SwiftOptions
184
184
}
185
185
}
186
186
187
+ func removeBuildRecord( ) {
188
+ guard let absPath = buildRecordPath. absolutePath else {
189
+ return
190
+ }
191
+ try ? fileSystem. removeFileTree ( absPath)
192
+ }
193
+
187
194
/// Before writing to the dependencies file path, preserve any previous file
188
195
/// that may have been there. No error handling -- this is just a nicety, it
189
196
/// doesn't matter if it fails.
Original file line number Diff line number Diff line change @@ -496,23 +496,26 @@ extension IncrementalCompilationState {
496
496
// MARK: - Serialization
497
497
498
498
extension IncrementalCompilationState {
499
- @_spi ( Testing) public func writeDependencyGraph( ) {
499
+ @_spi ( Testing) public func writeDependencyGraph( ) -> Bool {
500
500
// If the cross-module build is not enabled, the status quo dictates we
501
501
// not emit this file.
502
502
guard moduleDependencyGraph. info. isCrossModuleIncrementalBuildEnabled else {
503
- return
503
+ return false
504
504
}
505
505
506
506
guard
507
507
let recordInfo = self . driver. buildRecordInfo
508
508
else {
509
+ // It's OK to silently fail because no build record will be written
510
+ // so there will be no attempt to use the saved module dependency graph
511
+ // next time.
509
512
self . driver. diagnosticEngine. emit (
510
513
. warning_could_not_write_dependency_graph)
511
- return
514
+ return true
512
515
}
513
- self . moduleDependencyGraph. write ( to: recordInfo. dependencyGraphPath,
514
- on: self . driver. fileSystem,
515
- compilerVersion: recordInfo. actualSwiftVersion)
516
+ return self . moduleDependencyGraph. write ( to: recordInfo. dependencyGraphPath,
517
+ on: self . driver. fileSystem,
518
+ compilerVersion: recordInfo. actualSwiftVersion)
516
519
}
517
520
}
518
521
Original file line number Diff line number Diff line change @@ -663,19 +663,22 @@ extension ModuleDependencyGraph {
663
663
/// - fileSystem: The file system for this location.
664
664
/// - compilerVersion: A string containing version information for the
665
665
/// driver used to create this file.
666
+ /// - Returns: true if had error
666
667
@_spi ( Testing) public func write(
667
668
to path: VirtualPath ,
668
669
on fileSystem: FileSystem ,
669
670
compilerVersion: String
670
- ) {
671
+ ) -> Bool {
671
672
let data = ModuleDependencyGraph . Serializer. serialize ( self , compilerVersion)
672
673
673
674
do {
674
675
try fileSystem. writeFileContents ( path,
675
676
bytes: data,
676
677
atomically: true )
678
+ return false
677
679
} catch {
678
680
info. diagnosticEngine. emit ( . warning_could_not_write_dep_graph( to: path, error: error) )
681
+ return true
679
682
}
680
683
}
681
684
You can’t perform that action at this time.
0 commit comments