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,46 @@ 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
+ if version. version == 1 {
242
+ let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfoV1 . self)
243
+ try self . init (
244
+ target: destination. target. map { try Triple ( $0) } ,
245
+ sdk: destination. sdk,
246
+ binDir: destination. binDir,
247
+ extraFlags: . init(
248
+ cCompilerFlags: destination. extraCCFlags,
249
+ cxxCompilerFlags: destination. extraCPPFlags,
250
+ swiftCompilerFlags: destination. extraSwiftCFlags
251
+ )
252
+ )
253
+ } else if version. version == 2 {
254
+ let destination = try decoder. decode ( path: path, fileSystem: fileSystem, as: DestinationInfoV2 . self)
255
+ let destinationDirectory = path. parentDirectory
256
+
257
+ try self . init (
258
+ target: Triple ( destination. destinationTriple) ,
259
+ sdk: AbsolutePath ( validating: destination. sdkDir, relativeTo: destinationDirectory) ,
260
+ binDir: AbsolutePath ( validating: destination. toolchainBinDir, relativeTo: destinationDirectory) ,
261
+ extraFlags: . init(
262
+ cCompilerFlags: destination. extraCCFlags,
263
+ cxxCompilerFlags: destination. extraCPPFlags,
264
+ swiftCompilerFlags: destination. extraSwiftCFlags,
265
+ linkerFlags: destination. extraLinkerFlags
266
+ )
267
+ )
268
+ } else {
240
269
throw DestinationError . invalidSchemaVersion
241
270
}
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
271
}
255
272
}
256
273
257
274
fileprivate struct VersionInfo : Codable {
258
275
let version : Int
259
276
}
260
277
261
- fileprivate struct DestinationInfo : Codable {
278
+ fileprivate struct DestinationInfoV1 : Codable {
262
279
let target : String ?
263
280
let sdk : AbsolutePath ?
264
281
let binDir : AbsolutePath
@@ -275,3 +292,14 @@ fileprivate struct DestinationInfo: Codable {
275
292
case extraCPPFlags = " extra-cpp-flags "
276
293
}
277
294
}
295
+
296
+ fileprivate struct DestinationInfoV2 : Codable {
297
+ let sdkDir : String
298
+ let toolchainBinDir : String
299
+ let hostTriple : String
300
+ let destinationTriple : String
301
+ let extraCCFlags : [ String ]
302
+ let extraSwiftCFlags : [ String ]
303
+ let extraCPPFlags : [ String ]
304
+ let extraLinkerFlags : [ String ]
305
+ }
0 commit comments