Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Sources/PackageLoading/ModuleMapGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ import TSCBasic
/// Name of the module map file recognized by the Clang and Swift compilers.
public let moduleMapFilename = "module.modulemap"

extension Basics.AbsolutePath {
fileprivate var moduleEscapedPathString: String {
return self.pathString.replacing("\\", with: "\\\\")
}
}

/// A protocol for targets which might have a modulemap.
protocol ModuleMapProtocol {
var moduleMapPath: Basics.AbsolutePath { get }
Expand Down Expand Up @@ -179,9 +173,9 @@ public struct ModuleMapGenerator {
var moduleMap = "module \(moduleName) {\n"
switch type {
case .umbrellaHeader(let hdr):
moduleMap.append(" umbrella header \"\(hdr.moduleEscapedPathString)\"\n")
moduleMap.append(" umbrella header \"\(hdr.escapedPathString)\"\n")
case .umbrellaDirectory(let dir):
moduleMap.append(" umbrella \"\(dir.moduleEscapedPathString)\"\n")
moduleMap.append(" umbrella \"\(dir.escapedPathString)\"\n")
}
moduleMap.append(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Foundation
import TSCUtility

import struct Basics.AbsolutePath
import struct Basics.RelativePath
import class Basics.ObservabilitySystem
import func Basics.resolveSymlinks
import struct Basics.SourceControlURL
Expand Down Expand Up @@ -352,8 +353,8 @@ extension PackagePIFProjectBuilder {

// Generate a module map file, if needed.
var moduleMapFileContents = ""
var moduleMapFile = ""
let generatedModuleMapDir = "$(GENERATED_MODULEMAP_DIR)"
let moduleMapFile = try RelativePath(validating:"\(generatedModuleMapDir)/\(sourceModule.name).modulemap").pathString

if sourceModule.usesSwift && desiredModuleType != .macro {
// Generate ObjC compatibility header for Swift library targets.
Expand All @@ -366,8 +367,6 @@ extension PackagePIFProjectBuilder {
export *
}
"""
moduleMapFile = "\(generatedModuleMapDir)/\(sourceModule.name).modulemap"

// We only need to impart this to C clients.
impartedSettings[.OTHER_CFLAGS] = ["-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
} else if sourceModule.moduleMapFileRelativePath(fileSystem: self.pifBuilder.fileSystem) == nil {
Expand All @@ -376,22 +375,21 @@ extension PackagePIFProjectBuilder {
log(.debug, "\(package.name).\(sourceModule.name) generated umbrella header")
moduleMapFileContents = """
module \(sourceModule.c99name) {
umbrella header "\(path)"
umbrella header "\(path.escapedPathString)"
export *
}
"""
} else if case .umbrellaDirectory(let path) = sourceModule.moduleMapType {
log(.debug, "\(package.name).\(sourceModule.name) generated umbrella directory")
moduleMapFileContents = """
module \(sourceModule.c99name) {
umbrella "\(path)"
umbrella "\(path.escapedPathString)"
export *
}
"""
}
if moduleMapFileContents.hasContent {
// Pass the path of the module map up to all direct and indirect clients.
moduleMapFile = "\(generatedModuleMapDir)/\(sourceModule.name).modulemap"
impartedSettings[.OTHER_CFLAGS] = ["-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
impartedSettings[.OTHER_SWIFT_FLAGS] = ["-Xcc", "-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
}
Expand Down