Skip to content

Commit 9fe4642

Browse files
authored
Merge pull request #2972 from compnerd/quoted
Build: quote the path string for bundle resources
2 parents 5abb16c + 47472ae commit 9fe4642

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import PackageLoading
1616
import Foundation
1717
import SPMBuildCore
1818

19+
extension AbsolutePath {
20+
fileprivate var asSwiftStringLiteralConstant: String {
21+
return self.pathString.unicodeScalars
22+
.reduce("", { $0 + $1.escaped(asASCII: false) })
23+
}
24+
}
25+
1926
extension BuildParameters {
2027
/// Returns the directory to be used for module cache.
2128
public var moduleCache: AbsolutePath {
@@ -576,13 +583,17 @@ public final class SwiftTargetBuildDescription {
576583
guard let bundlePath = self.bundlePath else { return }
577584

578585
let stream = BufferedOutputByteStream()
586+
587+
let mainPath: AbsolutePath =
588+
AbsolutePath(Bundle.main.bundlePath).appending(component: bundlePath.basename)
589+
579590
stream <<< """
580591
import class Foundation.Bundle
581592
582593
extension Foundation.Bundle {
583594
static var module: Bundle = {
584-
let mainPath = Bundle.main.bundlePath + "/" + "\(bundlePath.basename)"
585-
let buildPath = "\(bundlePath.pathString)"
595+
let mainPath = "\(mainPath.asSwiftStringLiteralConstant)"
596+
let buildPath = "\(bundlePath.asSwiftStringLiteralConstant)"
586597
587598
let preferredBundle = Bundle(path: mainPath)
588599

0 commit comments

Comments
 (0)