Skip to content

Commit 7fd2fce

Browse files
committed
Build: quote the path string for bundle resources
We need to ensure that we escape `\` for paths in strings. This enables using bundles for tests on Windows.
1 parent 21152b8 commit 7fd2fce

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,21 @@ public final class SwiftTargetBuildDescription {
576576
guard let bundlePath = self.bundlePath else { return }
577577

578578
let stream = BufferedOutputByteStream()
579+
580+
let mainPath: String = AbsolutePath(Bundle.main.bundlePath)
581+
.appending(component: bundlePath.basename)
582+
.pathString
583+
.replacingOccurrences(of: "\\", with: "\\\\")
584+
let buildPath: String =
585+
bundlePath.pathString.replacingOccurrences(of: "\\", with: "\\\\")
586+
579587
stream <<< """
580588
import class Foundation.Bundle
581589
582590
extension Foundation.Bundle {
583591
static var module: Bundle = {
584-
let mainPath = Bundle.main.bundlePath + "/" + "\(bundlePath.basename)"
585-
let buildPath = "\(bundlePath.pathString)"
592+
let mainPath = "\(mainPath)"
593+
let buildPath = "\(buildPath)"
586594
587595
let preferredBundle = Bundle(path: mainPath)
588596

0 commit comments

Comments
 (0)