@@ -387,13 +387,12 @@ extension PackagePIFProjectBuilder {
387387 }
388388
389389 // Generate a module map file, if needed.
390- var moduleMapFileContents = " "
391- let generatedModuleMapDir = " $(GENERATED_MODULEMAP_DIR) "
392- var generatedModuleMapPath = try RelativePath ( validating: " \( generatedModuleMapDir) / \( sourceModule. name) .modulemap " ) . pathString
390+ let moduleMapFileContents : String ?
391+ let moduleMapPath : String ?
393392
394393 if sourceModule. usesSwift && desiredModuleType != . macro {
395394 // Generate ObjC compatibility header for Swift library targets.
396- settings [ . SWIFT_OBJC_INTERFACE_HEADER_DIR] = generatedModuleMapDir
395+ settings [ . SWIFT_OBJC_INTERFACE_HEADER_DIR] = " $(GENERATED_MODULEMAP_DIR) "
397396 settings [ . SWIFT_OBJC_INTERFACE_HEADER_NAME] = " \( sourceModule. name) -Swift.h "
398397
399398 moduleMapFileContents = """
@@ -402,6 +401,8 @@ extension PackagePIFProjectBuilder {
402401 export *
403402 }
404403 """
404+ let generatedModuleMapPath = try RelativePath ( validating: " $(GENERATED_MODULEMAP_DIR)/ \( sourceModule. name) .modulemap " ) . pathString
405+ moduleMapPath = generatedModuleMapPath
405406 // We only need to impart this to C clients.
406407 impartedSettings [ . OTHER_CFLAGS] = [ " -fmodule-map-file= \( generatedModuleMapPath) " , " $(inherited) " ]
407408 } else {
@@ -418,13 +419,18 @@ extension PackagePIFProjectBuilder {
418419 // The modulemap was already generated, we should explicitly impart it on dependents,
419420 impartedSettings [ . OTHER_CFLAGS] = [ " -fmodule-map-file= \( pluginGeneratedModuleMapPath) " , " $(inherited) " ]
420421 impartedSettings [ . OTHER_SWIFT_FLAGS] = [ " -Xcc " , " -fmodule-map-file= \( pluginGeneratedModuleMapPath) " , " $(inherited) " ]
421- generatedModuleMapPath = pluginGeneratedModuleMapPath. pathString
422+ moduleMapFileContents = nil
423+ moduleMapPath = pluginGeneratedModuleMapPath. pathString
422424 } else {
423425 switch sourceModule. moduleMapType {
424426 case nil , . some( . none) :
425427 // No modulemap, no action required.
428+ moduleMapFileContents = nil
429+ moduleMapPath = nil
426430 break
427431 case . custom( let customModuleMapPath) :
432+ moduleMapFileContents = nil
433+ moduleMapPath = customModuleMapPath. pathString
428434 // We don't need to generate a modulemap, but we should explicitly impart it on dependents,
429435 // even if it will appear in search paths. See: https://github.com/swiftlang/swift-package-manager/issues/9290
430436 impartedSettings [ . OTHER_CFLAGS] = [ " -fmodule-map-file= \( customModuleMapPath) " , " $(inherited) " ]
@@ -437,6 +443,8 @@ extension PackagePIFProjectBuilder {
437443 export *
438444 }
439445 """
446+ let generatedModuleMapPath = try RelativePath ( validating: " $(GENERATED_MODULEMAP_DIR)/ \( sourceModule. name) .modulemap " ) . pathString
447+ moduleMapPath = generatedModuleMapPath
440448 // Pass the path of the module map up to all direct and indirect clients.
441449 impartedSettings [ . OTHER_CFLAGS] = [ " -fmodule-map-file= \( generatedModuleMapPath) " , " $(inherited) " ]
442450 impartedSettings [ . OTHER_SWIFT_FLAGS] = [ " -Xcc " , " -fmodule-map-file= \( generatedModuleMapPath) " , " $(inherited) " ]
@@ -448,6 +456,8 @@ extension PackagePIFProjectBuilder {
448456 export *
449457 }
450458 """
459+ let generatedModuleMapPath = try RelativePath ( validating: " $(GENERATED_MODULEMAP_DIR)/ \( sourceModule. name) .modulemap " ) . pathString
460+ moduleMapPath = generatedModuleMapPath
451461 // Pass the path of the module map up to all direct and indirect clients.
452462 impartedSettings [ . OTHER_CFLAGS] = [ " -fmodule-map-file= \( generatedModuleMapPath) " , " $(inherited) " ]
453463 impartedSettings [ . OTHER_SWIFT_FLAGS] = [ " -Xcc " , " -fmodule-map-file= \( generatedModuleMapPath) " , " $(inherited) " ]
@@ -524,8 +534,12 @@ extension PackagePIFProjectBuilder {
524534 }
525535
526536 settings [ . PACKAGE_RESOURCE_TARGET_KIND] = " regular "
527- settings [ . MODULEMAP_FILE_CONTENTS] = moduleMapFileContents
528- settings [ . MODULEMAP_PATH] = generatedModuleMapPath
537+ if let moduleMapFileContents {
538+ settings [ . MODULEMAP_FILE_CONTENTS] = moduleMapFileContents
539+ }
540+ if let moduleMapPath {
541+ settings [ . MODULEMAP_PATH] = moduleMapPath
542+ }
529543 settings [ . DEFINES_MODULE] = " YES "
530544
531545 // Settings for text-based API.
0 commit comments