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 @@ -18,11 +18,10 @@ import Foundation
18
18
import SPMBuildCore
19
19
@_implementationOnly import SwiftDriver
20
20
21
- extension AbsolutePath {
22
- fileprivate var asSwiftStringLiteralConstant : String {
23
- return self . pathString. unicodeScalars
24
- . reduce ( " " , { $0 + $1. escaped ( asASCII: false ) } )
25
- }
21
+ extension String {
22
+ fileprivate var asSwiftStringLiteralConstant : String {
23
+ return unicodeScalars. reduce ( " " , { $0 + $1. escaped ( asASCII: false ) } )
24
+ }
26
25
}
27
26
28
27
extension BuildParameters {
@@ -663,17 +662,13 @@ public final class SwiftTargetBuildDescription {
663
662
guard let bundlePath = self . bundlePath else { return }
664
663
665
664
let stream = BufferedOutputByteStream ( )
666
-
667
- let mainPath : AbsolutePath =
668
- AbsolutePath ( Bundle . main. bundlePath) . appending ( component: bundlePath. basename)
669
-
670
665
stream <<< """
671
666
import class Foundation.Bundle
672
667
673
668
extension Foundation.Bundle {
674
669
static var module: Bundle = {
675
- let mainPath = " \( mainPath . asSwiftStringLiteralConstant) "
676
- let buildPath = " \( bundlePath. asSwiftStringLiteralConstant) "
670
+ let mainPath = Bundle.main.bundleURL.appendingPathComponent( " \( bundlePath . basename . asSwiftStringLiteralConstant) " ).path
671
+ let buildPath = " \( bundlePath. pathString . asSwiftStringLiteralConstant) "
677
672
678
673
let preferredBundle = Bundle(path: mainPath)
679
674
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