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?
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.
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.
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
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
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.