Skip to content

Commit d51a31c

Browse files
committed
PackageLoading: escape \ when generating the modulemap
The `pathString` is overloaded and used as both a printing string and a path string. When used to generate the module map, we need to escape the path separator as it is an escape sequence indicator otherwise. This allows us to generate modulemaps which can be consumed by clang on Windows.
1 parent 1bcf98d commit d51a31c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/PackageLoading/ModuleMapGenerator.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111
import TSCBasic
1212
import PackageModel
13+
import Foundation
1314

1415
public let moduleMapFilename = "module.modulemap"
1516

17+
extension AbsolutePath {
18+
fileprivate var moduleEscapedPathString: String {
19+
return self.pathString.replacingOccurrences(of: "\\", with: "\\\\")
20+
}
21+
}
22+
1623
/// A protocol for targets which might have a modulemap.
1724
protocol ModuleMapProtocol {
1825
var moduleMapPath: AbsolutePath { get }
@@ -152,9 +159,9 @@ public struct ModuleMapGenerator {
152159
stream <<< "module \(target.c99name) {\n"
153160
switch type {
154161
case .header(let header):
155-
stream <<< " umbrella header \"\(header.pathString)\"\n"
162+
stream <<< " umbrella header \"\(header.moduleEscapedPathString)\"\n"
156163
case .directory(let path):
157-
stream <<< " umbrella \"\(path.pathString)\"\n"
164+
stream <<< " umbrella \"\(path.moduleEscapedPathString)\"\n"
158165
}
159166
stream <<< " export *\n"
160167
stream <<< "}\n"

0 commit comments

Comments
 (0)