thomasvl
(Thomas Van Lenten)
1
I'm trying to update one project to use the new Resources support, and I'm not sure if this is a case of I'm holding it wrong or something else.
GitHub - google/gtm-session-fetcher: Google Toolbox for Mac - Session Fetcher is ObjC code, but we have a basic SwiftPM package. The tests need some resources, so it was hot-wired in the code to work around things, but I made an attempt to things over. If I open the Package.swift in Xcode 12, then the tests seem to build/pass; but if I try to use swift test on the command line, then SWIFTPM_MODULE_BUNDLE seems to always be returning me nil. I'm assuming there shouldn't be a difference in behavior for this case, do I have something configured wrong?
3 Likes
NeoNacho
(Boris Buegling)
2
thomasvl
(Thomas Van Lenten)
3
I don't think I'm hitting that, because the tests don't crash (the fatalError in the diff?); SWIFTPM_MODULE_BUNDLE is resulting in nil under swift test.
thomasvl
(Thomas Van Lenten)
4
paulb777
(Paul Beusterien)
5
I worked around swift test issues by using xcodebuild for testing.
1 Like
NeoNacho
(Boris Buegling)
6
Yep, you're right. I just double-checked and these are two separate issues.
thomasvl
(Thomas Van Lenten)
7
I'm guessing no workaround, so need to wait for a fix and then a new Swift release?
NeoNacho
(Boris Buegling)
8
Can't think of a good workaround, but it may be possible to declare a Swift target which contains the resources and just exposes its Bundle.module via a public accessor. The ObjC target could then use that accessor to get to the bundle.
BrentM
(Brent Mifsud)
9
Has there been any progress on this? Seems to also be happening for pure swift projects as well.
I have a project where I have included resources in my test bundle.
Building, testing, accessing the module bundle within Xcode works fine.
running swift test and swift test --generate-linuxmain fail with the following error:
Fatal error: could not load resource bundle: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec/swift/pm/BeartoothSDK_BeartoothSDKTests.bundle: file BeartoothSDKTests/resource_bundle_accessor.swift, line 7
here's my package manifest:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "BeartoothSDK",
products: [
.library(name: "BeartoothSDK", targets: ["BeartoothSDK"]),
],
dependencies: [],
targets: [
.target(name: "BeartoothSDK", dependencies: []),
.testTarget(
name: "BeartoothSDKTests",
dependencies: ["BeartoothSDK"],
resources: [.process("Resources")]
),
]
)
Cocoanetics
(Oliver Drobnik)
10
Oh boy. I just hit the same problem as well. The accessor gets created, but it points to the wrong path. There seems to be a problem in the way the accessor figures out the path of the final product.
it tries to load the resource bundle from /Applications/Xcode.app/Contents/Developer/usr/bin/Kvitto_KvittoTests.bundle which obviously is the wrong place.
For unit tests this is the command that gets executed, which you see if you run swift test --verbose
/Applications/Xcode.app/Contents/Developer/usr/bin/xctest /Users/oliver/Projects/Kvitto/.build/x86_64-apple-macosx/debug/KvittoPackageTests.xctest
BrentM
(Brent Mifsud)
11
I created a bug report on the swift jira for this... not sure if that was the right place:
thomasvl
(Thomas Van Lenten)
12
I opened one back in comment 4:
BrentM
(Brent Mifsud)
13
awesome. I will close mine and reference yours.
BrentM
(Brent Mifsud)
14
tried generating an Xcode project specifically for this workaround. Seems like the extension for Bundle.module never gets generated in this case...
BrentM
(Brent Mifsud)
15
after some digging, looks like its fixed and shipping with Xcode 12.2: https://github.com/apple/swift-package-manager/pull/2817
thomasvl
(Thomas Van Lenten)
16
I don't think that is a fix.
There's a comment on it about pulling it over into the 5.3 branch. That PR mentions that it doesn't fix the issue I reported. So at this point Xcode 12.2 is likely still going to fail in this case.
thomasvl
(Thomas Van Lenten)
17
Just tried things with Swift 5.5, and I'm still getting nil for SWIFTPM_MODULE_BUNDLE
bradhowes
(Brad Howes)
18
I think I am hitting the same issue. Was it ever resolved for anyone via a workaround? I've tried adding various unsafe flags in Package.swift to try and reproduce what Xcode does but I cannot get xcodebuild to succeed where swift build does. Of course, it took me a lot of tweaking to get swift build to work at all while Xcode 13.2 would compile and run tests without issue.
For what its worth, this is what I am trying to build/test via command-line: https://github.com/bradhowes/SF2Lib
1 Like