Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import PackageLoading
import Foundation
import SPMBuildCore

extension AbsolutePath {
fileprivate var asSwiftStringLiteralConstant: String {
return self.pathString.unicodeScalars
.reduce("", { $0 + $1.escaped(asASCII: false) })
}
}

extension BuildParameters {
/// Returns the directory to be used for module cache.
public var moduleCache: AbsolutePath {
Expand Down Expand Up @@ -576,13 +583,17 @@ public final class SwiftTargetBuildDescription {
guard let bundlePath = self.bundlePath else { return }

let stream = BufferedOutputByteStream()

let mainPath: AbsolutePath =
AbsolutePath(Bundle.main.bundlePath).appending(component: bundlePath.basename)

stream <<< """
import class Foundation.Bundle

extension Foundation.Bundle {
static var module: Bundle = {
let mainPath = Bundle.main.bundlePath + "/" + "\(bundlePath.basename)"
Copy link
Contributor

@ffried ffried Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change actually broke the lookup for resource bundles. Since Bundle.main is now executed inside the swift build context, mainPath is now /usr/bin on linux instead of the location of the output binary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the call to Bundle.main back to the generated code in #3463

let buildPath = "\(bundlePath.pathString)"
let mainPath = "\(mainPath.asSwiftStringLiteralConstant)"
let buildPath = "\(bundlePath.asSwiftStringLiteralConstant)"

let preferredBundle = Bundle(path: mainPath)

Expand Down