@@ -39,7 +39,7 @@ class PackageModelTests: XCTestCase {
3939 checkCodable ( . executable)
4040 checkCodable ( . test)
4141 }
42-
42+
4343 func testProductFilterCodable( ) throws {
4444 // Test ProductFilter.everything
4545 try {
@@ -66,9 +66,77 @@ class PackageModelTests: XCTestCase {
6666 toolchainBinDir: toolchainPath. appending ( components: " usr " , " bin " )
6767 )
6868
69- XCTAssertEqual ( try UserToolchain . deriveSwiftCFlags ( triple: triple, destination: destination, environment: . process( ) ) , [
70- // Needed when cross‐compiling for Android. 2020‐03‐01
71- " -sdk " , sdkDir. pathString,
72- ] )
69+ XCTAssertEqual (
70+ try UserToolchain . deriveSwiftCFlags ( triple: triple, destination: destination, environment: . process( ) ) ,
71+ [
72+ // Needed when cross‐compiling for Android. 2020‐03‐01
73+ " -sdk " , sdkDir. pathString,
74+ ]
75+ )
76+ }
77+
78+ func testWindowsLibrarianSelection( ) throws {
79+ // tiny PE binary from: https://archive.is/w01DO
80+ let contents : [ UInt8 ] = [
81+ 0x4D , 0x5A , 0x00 , 0x00 , 0x50 , 0x45 , 0x00 , 0x00 , 0x4C , 0x01 , 0x01 , 0x00 ,
82+ 0x6A , 0x2A , 0x58 , 0xC3 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
83+ 0x04 , 0x00 , 0x03 , 0x01 , 0x0B , 0x01 , 0x08 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
84+ 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x0C , 0x00 , 0x00 , 0x00 ,
85+ 0x04 , 0x00 , 0x00 , 0x00 , 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
86+ 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
87+ 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
88+ 0x68 , 0x00 , 0x00 , 0x00 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
89+ 0x02 ,
90+ ]
91+
92+ #if os(Windows)
93+ let suffix = " .exe "
94+ #else
95+ let suffix = " "
96+ #endif
97+
98+ let triple = try Triple ( " x86_64-unknown-windows-msvc " )
99+ let fs = TSCBasic . localFileSystem
100+
101+ try withTemporaryFile { [ contents] _ in
102+ try withTemporaryDirectory ( removeTreeOnDeinit: true ) { [ contents] tmp in
103+ let bin = tmp. appending ( component: " bin " )
104+ try fs. createDirectory ( bin)
105+
106+ let lld = bin. appending ( component: " lld-link \( suffix) " )
107+ try fs. writeFileContents ( lld, bytes: ByteString ( contents) )
108+
109+ let not = bin. appending ( component: " not-link \( suffix) " )
110+ try fs. writeFileContents ( not, bytes: ByteString ( contents) )
111+
112+ #if !os(Windows)
113+ try fs. chmod ( . executable, path: lld, options: [ ] )
114+ try fs. chmod ( . executable, path: not, options: [ ] )
115+ #endif
116+
117+ try XCTAssertEqual (
118+ UserToolchain . determineLibrarian (
119+ triple: triple, binDir: bin, useXcrun: false , environment: [ : ] , searchPaths: [ ] ,
120+ extraSwiftFlags: [ " -Xswiftc " , " -use-ld=lld " ]
121+ ) ,
122+ lld
123+ )
124+
125+ try XCTAssertEqual (
126+ UserToolchain . determineLibrarian (
127+ triple: triple, binDir: bin, useXcrun: false , environment: [ : ] , searchPaths: [ ] ,
128+ extraSwiftFlags: [ " -Xswiftc " , " -use-ld=not-link \( suffix) " ]
129+ ) ,
130+ not
131+ )
132+
133+ try XCTAssertThrowsError (
134+ UserToolchain . determineLibrarian (
135+ triple: triple, binDir: bin, useXcrun: false , environment: [ : ] , searchPaths: [ ] ,
136+ extraSwiftFlags: [ ]
137+ )
138+ )
139+ }
140+ }
73141 }
74142}
0 commit comments