@@ -112,6 +112,60 @@ private func checkExplicitModuleBuildJobDependencies(job: Job,
112112 }
113113}
114114
115+ internal func getDriverArtifactsForScanning( ) throws -> ( stdLibPath: AbsolutePath ,
116+ shimsPath: AbsolutePath ,
117+ toolchain: Toolchain ,
118+ hostTriple: Triple ) {
119+ // Just instantiating to get at the toolchain path
120+ let driver = try Driver ( args: [ " swiftc " , " -explicit-module-build " ,
121+ " -module-name " , " testDependencyScanning " ,
122+ " test.swift " ] )
123+ let ( stdLibPath, shimsPath) = try getStdlibShimsPaths ( driver)
124+ XCTAssertTrue ( localFileSystem. exists ( stdLibPath) ,
125+ " expected Swift StdLib at: \( stdLibPath. description) " )
126+ XCTAssertTrue ( localFileSystem. exists ( shimsPath) ,
127+ " expected Swift Shims at: \( shimsPath. description) " )
128+ return ( stdLibPath, shimsPath, driver. toolchain, driver. hostTriple)
129+ }
130+
131+ func getStdlibShimsPaths( _ driver: Driver ) throws -> ( AbsolutePath , AbsolutePath ) {
132+ let toolchainRootPath : AbsolutePath = try driver. toolchain. getToolPath ( . swiftCompiler)
133+ . parentDirectory // bin
134+ . parentDirectory // toolchain root
135+ if driver. targetTriple. isDarwin {
136+ let executor = try SwiftDriverExecutor ( diagnosticsEngine: DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ,
137+ processSet: ProcessSet ( ) ,
138+ fileSystem: localFileSystem,
139+ env: ProcessEnv . vars)
140+ let sdkPath = try executor. checkNonZeroExit (
141+ args: " xcrun " , " -sdk " , " macosx " , " --show-sdk-path " ) . spm_chomp ( )
142+ let stdLibPath = try AbsolutePath ( validating: sdkPath) . appending ( component: " usr " )
143+ . appending ( component: " lib " )
144+ . appending ( component: " swift " )
145+ return ( stdLibPath, stdLibPath. appending ( component: " shims " ) )
146+ } else if driver. targetTriple. isWindows {
147+ if let sdkroot = try driver. toolchain. defaultSDKPath ( driver. targetTriple) {
148+ return ( sdkroot. appending ( components: " usr " , " lib " , " swift " , " windows " ) ,
149+ sdkroot. appending ( components: " usr " , " lib " , " swift " , " shims " ) )
150+ }
151+ return ( toolchainRootPath
152+ . appending ( component: " lib " )
153+ . appending ( component: " swift " )
154+ . appending ( component: driver. targetTriple. osNameUnversioned) ,
155+ toolchainRootPath
156+ . appending ( component: " lib " )
157+ . appending ( component: " swift " )
158+ . appending ( component: " shims " ) )
159+ } else {
160+ return ( toolchainRootPath. appending ( component: " lib " )
161+ . appending ( component: " swift " )
162+ . appending ( component: driver. targetTriple. osNameUnversioned) ,
163+ toolchainRootPath. appending ( component: " lib " )
164+ . appending ( component: " swift " )
165+ . appending ( component: " shims " ) )
166+ }
167+ }
168+
115169/// Test that for the given JSON module dependency graph, valid jobs are generated
116170final class ExplicitModuleBuildTests : XCTestCase {
117171 func testModuleDependencyBuildCommandGeneration( ) throws {
@@ -391,9 +445,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
391445
392446 let checkForLinkLibrary = { ( info: ModuleInfo , linkName: String , isFramework: Bool , shouldForceLoad: Bool ) in
393447 let linkLibraries = try XCTUnwrap ( info. linkLibraries)
394- XCTAssertEqual ( linkLibraries. count, 1 )
395- let linkLibrary = try XCTUnwrap ( linkLibraries. first)
396- XCTAssertEqual ( linkLibrary. linkName, linkName)
448+ let linkLibrary = try XCTUnwrap ( linkLibraries. first { $0. linkName == linkName } )
397449 XCTAssertEqual ( linkLibrary. isFramework, isFramework)
398450 XCTAssertEqual ( linkLibrary. shouldForceLoad, shouldForceLoad)
399451 }
@@ -1339,60 +1391,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
13391391 }
13401392 }
13411393
1342- func getStdlibShimsPaths( _ driver: Driver ) throws -> ( AbsolutePath , AbsolutePath ) {
1343- let toolchainRootPath : AbsolutePath = try driver. toolchain. getToolPath ( . swiftCompiler)
1344- . parentDirectory // bin
1345- . parentDirectory // toolchain root
1346- if driver. targetTriple. isDarwin {
1347- let executor = try SwiftDriverExecutor ( diagnosticsEngine: DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ,
1348- processSet: ProcessSet ( ) ,
1349- fileSystem: localFileSystem,
1350- env: ProcessEnv . vars)
1351- let sdkPath = try executor. checkNonZeroExit (
1352- args: " xcrun " , " -sdk " , " macosx " , " --show-sdk-path " ) . spm_chomp ( )
1353- let stdLibPath = try AbsolutePath ( validating: sdkPath) . appending ( component: " usr " )
1354- . appending ( component: " lib " )
1355- . appending ( component: " swift " )
1356- return ( stdLibPath, stdLibPath. appending ( component: " shims " ) )
1357- } else if driver. targetTriple. isWindows {
1358- if let sdkroot = try driver. toolchain. defaultSDKPath ( driver. targetTriple) {
1359- return ( sdkroot. appending ( components: " usr " , " lib " , " swift " , " windows " ) ,
1360- sdkroot. appending ( components: " usr " , " lib " , " swift " , " shims " ) )
1361- }
1362- return ( toolchainRootPath
1363- . appending ( component: " lib " )
1364- . appending ( component: " swift " )
1365- . appending ( component: driver. targetTriple. osNameUnversioned) ,
1366- toolchainRootPath
1367- . appending ( component: " lib " )
1368- . appending ( component: " swift " )
1369- . appending ( component: " shims " ) )
1370- } else {
1371- return ( toolchainRootPath. appending ( component: " lib " )
1372- . appending ( component: " swift " )
1373- . appending ( component: driver. targetTriple. osNameUnversioned) ,
1374- toolchainRootPath. appending ( component: " lib " )
1375- . appending ( component: " swift " )
1376- . appending ( component: " shims " ) )
1377- }
1378- }
1379-
1380- private func getDriverArtifactsForScanning( ) throws -> ( stdLibPath: AbsolutePath ,
1381- shimsPath: AbsolutePath ,
1382- toolchain: Toolchain ,
1383- hostTriple: Triple ) {
1384- // Just instantiating to get at the toolchain path
1385- let driver = try Driver ( args: [ " swiftc " , " -explicit-module-build " ,
1386- " -module-name " , " testDependencyScanning " ,
1387- " test.swift " ] )
1388- let ( stdLibPath, shimsPath) = try getStdlibShimsPaths ( driver)
1389- XCTAssertTrue ( localFileSystem. exists ( stdLibPath) ,
1390- " expected Swift StdLib at: \( stdLibPath. description) " )
1391- XCTAssertTrue ( localFileSystem. exists ( shimsPath) ,
1392- " expected Swift Shims at: \( shimsPath. description) " )
1393- return ( stdLibPath, shimsPath, driver. toolchain, driver. hostTriple)
1394- }
1395-
13961394 /// Test the libSwiftScan dependency scanning (import-prescan).
13971395 func testDependencyImportPrescan( ) throws {
13981396 let ( stdLibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning ( )
@@ -2090,9 +2088,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
20902088 XCTAssertTrue ( contents. contains ( " \" G \" [style=bold, color=orange " ) )
20912089 XCTAssertTrue ( contents. contains ( " \" E \" [style=bold, color=orange, style=filled " ) )
20922090 XCTAssertTrue ( contents. contains ( " \" C (C) \" [style=bold, color=lightskyblue, style=filled " ) )
2093- XCTAssertTrue ( contents. contains ( " \" Swift \" [style=bold, color=orange, style=filled " ) )
2091+ XCTAssertTrue ( contents. contains ( " \" Swift \" [style=bold, color=orange, style=filled " ) ||
2092+ contents. contains ( " \" Swift (Prebuilt) \" [style=bold, color=darkorange3, style=filled " ) )
20942093 XCTAssertTrue ( contents. contains ( " \" SwiftShims (C) \" [style=bold, color=lightskyblue, style=filled " ) )
2095- XCTAssertTrue ( contents. contains ( " \" Swift \" -> \" SwiftShims (C) \" [color=black]; " ) )
2094+ XCTAssertTrue ( contents. contains ( " \" Swift \" -> \" SwiftShims (C) \" [color=black]; " ) ||
2095+ contents. contains ( " \" Swift (Prebuilt) \" -> \" SwiftShims (C) \" [color=black]; " ) )
20962096 }
20972097 }
20982098
@@ -2237,7 +2237,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
22372237 let moduleCachePath = path. appending ( component: " ModuleCache " )
22382238 try localFileSystem. createDirectory ( moduleCachePath)
22392239 let main = path. appending ( component: " testTraceDependency.swift " )
2240- try localFileSystem. writeFileContents ( main, bytes:
2240+ try localFileSystem. writeFileContents ( main, bytes:
22412241 """
22422242 import C; \
22432243 import E; \
0 commit comments