1
1
import TSCBasic
2
2
import TSCUtility
3
+ import Foundation
3
4
5
+ // FIXME: rename to something like IncrementalCompilationInitialState
4
6
public struct IncrementalCompilation {
5
7
public let showIncrementalBuildDecisions : Bool
6
8
public let shouldCompileIncrementally : Bool
7
9
public let buildRecordPath : VirtualPath ?
8
10
public let outputBuildRecordForModuleOnlyBuild : Bool
11
+ public let argsHash : String
12
+ public let lastBuildTime : Date
13
+ public let outOfDateMap : InputInfoMap ?
14
+ public let rebuildEverything : Bool
9
15
10
16
public init ( _ parsedOptions: inout ParsedOptions ,
11
17
compilerMode: CompilerMode ,
12
18
outputFileMap: OutputFileMap ? ,
13
19
compilerOutputType: FileType ? ,
14
20
moduleOutput: ModuleOutput ? ,
21
+ inputFiles: [ TypedVirtualPath ] ,
15
22
diagnosticEngine: DiagnosticsEngine
16
23
) {
17
24
let showIncrementalBuildDecisions = Self . getShowIncrementalBuildDecisions ( & parsedOptions)
@@ -33,9 +40,29 @@ public struct IncrementalCompilation {
33
40
// file for '-emit-module' only mode as well.
34
41
self . outputBuildRecordForModuleOnlyBuild = self . buildRecordPath != nil &&
35
42
moduleOutput? . isTopLevel ?? false
43
+
44
+ let argsHash = Self . computeArgsHash ( parsedOptions)
45
+ self . argsHash = argsHash
46
+ let lastBuildTime = Date . init ( )
47
+ self . lastBuildTime = lastBuildTime
48
+
49
+ if let buRP = buildRecordPath, shouldCompileIncrementally {
50
+ self . outOfDateMap = InputInfoMap . populateOutOfDateMap (
51
+ argsHash: argsHash,
52
+ lastBuildTime: lastBuildTime,
53
+ inputFiles: inputFiles,
54
+ buildRecordPath: buRP,
55
+ showIncrementalBuildDecisions: showIncrementalBuildDecisions)
56
+ }
57
+ else {
58
+ self . outOfDateMap = nil
59
+ }
60
+ // FIXME: Distinguish errors from "file removed", which is benign.
61
+ self . rebuildEverything = outOfDateMap == nil
36
62
}
37
63
38
- private static func getShowIncrementalBuildDecisions( _ parsedOptions: inout ParsedOptions ) -> Bool {
64
+ private static func getShowIncrementalBuildDecisions( _ parsedOptions: inout ParsedOptions )
65
+ -> Bool {
39
66
parsedOptions. hasArgument ( . driver_show_incremental)
40
67
}
41
68
@@ -87,6 +114,16 @@ public struct IncrementalCompilation {
87
114
? VirtualPath ( path: partialBuildRecordPath. name + " ~moduleonly " )
88
115
: partialBuildRecordPath
89
116
}
117
+
118
+ static private func computeArgsHash( _ parsedOptionsArg: ParsedOptions ) -> String {
119
+ var parsedOptions = parsedOptionsArg
120
+ let hashInput = parsedOptions
121
+ . filter { $0. option. affectsIncrementalBuild && $0. option. kind != . input}
122
+ . map { $0. option. spelling}
123
+ . sorted ( )
124
+ . joined ( )
125
+ return SHA256 ( hashInput) . digestString ( )
126
+ }
90
127
}
91
128
92
129
0 commit comments