@@ -1517,6 +1517,50 @@ final class ExplicitModuleBuildTests: XCTestCase {
1517
1517
}
1518
1518
}
1519
1519
1520
+ // Ensure dependency scanning succeeds via fallback `swift-frontend -scan-dependenceis`
1521
+ // mechanism if libSwiftScan.dylib fails to load.
1522
+ func testDependencyScanningFallback( ) throws {
1523
+ let ( stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning ( )
1524
+
1525
+ // Create a simple test case.
1526
+ try withTemporaryDirectory { path in
1527
+ let main = path. appending ( component: " testDependencyScanningFallback.swift " )
1528
+ try localFileSystem. writeFileContents ( main, bytes: " import C; " )
1529
+
1530
+ let dummyBrokenDylib = path. appending ( component: " lib_InternalSwiftScan.dylib " )
1531
+ try localFileSystem. writeFileContents ( dummyBrokenDylib, bytes: " n/a " )
1532
+
1533
+ var environment = ProcessEnv . vars
1534
+ environment [ " SWIFT_DRIVER_SWIFTSCAN_LIB " ] = dummyBrokenDylib. nativePathString ( escaped: true )
1535
+
1536
+ let cHeadersPath : AbsolutePath =
1537
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
1538
+ . appending ( component: " CHeaders " )
1539
+ let swiftModuleInterfacesPath : AbsolutePath =
1540
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
1541
+ . appending ( component: " Swift " )
1542
+ let sdkArgumentsForTesting = ( try ? Driver . sdkArgumentsForTesting ( ) ) ?? [ ]
1543
+ var driver = try Driver ( args: [ " swiftc " ,
1544
+ " -I " , cHeadersPath. nativePathString ( escaped: true ) ,
1545
+ " -I " , swiftModuleInterfacesPath. nativePathString ( escaped: true ) ,
1546
+ " -I " , stdlibPath. nativePathString ( escaped: true ) ,
1547
+ " -I " , shimsPath. nativePathString ( escaped: true ) ,
1548
+ " /tmp/Foo.o " ,
1549
+ " -explicit-module-build " ,
1550
+ " -working-directory " , path. nativePathString ( escaped: true ) ,
1551
+ " -disable-clang-target " ,
1552
+ main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
1553
+ env: environment)
1554
+ let interModuleDependencyGraph = try driver. performDependencyScan ( )
1555
+
1556
+
1557
+ print ( driver. diagnosticEngine. diagnostics)
1558
+ XCTAssertTrue ( driver. diagnosticEngine. diagnostics. contains { $0. behavior == . remark &&
1559
+ $0. message. text == " In-process dependency scan query failed due to incompatible libSwiftScan ( \( dummyBrokenDylib. nativePathString ( escaped: true ) ) ). Fallback to `swift-frontend` dependency scanner invocation. " } )
1560
+ XCTAssertTrue ( interModuleDependencyGraph. mainModule. directDependencies? . contains ( where: { $0. moduleName == " C " } ) )
1561
+ }
1562
+ }
1563
+
1520
1564
func testParallelDependencyScanningDiagnostics( ) throws {
1521
1565
let ( stdlibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning ( )
1522
1566
// The dependency oracle wraps an instance of libSwiftScan and ensures thread safety across
0 commit comments