MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
521 stars 83 forks source link

Bug: iOS extension scheme requires running main application first to reflect code changes #2979

Closed seshness closed 5 months ago

seshness commented 6 months ago

Description

👋 I have an iOS application with a share extension using rules_xcodeproj.

When I make code changes to my application and run the share extension scheme in Xcode to start MobileSafari in a simulator, I don't see my changes reflected.

Reproduction steps

I created a couple of minimal repos to repro what I'm seeing:

Behaviour Project generation method Repository
Expected Vanilla Xcode https://github.com/seshness/SampleSharingApp
Unexpected Bazel + rules_xcodeproj https://github.com/seshness/SampleSharingAppBazel

In the Vanilla Xcode case, I can

  1. Open the Xcode project.
  2. Make a change to ShareViewController.swift, eg. change the alert text.
  3. Run the ShareExtension scheme with Safari in a simulator.
  4. See the updated text when triggering the share action from a share sheet.

In the Bazel + rules_xcodeproj case, I need to

  1. Open the Xcode project (generated with bazel run //:xcodeproj).
  2. Make a change to ShareViewController.swift.
  3. Run the iOSApp scheme for the iOS application. Let the app launch on the Simulator.
  4. Run the ShareExt scheme with Safari in a simulator.
  5. See the updated text when triggering the share action from a share sheet.

Expected behavior

I would like running the extension's scheme only to be sufficient to see code changes to the extension.

rules_xcodeproj version

1.18.0

Xcode version

15.3 (15E204a)

Bazel version

7.1.1

rules_apple version

3.4.0

rules_swift version

1.17.0

Additional information

I tried comparing the two generated schemes:

  1. Vanilla Xcode: SampleSharingApp.xcodeproj/xcshareddata/xcschemes/ShareExtension.xcscheme
  2. Bazel + rules_xcodeproj: SampleSharingAppBazel.xcodeproj/xcshareddata/xcschemes/ShareExt.xcscheme

and noticed Vanilla Xcode sets askForAppToLaunch = "Yes" whereas the Bazel-generated scheme suspiciously does not.

brentleyjones commented 6 months ago

Does changing the scheme to match fix it? I think it wouldn't, since I think it's related to copying outputs. I'm also surprised that https://github.com/MobileNativeFoundation/rules_xcodeproj/commit/d44b4ed4f99e214e352ff8eb36edcb3fee3bd836 didn't fix this. We are probably doing something else wrong, possibly order related, between the host extension and the app.

seshness commented 6 months ago

Changing the scheme to include askForAppToLaunch = "Yes" does not fix it :(

Thanks for the pointer! I'll try poking at the copy outputs phase.

seshness commented 6 months ago

I think I found a significant difference between the vanilla Xcode project & Bazel project. In the vanilla Xcode version there's a 'Target Dependency' in the main application for the extension. In the Bazel-generated project there's a BazelDependencies Target Dependency but no extension.

If I add the extension manually in Xcode and attempt to launch in the simulator, I see an error:

Simulator device failed to install the application. An application bundle was not found at the provided path. Provide a valid path to the desired application bundle.

The path to the bundle uses Debug-iphoneos instead of Debug-iphonesimulator 🤔

I saved the log output to this gist: https://gist.github.com/seshness/c83f895b7c97c572fea5df454bcdd708#file-investigation_02-md

What constructs paths for the Xcode launch action?

brentleyjones commented 5 months ago

After #3005, I got the same error as you related to Debug-iphoneos. I tracked it down to a bug in Xcode when SUPPORTED_PLATFORMS of the extension doesn't include both simulator and device platforms. I'll get a fix for that soon.