Skip to content

Commit 87b54d3

Browse files
committed
fix modulemap generation on window using swift-build
- Windows paths need to be escaped
1 parent 7046c68 commit 87b54d3

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

Sources/PackageLoading/ModuleMapGenerator.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ import TSCBasic
1818
/// Name of the module map file recognized by the Clang and Swift compilers.
1919
public let moduleMapFilename = "module.modulemap"
2020

21-
extension Basics.AbsolutePath {
22-
fileprivate var moduleEscapedPathString: String {
23-
return self.pathString.replacing("\\", with: "\\\\")
24-
}
25-
}
26-
2721
/// A protocol for targets which might have a modulemap.
2822
protocol ModuleMapProtocol {
2923
var moduleMapPath: Basics.AbsolutePath { get }
@@ -179,9 +173,9 @@ public struct ModuleMapGenerator {
179173
var moduleMap = "module \(moduleName) {\n"
180174
switch type {
181175
case .umbrellaHeader(let hdr):
182-
moduleMap.append(" umbrella header \"\(hdr.moduleEscapedPathString)\"\n")
176+
moduleMap.append(" umbrella header \"\(hdr.escapedPathString)\"\n")
183177
case .umbrellaDirectory(let dir):
184-
moduleMap.append(" umbrella \"\(dir.moduleEscapedPathString)\"\n")
178+
moduleMap.append(" umbrella \"\(dir.escapedPathString)\"\n")
185179
}
186180
moduleMap.append(
187181
"""

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Foundation
1414
import TSCUtility
1515

1616
import struct Basics.AbsolutePath
17+
import struct Basics.RelativePath
1718
import class Basics.ObservabilitySystem
1819
import func Basics.resolveSymlinks
1920
import struct Basics.SourceControlURL
@@ -366,7 +367,7 @@ extension PackagePIFProjectBuilder {
366367
export *
367368
}
368369
"""
369-
moduleMapFile = "\(generatedModuleMapDir)/\(sourceModule.name).modulemap"
370+
moduleMapFile = try RelativePath(validating:"\(generatedModuleMapDir)/\(sourceModule.name).modulemap").pathString
370371

371372
// We only need to impart this to C clients.
372373
impartedSettings[.OTHER_CFLAGS] = ["-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
@@ -376,15 +377,15 @@ extension PackagePIFProjectBuilder {
376377
log(.debug, "\(package.name).\(sourceModule.name) generated umbrella header")
377378
moduleMapFileContents = """
378379
module \(sourceModule.c99name) {
379-
umbrella header "\(path)"
380+
umbrella header "\(path.escapedPathString)"
380381
export *
381382
}
382383
"""
383384
} else if case .umbrellaDirectory(let path) = sourceModule.moduleMapType {
384385
log(.debug, "\(package.name).\(sourceModule.name) generated umbrella directory")
385386
moduleMapFileContents = """
386387
module \(sourceModule.c99name) {
387-
umbrella "\(path)"
388+
umbrella "\(path.escapedPathString)"
388389
export *
389390
}
390391
"""

0 commit comments

Comments
 (0)