@@ -17,8 +17,9 @@ import TSCUtility
17
17
import XCTest
18
18
19
19
private let bundleRootPath = try ! AbsolutePath ( validating: " /tmp/cross-toolchain " )
20
- private let toolchainBinDir = bundleRootPath. appending ( . init( " swift.xctoolchain/usr/bin " ) )
21
- private let sdkRootDir = bundleRootPath. appending ( . init( " ubuntu-jammy.sdk " ) )
20
+ private let toolchainBinDir = RelativePath ( " swift.xctoolchain/usr/bin " )
21
+ private let sdkRootDir = RelativePath ( " ubuntu-jammy.sdk " )
22
+ private let hostTriple = " arm64-apple-darwin22.1.0 "
22
23
private let destinationTriple = " x86_64-unknown-linux-gnu "
23
24
private let extraFlags = BuildFlags (
24
25
cCompilerFlags: [ " -fintegrated-as " ] ,
@@ -31,32 +32,66 @@ private let destinationV1JSON =
31
32
#"""
32
33
{
33
34
"version": 1,
34
- "sdk": " \#( sdkRootDir) ",
35
- "toolchain-bin-dir": " \#( toolchainBinDir) ",
35
+ "sdk": " \#( bundleRootPath . appending ( sdkRootDir) ) ",
36
+ "toolchain-bin-dir": " \#( bundleRootPath . appending ( toolchainBinDir) ) ",
36
37
"target": " \#( destinationTriple) ",
37
38
"extra-cc-flags": \#( extraFlags. cCompilerFlags) ,
38
39
"extra-swiftc-flags": \#( extraFlags. swiftCompilerFlags) ,
39
40
"extra-cpp-flags": \#( extraFlags. cxxCompilerFlags)
40
41
}
41
42
"""#
42
43
43
- class DestinationTests : XCTestCase {
44
+ private let destinationV2JSON =
45
+ #"""
46
+ {
47
+ "version": 2,
48
+ "sdkRootDir": " \#( sdkRootDir) ",
49
+ "toolchainBinDir": " \#( toolchainBinDir) ",
50
+ "hostTriple": " \#( hostTriple) ",
51
+ "destinationTriple": " \#( destinationTriple) ",
52
+ "extraCCFlags": \#( extraFlags. cCompilerFlags) ,
53
+ "extraSwiftCFlags": \#( extraFlags. swiftCompilerFlags) ,
54
+ "extraCXXFlags": \#( extraFlags. cxxCompilerFlags) ,
55
+ "extraLinkerFlags": \#( extraFlags. linkerFlags)
56
+ }
57
+ """#
58
+
59
+ final class DestinationTests : XCTestCase {
44
60
func testDestinationCodable( ) throws {
45
- let fs = InMemoryFileSystem ( files: [ " /sdk/destination.json " : ByteString ( encodingAsUTF8: destinationV1JSON) ] )
61
+ let fs = InMemoryFileSystem ( files: [
62
+ " \( bundleRootPath) /destinationV1.json " : ByteString ( encodingAsUTF8: destinationV1JSON) ,
63
+ " \( bundleRootPath) /destinationV2.json " : ByteString ( encodingAsUTF8: destinationV2JSON) ,
64
+ ] )
46
65
47
- let destinationV1 = try Destination ( fromFile: AbsolutePath ( validating : " /sdk/destination .json" ) , fileSystem: fs)
66
+ let destinationV1 = try Destination ( fromFile: bundleRootPath . appending ( . init ( " destinationV1 .json" ) ) , fileSystem: fs)
48
67
49
68
var flagsWithoutLinkerFlags = extraFlags
50
69
flagsWithoutLinkerFlags. linkerFlags = [ ]
51
70
71
+ let sdkRootAbsolutePath = bundleRootPath. appending ( sdkRootDir)
72
+ let toolchainBinAbsolutePath = bundleRootPath. appending ( toolchainBinDir)
73
+
52
74
XCTAssertEqual (
53
75
destinationV1,
54
76
Destination (
55
77
destinationTriple: try Triple ( destinationTriple) ,
56
- sdkRootDir: sdkRootDir ,
57
- toolchainBinDir: toolchainBinDir ,
78
+ sdkRootDir: sdkRootAbsolutePath ,
79
+ toolchainBinDir: toolchainBinAbsolutePath ,
58
80
extraFlags: flagsWithoutLinkerFlags
59
81
)
60
82
)
83
+
84
+ let destinationV2 = try Destination ( fromFile: bundleRootPath. appending ( . init( " destinationV2.json " ) ) , fileSystem: fs)
85
+
86
+ XCTAssertEqual (
87
+ destinationV2,
88
+ Destination (
89
+ hostTriple: try Triple ( hostTriple) ,
90
+ destinationTriple: try Triple ( destinationTriple) ,
91
+ sdkRootDir: sdkRootAbsolutePath,
92
+ toolchainBinDir: toolchainBinAbsolutePath,
93
+ extraFlags: extraFlags
94
+ )
95
+ )
61
96
}
62
97
}
0 commit comments