@@ -174,14 +174,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
174174 for job in modulePrebuildJobs {
175175 XCTAssertEqual ( job. outputs. count, 1 )
176176 XCTAssertFalse ( driver. isExplicitMainModuleJob ( job: job) )
177- let pcmFileEncoder = { ( moduleInfo: ModuleInfo , hashParts: [ String ] ) -> VirtualPath . Handle in
178- try ! driver. explicitDependencyBuildPlanner!. targetEncodedClangModuleFilePath ( for: moduleInfo,
179- hashParts: hashParts)
180- }
181- let pcmModuleNameEncoder = { ( moduleName: String , hashParts: [ String ] ) -> String in
182- try ! driver. explicitDependencyBuildPlanner!. targetEncodedClangModuleName ( for: moduleName,
183- hashParts: hashParts)
184- }
177+
178+ let ( pcmFileEncoder, pcmModuleNameEncoder) = pcmEncoderProducer ( dependencyGraph: moduleDependencyGraph, driver: driver)
185179 switch ( job. outputs [ 0 ] . file) {
186180 case . relative( pcmArgsEncodedRelativeModulePath ( for: " SwiftShims " , with: pcmArgs,
187181 pcmModuleNameEncoder: pcmModuleNameEncoder) ) :
@@ -268,6 +262,39 @@ final class ExplicitModuleBuildTests: XCTestCase {
268262 path. extension! == FileType . swiftModule. rawValue
269263 }
270264
265+ private func pcmEncoderProducer( dependencyGraph: InterModuleDependencyGraph ,
266+ driver: Driver )
267+ -> ( ( ModuleInfo , [ String ] ) -> VirtualPath . Handle , ( String , [ String ] ) -> String ) {
268+ var driverCopy = driver
269+ let moduleMapIncludedHashParts = { ( _ moduleName: String , _ hashParts: [ String ] ) -> [ String ] in
270+ let moduleDetails = try ? dependencyGraph. clangModuleDetails ( of: . clang( moduleName) )
271+ let lookupHashParts : [ String ]
272+ if let details = moduleDetails {
273+ let moduleMapPath = details. moduleMapPath. path. description
274+ lookupHashParts = [ moduleMapPath] + hashParts
275+ } else {
276+ // No such module found, no modulemap
277+ lookupHashParts = hashParts
278+ }
279+ return lookupHashParts
280+ }
281+
282+ let pcmFileEncoder = { ( moduleInfo: ModuleInfo , hashParts: [ String ] ) -> VirtualPath . Handle in
283+ let plainModulePath = VirtualPath . lookup ( moduleInfo. modulePath. path)
284+ let moduleName = plainModulePath. basenameWithoutExt
285+ let lookupHashParts = moduleMapIncludedHashParts ( moduleName, hashParts)
286+ return try ! driverCopy. explicitDependencyBuildPlanner!. targetEncodedClangModuleFilePath ( for: moduleInfo,
287+ hashParts: lookupHashParts)
288+ }
289+
290+ let pcmModuleNameEncoder = { ( moduleName: String , hashParts: [ String ] ) -> String in
291+ let lookupHashParts = moduleMapIncludedHashParts ( moduleName, hashParts)
292+ return try ! driverCopy. explicitDependencyBuildPlanner!. targetEncodedClangModuleName ( for: moduleName,
293+ hashParts: lookupHashParts)
294+ }
295+ return ( pcmFileEncoder, pcmModuleNameEncoder)
296+ }
297+
271298 /// Test generation of explicit module build jobs for dependency modules when the driver
272299 /// is invoked with -experimental-explicit-module-build
273300 func testExplicitModuleBuildJobs( ) throws {
@@ -308,14 +335,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
308335 pcmArgs9. append ( contentsOf: [ " -Xcc " , " -fapinotes-swift-version=5 " ] )
309336 pcmArgs15. append ( contentsOf: [ " -Xcc " , " -fapinotes-swift-version=5 " ] )
310337 }
311- let pcmFileEncoder = { ( moduleInfo: ModuleInfo , hashParts: [ String ] ) -> VirtualPath . Handle in
312- try ! driver. explicitDependencyBuildPlanner!. targetEncodedClangModuleFilePath ( for: moduleInfo,
313- hashParts: hashParts)
314- }
315- let pcmModuleNameEncoder = { ( moduleName: String , hashParts: [ String ] ) -> String in
316- try ! driver. explicitDependencyBuildPlanner!. targetEncodedClangModuleName ( for: moduleName,
317- hashParts: hashParts)
318- }
338+
339+ let ( pcmFileEncoder, pcmModuleNameEncoder) = pcmEncoderProducer ( dependencyGraph: dependencyGraph, driver: driver)
319340
320341 for job in jobs {
321342 XCTAssertEqual ( job. outputs. count, 1 )
@@ -352,6 +373,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
352373 // Clang Dependencies
353374 } else if outputFilePath. extension != nil ,
354375 outputFilePath. extension! == FileType . pcm. rawValue {
376+
355377 switch ( outputFilePath) {
356378 case . relative( pcmArgsEncodedRelativeModulePath ( for: " A " , with: pcmArgsCurrent,
357379 pcmModuleNameEncoder: pcmModuleNameEncoder) ) :
@@ -470,14 +492,9 @@ final class ExplicitModuleBuildTests: XCTestCase {
470492 pcmArgs9. append ( contentsOf: [ " -Xcc " , " -fapinotes-swift-version=5 " ] )
471493 pcmArgs15. append ( contentsOf: [ " -Xcc " , " -fapinotes-swift-version=5 " ] )
472494 }
473- let pcmFileEncoder = { ( moduleInfo: ModuleInfo , hashParts: [ String ] ) -> VirtualPath . Handle in
474- try ! driver. explicitDependencyBuildPlanner!. targetEncodedClangModuleFilePath ( for: moduleInfo,
475- hashParts: hashParts)
476- }
477- let pcmModuleNameEncoder = { ( moduleName: String , hashParts: [ String ] ) -> String in
478- try ! driver. explicitDependencyBuildPlanner!. targetEncodedClangModuleName ( for: moduleName,
479- hashParts: hashParts)
480- }
495+
496+ let ( pcmFileEncoder, pcmModuleNameEncoder) = pcmEncoderProducer ( dependencyGraph: dependencyGraph, driver: driver)
497+
481498 for job in jobs {
482499 guard job. kind != . interpret else { continue }
483500 XCTAssertEqual ( job. outputs. count, 1 )
0 commit comments