Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13560] swiftpm: SWIFTPM_MODULE_BUNDLE returning nil #4500

Closed
thomasvl opened this issue Sep 17, 2020 · 6 comments · Fixed by #5921
Closed

[SR-13560] swiftpm: SWIFTPM_MODULE_BUNDLE returning nil #4500

thomasvl opened this issue Sep 17, 2020 · 6 comments · Fixed by #5921
Assignees
Labels

Comments

@thomasvl
Copy link
Contributor

Previous ID SR-13560
Radar rdar://problem/69090207
Original Reporter @thomasvl
Type Bug
Additional Detail from JIRA
Votes 5
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 54f1a590f07af2575ba60b5ea19e1321

is duplicated by:

  • SR-13714 'Swift test' fails when including package resources

Issue Description:

An all ObjC package is getting nil from SWIFTPM_MODULE_BUNDLE when using swift test, but if the Package.swift is directly opened in Xcode 12, then the tests pass as the bundle is returned.

Project: https://github.com/google/gtm-session-fetcher
Commit attempt to move the 5.3 Resource support: thomasvl/gtm-session-fetcher@f38d107

Raised in https://forums.swift.org/t/5-3-resources-support-not-working-on-with-swift-test/40381

@neonichu
Copy link
Member

@swift-ci create

@BrentMifsud
Copy link

also experiencing a related issue with an all Swift Package: SR-13714

@thomasvl
Copy link
Contributor Author

With 5.5 I'm still getting nil for SWIFTPM_MODULE_BUNDLE

My most recent attempt is on https://github.com/thomasvl/gtm-session-fetcher/tree/swiftpm_updates.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
mokagio added a commit to Automattic/Automattic-Tracks-iOS that referenced this issue Jun 14, 2022
Notice that this introduces an error when running `swift test`:

```
$ swift test

Building for debugging...
/Users/gio/Developer/a8c/tracks-apple-pod/Sources/Model/ObjC/Common/Core Data/TracksContextManager.m:24:24: error: use of undeclared identifier 'SWIFTPM_MODULE_BUNDLE'
    NSBundle *bundle = SWIFTPM_MODULE_BUNDLE;
                       ^
1 error generated.
[0/6] Compiling TracksContextManager.m
error: fatalError
```

This is a known Swift Package Manager issue. See:

- apple/swift-package-manager#4500
- https://forums.swift.org/t/5-3-resources-support-not-working-on-with-swift-test/40381

However, `bundle exec fastlane test`, which uses `xcodebuild` under the
hood, works.

Given our workflow is based on Xcode locally and Fastlane in CI, the
regression seems acceptable.

The reason I'm keen to upgrade to 5.5 is that it's the required tooling
version to integrate Buildkite's Test Analytics. See
https://github.com/buildkite/test-collector-swift/blob/v0.1.0/Package.swift#L1
@mokagio
Copy link

mokagio commented Jun 14, 2022

We run into this issue, too, with 5.5. It can be verified by checking out this commit.

For what is worth, swift tests worked with the 5.3 tools.

@neonichu
Copy link
Member

neonichu commented Jun 15, 2022

Looks like the implementation is

NSBundle* \(target.c99name)_SWIFTPM_MODULE_BUNDLE() {
            NSURL *bundleURL = [[[NSBundle mainBundle] bundleURL] URLByAppendingPathComponent:@"\(bundleBasename)"];
            return [NSBundle bundleWithURL:bundleURL];
        }

IIRC, the main bundle when executing tests is the test runner, so it makes sense that this would return nil. In Xcode's build system, a more comprehensive implementation is generated that is similar to what we do for Swift.

@ncooke3
Copy link
Contributor

ncooke3 commented Nov 22, 2022

@neonichu, I also ran into this while manually testing #5919. I have proposed a fix for this issue in #5921.

tomerd pushed a commit that referenced this issue Nov 29, 2022
…5921)

motivation: I noticed an issue when trying to access a Clang package's resources
  when testing the target from the SwiftPM CLI. In short, the resource
  bundle is placed in the same place when building a Clang-only or
  Swift-only package, but the generated resource_bundle_accessor.m's logic
  tries to create an NSBundle for a path that DNE. The difference becomes
  clear when comparing the logic to the resource_bundle_accessor.swift
  that is generated from Swift-only packages with resources.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants