12
12
13
13
import Basics
14
14
import Foundation
15
+ import SystemPackage
15
16
import TSCBasic
16
17
17
18
import struct TSCUtility. Triple
@@ -235,30 +236,47 @@ extension Destination {
235
236
public init ( fromFile path: AbsolutePath , fileSystem: FileSystem ) throws {
236
237
let decoder = JSONDecoder . makeWithDefaults ( )
237
238
let version = try decoder. decode ( path: path, fileSystem: fileSystem, as: VersionInfo . self)
239
+
238
240
// Check schema version.
239
- guard version. version == 1 else {
241
+ switch version. version {
242
+ case 1 :
243
+ let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfoV1 . self)
244
+ try self . init (
245
+ target: destination. target. map { try Triple ( $0) } ,
246
+ sdk: destination. sdk,
247
+ binDir: destination. binDir,
248
+ extraFlags: . init(
249
+ cCompilerFlags: destination. extraCCFlags,
250
+ cxxCompilerFlags: destination. extraCPPFlags,
251
+ swiftCompilerFlags: destination. extraSwiftCFlags
252
+ )
253
+ )
254
+ case 2 :
255
+ let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfoV2 . self)
256
+ let destinationDirectory = path. parentDirectory
257
+
258
+ try self . init (
259
+ target: Triple ( destination. destinationTriple) ,
260
+ sdk: AbsolutePath ( validating: destination. sdkDir, relativeTo: destinationDirectory) ,
261
+ binDir: AbsolutePath ( validating: destination. toolchainBinDir, relativeTo: destinationDirectory) ,
262
+ extraFlags: . init(
263
+ cCompilerFlags: destination. extraCCFlags,
264
+ cxxCompilerFlags: destination. extraCPPFlags,
265
+ swiftCompilerFlags: destination. extraSwiftCFlags,
266
+ linkerFlags: destination. extraLinkerFlags
267
+ )
268
+ )
269
+ default :
240
270
throw DestinationError . invalidSchemaVersion
241
271
}
242
- let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfo . self)
243
- try self . init (
244
- target: destination. target. map { try Triple ( $0) } ,
245
- sdk: destination. sdk,
246
- binDir: destination. binDir,
247
- extraFlags: BuildFlags (
248
- cCompilerFlags: destination. extraCCFlags,
249
- // maintaining `destination.extraCPPFlags` naming inconsistency for compatibility.
250
- cxxCompilerFlags: destination. extraCPPFlags,
251
- swiftCompilerFlags: destination. extraSwiftCFlags
252
- )
253
- )
254
272
}
255
273
}
256
274
257
275
fileprivate struct VersionInfo : Codable {
258
276
let version : Int
259
277
}
260
278
261
- fileprivate struct DestinationInfo : Codable {
279
+ fileprivate struct DestinationInfoV1 : Codable {
262
280
let target : String ?
263
281
let sdk : AbsolutePath ?
264
282
let binDir : AbsolutePath
@@ -275,3 +293,14 @@ fileprivate struct DestinationInfo: Codable {
275
293
case extraCPPFlags = " extra-cpp-flags "
276
294
}
277
295
}
296
+
297
+ fileprivate struct DestinationInfoV2 : Codable {
298
+ let sdkDir : String
299
+ let toolchainBinDir : String
300
+ let hostTriple : String
301
+ let destinationTriple : String
302
+ let extraCCFlags : [ String ]
303
+ let extraSwiftCFlags : [ String ]
304
+ let extraCPPFlags : [ String ]
305
+ let extraLinkerFlags : [ String ]
306
+ }
0 commit comments