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
@@ -262,30 +263,47 @@ extension Destination {
262
263
public init ( fromFile path: AbsolutePath , fileSystem: FileSystem ) throws {
263
264
let decoder = JSONDecoder . makeWithDefaults ( )
264
265
let version = try decoder. decode ( path: path, fileSystem: fileSystem, as: VersionInfo . self)
266
+
265
267
// Check schema version.
266
- guard version. version == 1 else {
268
+ switch version. version {
269
+ case 1 :
270
+ let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfoV1 . self)
271
+ try self . init (
272
+ target: destination. target. map { try Triple ( $0) } ,
273
+ sdk: destination. sdk,
274
+ binDir: destination. binDir,
275
+ extraFlags: . init(
276
+ cCompilerFlags: destination. extraCCFlags,
277
+ cxxCompilerFlags: destination. extraCPPFlags,
278
+ swiftCompilerFlags: destination. extraSwiftCFlags
279
+ )
280
+ )
281
+ case 2 :
282
+ let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfoV2 . self)
283
+ let destinationDirectory = path. parentDirectory
284
+
285
+ try self . init (
286
+ target: Triple ( destination. destinationTriple) ,
287
+ sdk: AbsolutePath ( validating: destination. sdkDir, relativeTo: destinationDirectory) ,
288
+ binDir: AbsolutePath ( validating: destination. toolchainBinDir, relativeTo: destinationDirectory) ,
289
+ extraFlags: . init(
290
+ cCompilerFlags: destination. extraCCFlags,
291
+ cxxCompilerFlags: destination. extraCPPFlags,
292
+ swiftCompilerFlags: destination. extraSwiftCFlags,
293
+ linkerFlags: destination. extraLinkerFlags
294
+ )
295
+ )
296
+ default :
267
297
throw DestinationError . invalidSchemaVersion
268
298
}
269
- let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfo . self)
270
- try self . init (
271
- destinationTriple: destination. target. map { try Triple ( $0) } ,
272
- sdkRootDir: destination. sdk,
273
- toolchainBinDir: destination. binDir,
274
- extraFlags: BuildFlags (
275
- cCompilerFlags: destination. extraCCFlags,
276
- // maintaining `destination.extraCPPFlags` naming inconsistency for compatibility.
277
- cxxCompilerFlags: destination. extraCPPFlags,
278
- swiftCompilerFlags: destination. extraSwiftCFlags
279
- )
280
- )
281
299
}
282
300
}
283
301
284
302
fileprivate struct VersionInfo : Codable {
285
303
let version : Int
286
304
}
287
305
288
- fileprivate struct DestinationInfo : Codable {
306
+ fileprivate struct DestinationInfoV1 : Codable {
289
307
let target : String ?
290
308
let sdk : AbsolutePath ?
291
309
let binDir : AbsolutePath
@@ -302,3 +320,14 @@ fileprivate struct DestinationInfo: Codable {
302
320
case extraCPPFlags = " extra-cpp-flags "
303
321
}
304
322
}
323
+
324
+ fileprivate struct DestinationInfoV2 : Codable {
325
+ let sdkDir : String
326
+ let toolchainBinDir : String
327
+ let hostTriple : String
328
+ let destinationTriple : String
329
+ let extraCCFlags : [ String ]
330
+ let extraSwiftCFlags : [ String ]
331
+ let extraCPPFlags : [ String ]
332
+ let extraLinkerFlags : [ String ]
333
+ }
0 commit comments