@@ -14,8 +14,6 @@ import class TSCBasic.DiagnosticsEngine
14
14
import struct TSCBasic. AbsolutePath
15
15
import struct TSCBasic. Diagnostic
16
16
17
- @_implementationOnly import Yams
18
-
19
17
/// Holds the info about inputs needed to plan incremenal compilation
20
18
/// A.k.a. BuildRecord was the legacy name
21
19
public struct BuildRecord {
@@ -40,155 +38,6 @@ public struct BuildRecord {
40
38
self . buildEndTime = buildEndTime
41
39
self . inputInfos = inputInfos
42
40
}
43
-
44
- public enum SectionName : String , CaseIterable {
45
- case swiftVersion = " version "
46
- case argsHash = " options "
47
- // Implement this for a smoother transition
48
- case legacyBuildStartTime = " build_time "
49
- case buildStartTime = " build_start_time "
50
- case buildEndTime = " build_end_time "
51
- case inputInfos = " inputs "
52
-
53
- var serializedName : String { rawValue }
54
- }
55
-
56
- var allInputs : Set < VirtualPath > {
57
- Set ( inputInfos. map { $0. key } )
58
- }
59
- }
60
-
61
- // MARK: - Reading the old map and deciding whether to use it
62
- public extension BuildRecord {
63
- enum Error : Swift . Error {
64
- case malformedYAML
65
- case invalidKey
66
- case missingTimeStamp
67
- case missingInputSequenceNode
68
- case missingInputEntryNode
69
- case missingPriorBuildState
70
- case unexpectedKey( String )
71
- case malformed( SectionName )
72
-
73
- var reason : String {
74
- switch self {
75
- case . malformedYAML:
76
- return " "
77
- case . invalidKey:
78
- return " "
79
- case . missingTimeStamp:
80
- return " could not read time value in build record "
81
- case . missingInputSequenceNode:
82
- return " no sequence node for input entry in build record "
83
- case . missingInputEntryNode:
84
- return " no input entry in build record "
85
- case . missingPriorBuildState:
86
- return " no previous build state in build record "
87
- case . unexpectedKey( let key) :
88
- return " Unexpected key ' \( key) ' "
89
- case . malformed( let section) :
90
- return " Malformed value for key ' \( section. serializedName) ' "
91
- }
92
- }
93
- }
94
- init ( contents: String ) throws {
95
- guard let sections = try ? Parser ( yaml: contents, resolver: . basic, encoding: . utf8)
96
- . singleRoot ( ) ? . mapping
97
- else {
98
- throw Error . malformedYAML
99
- }
100
- var argsHash : String ?
101
- var swiftVersion : String ?
102
- // Legacy driver does not disable incremental if no buildTime field.
103
- var buildStartTime : TimePoint = . distantPast
104
- var buildEndTime : TimePoint = . distantFuture
105
- var inputInfos : [ VirtualPath : InputInfo ] ?
106
- for (key, value) in sections {
107
- guard let k = key. string else {
108
- throw Error . invalidKey
109
- }
110
- switch k {
111
- case SectionName . swiftVersion. serializedName:
112
- // There's a test that uses "" for an illegal value
113
- guard let s = value. string, s != " " else {
114
- break
115
- }
116
- swiftVersion = s
117
- case SectionName . argsHash. serializedName:
118
- guard let s = value. string, s != " " else {
119
- break
120
- }
121
- argsHash = s
122
- case SectionName . buildStartTime. serializedName,
123
- SectionName . legacyBuildStartTime. serializedName:
124
- buildStartTime = try Self . decodeDate ( value, forInputInfo: false )
125
- case SectionName . buildEndTime. serializedName:
126
- buildEndTime = try Self . decodeDate ( value, forInputInfo: false )
127
- case SectionName . inputInfos. serializedName:
128
- inputInfos = try Self . decodeInputInfos ( value)
129
- default :
130
- throw Error . unexpectedKey ( k)
131
- }
132
- }
133
- // The legacy driver allows argHash to be absent to ease testing.
134
- // Mimic the legacy driver for testing ease: If no `argsHash` section,
135
- // record still matches.
136
- guard let sv = swiftVersion else {
137
- throw Error . malformed ( . swiftVersion)
138
- }
139
- guard let iis = inputInfos else {
140
- throw Error . malformed ( . inputInfos)
141
- }
142
- guard let argsHash = argsHash else {
143
- throw Error . malformed ( . argsHash)
144
- }
145
- self . init ( argsHash: argsHash,
146
- swiftVersion: sv,
147
- buildStartTime: buildStartTime,
148
- buildEndTime: buildEndTime,
149
- inputInfos: iis)
150
- }
151
-
152
- private static func decodeDate(
153
- _ node: Yams . Node ,
154
- forInputInfo: Bool
155
- ) throws -> TimePoint {
156
- guard let vals = node. sequence else {
157
- if forInputInfo {
158
- throw Error . missingInputSequenceNode
159
- } else {
160
- throw Error . missingTimeStamp
161
- }
162
- }
163
- guard vals. count == 2 ,
164
- let secs = vals [ 0 ] . int,
165
- let ns = vals [ 1 ] . int
166
- else {
167
- throw Error . missingTimeStamp
168
- }
169
- return TimePoint ( seconds: UInt64 ( secs) , nanoseconds: UInt32 ( ns) )
170
- }
171
-
172
- private static func decodeInputInfos(
173
- _ node: Yams . Node
174
- ) throws -> [ VirtualPath : InputInfo ] {
175
- guard let map = node. mapping else {
176
- throw BuildRecord . Error. malformed ( . inputInfos)
177
- }
178
- var infos = [ VirtualPath: InputInfo] ( )
179
- for (keyNode, valueNode) in map {
180
- guard let pathString = keyNode. string,
181
- let path = try ? VirtualPath ( path: pathString)
182
- else {
183
- throw BuildRecord . Error. missingInputEntryNode
184
- }
185
- let previousModTime = try decodeDate ( valueNode, forInputInfo: true )
186
- let inputInfo = try InputInfo (
187
- tag: valueNode. tag. description, previousModTime: previousModTime)
188
- infos [ path] = inputInfo
189
- }
190
- return infos
191
- }
192
41
}
193
42
194
43
// MARK: - Creating and writing a new map
@@ -222,82 +71,4 @@ extension BuildRecord {
222
71
inputInfos: Dictionary ( uniqueKeysWithValues: inputInfosArray)
223
72
)
224
73
}
225
-
226
- /// Pass in `currentArgsHash` to ensure it is non-nil
227
- public func encode( diagnosticEngine: DiagnosticsEngine ) -> String ? {
228
- let pathsAndInfos = inputInfos. map {
229
- input, inputInfo -> ( String , InputInfo ) in
230
- return ( input. name, inputInfo)
231
- }
232
- let inputInfosNode = Yams . Node (
233
- pathsAndInfos
234
- . sorted { $0. 0 < $1. 0 }
235
- . map { ( Yams . Node ( $0. 0 , . implicit, . doubleQuoted) , Self . encode ( $0. 1 ) ) }
236
- )
237
- let fieldNodes = [
238
- ( SectionName . swiftVersion, Yams . Node ( swiftVersion, . implicit, . doubleQuoted) ) ,
239
- ( SectionName . argsHash, Yams . Node ( argsHash, . implicit, . doubleQuoted) ) ,
240
- ( SectionName . buildStartTime, Self . encode ( buildStartTime) ) ,
241
- ( SectionName . buildEndTime, Self . encode ( buildEndTime) ) ,
242
- ( SectionName . inputInfos, inputInfosNode )
243
- ] . map { ( Yams . Node ( $0. 0 . serializedName) , $0. 1 ) }
244
-
245
- let buildRecordNode = Yams . Node ( fieldNodes, . implicit, . block)
246
- // let options = Yams.Emitter.Options(canonical: true)
247
- do {
248
- return try Yams . serialize ( node: buildRecordNode,
249
- width: - 1 ,
250
- sortKeys: false )
251
- } catch {
252
- diagnosticEngine. emit ( . warning_could_not_serialize_build_record( error) )
253
- return nil
254
- }
255
- }
256
-
257
- private static func encode( _ date: TimePoint , tag tagString: String ? = nil ) -> Yams . Node {
258
- return Yams . Node (
259
- [ Yams . Node ( String ( date. seconds) ) , Yams . Node ( String ( date. nanoseconds) ) ] ,
260
- tagString. map { Yams . Tag ( Yams . Tag. Name ( rawValue: $0) ) } ?? . implicit,
261
- . flow)
262
- }
263
-
264
- private static func encode( _ inputInfo: InputInfo ) -> Yams . Node {
265
- encode ( inputInfo. previousModTime, tag: inputInfo. tag)
266
- }
267
-
268
- }
269
-
270
- extension Diagnostic . Message {
271
- static func warning_could_not_serialize_build_record( _ err: Error
272
- ) -> Diagnostic . Message {
273
- . warning( " next compile won't be incremental; Could not serialize build record: \( err. localizedDescription) " )
274
- }
275
- static func warning_could_not_write_build_record_not_absolutePath(
276
- _ path: VirtualPath
277
- ) -> Diagnostic . Message {
278
- . warning( " next compile won't be incremental; build record path was not absolute: \( path) " )
279
- }
280
- static func warning_could_not_write_build_record( _ path: AbsolutePath
281
- ) -> Diagnostic . Message {
282
- . warning( " next compile won't be incremental; could not write build record to \( path) " )
283
- }
284
- }
285
-
286
-
287
- // MARK: - reading
288
- extension InputInfo {
289
- fileprivate init (
290
- tag: String ,
291
- previousModTime: TimePoint
292
- ) throws {
293
- guard let status = Status ( identifier: tag) else {
294
- throw BuildRecord . Error. missingPriorBuildState
295
- }
296
- self . init ( status: status, previousModTime: previousModTime)
297
- }
298
- }
299
-
300
- // MARK: - writing
301
- extension InputInfo {
302
- fileprivate var tag : String { status. identifier }
303
74
}
0 commit comments