File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,10 @@ import PackageLoading
17
17
import Foundation
18
18
import SPMBuildCore
19
19
20
- extension AbsolutePath {
21
- fileprivate var asSwiftStringLiteralConstant : String {
22
- return self . pathString. unicodeScalars
23
- . reduce ( " " , { $0 + $1. escaped ( asASCII: false ) } )
24
- }
20
+ extension String {
21
+ fileprivate var asSwiftStringLiteralConstant : String {
22
+ return unicodeScalars. reduce ( " " , { $0 + $1. escaped ( asASCII: false ) } )
23
+ }
25
24
}
26
25
27
26
extension BuildParameters {
@@ -662,17 +661,13 @@ public final class SwiftTargetBuildDescription {
662
661
guard let bundlePath = self . bundlePath else { return }
663
662
664
663
let stream = BufferedOutputByteStream ( )
665
-
666
- let mainPath : AbsolutePath =
667
- AbsolutePath ( Bundle . main. bundlePath) . appending ( component: bundlePath. basename)
668
-
669
664
stream <<< """
670
665
import class Foundation.Bundle
671
666
672
667
extension Foundation.Bundle {
673
668
static var module: Bundle = {
674
- let mainPath = " \( mainPath . asSwiftStringLiteralConstant) "
675
- let buildPath = " \( bundlePath. asSwiftStringLiteralConstant) "
669
+ let mainPath = Bundle.main.bundleURL.appendingPathComponent( " \( bundlePath . basename . asSwiftStringLiteralConstant) " ).path
670
+ let buildPath = " \( bundlePath. pathString . asSwiftStringLiteralConstant) "
676
671
677
672
let preferredBundle = Bundle(path: mainPath)
678
673
Original file line number Diff line number Diff line change @@ -2464,6 +2464,9 @@ final class BuildPlanTests: XCTestCase {
2464
2464
let resourceAccessor = fooTarget. sources. first { $0. basename == " resource_bundle_accessor.swift " } !
2465
2465
let contents = try fs. readFileContents ( resourceAccessor) . cString
2466
2466
XCTAssertTrue ( contents. contains ( " extension Foundation.Bundle " ) , contents)
2467
+ // Assert that `Bundle.main` is executed in the compiled binary (and not during compilation)
2468
+ // See https://bugs.swift.org/browse/SR-14555 and https://github.com/apple/swift-package-manager/pull/2972/files#r623861646
2469
+ XCTAssertTrue ( contents. contains ( " let mainPath = Bundle.main. " ) , contents)
2467
2470
2468
2471
let barTarget = try result. target ( for: " Bar " ) . swiftTarget ( )
2469
2472
XCTAssertEqual ( barTarget. objects. map { $0. pathString } , [
You can’t perform that action at this time.
0 commit comments