@@ -592,6 +592,63 @@ final class ExplicitModuleBuildTests: XCTestCase {
592592 #endif
593593 }
594594
595+ func testModuleAliasingWithExplicitBuild( ) throws {
596+ try withTemporaryDirectory { path in
597+ try localFileSystem. changeCurrentWorkingDirectory ( to: path)
598+ let srcBar = path. appending ( component: " bar.swift " )
599+ let moduleBarPath = path. appending ( component: " Bar.swiftmodule " ) . pathString. nativePathString ( ) . escaped ( )
600+ try localFileSystem. writeFileContents ( srcBar) {
601+ $0 <<< " public class KlassBar {} "
602+ }
603+
604+ let sdkArgumentsForTesting = ( try ? Driver . sdkArgumentsForTesting ( ) ) ?? [ ]
605+ var driver1 = try Driver ( args: [ " swiftc " ,
606+ " -explicit-module-build " ,
607+ " -module-name " ,
608+ " Bar " ,
609+ " -emit-module " ,
610+ " -emit-module-path " ,
611+ moduleBarPath,
612+ srcBar. pathString. nativePathString ( ) . escaped ( ) ] + sdkArgumentsForTesting,
613+ env: ProcessEnv . vars)
614+ let jobs1 = try driver1. planBuild ( )
615+ try driver1. run ( jobs: jobs1)
616+ XCTAssertFalse ( driver1. diagnosticEngine. hasErrors)
617+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: moduleBarPath) )
618+
619+ let srcFoo = path. appending ( component: " foo.swift " )
620+ let moduleFooPath = path. appending ( component: " Foo.swiftmodule " ) . pathString. nativePathString ( ) . escaped ( )
621+
622+ // Module Foo imports Car but it's mapped to Bar (real name)
623+ // `-module-alias Car=Bar` allows Car (alias) to be referenced
624+ // in source files in Foo, but its contents will be compiled
625+ // as Bar (real name on-disk).
626+ try localFileSystem. writeFileContents ( srcFoo) {
627+ $0 <<< " import Car \n "
628+ $0 <<< " func run() -> Car.KlassBar? { return nil } "
629+ }
630+ var driver2 = try Driver ( args: [ " swiftc " ,
631+ " -I " ,
632+ path. pathString. nativePathString ( ) . escaped ( ) ,
633+ " -j " ,
634+ " 1 " ,
635+ " -explicit-module-build " ,
636+ " -module-name " ,
637+ " Foo " ,
638+ " -emit-module " ,
639+ " -emit-module-path " ,
640+ moduleFooPath,
641+ " -module-alias " ,
642+ " Car=Bar " ,
643+ srcFoo. pathString. nativePathString ( ) . escaped ( ) ] + sdkArgumentsForTesting,
644+ env: ProcessEnv . vars)
645+ let jobs2 = try driver2. planBuild ( )
646+ try driver2. run ( jobs: jobs2)
647+ XCTAssertFalse ( driver2. diagnosticEngine. hasErrors)
648+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: moduleFooPath) )
649+ }
650+ }
651+
595652 func testExplicitModuleBuildEndToEnd( ) throws {
596653 // The macOS-only restriction is temporary while Clang's dependency scanner
597654 // is gaining the ability to perform name-based module lookup.
0 commit comments