Testing scheme builds wrong app target when two targets have same product name

Originator:jalkut
Number:rdar://19924983 Date Originated:23-Feb-2015 02:50 PM
Status:Open Resolved:
Product:Developer Tools Product Version:6.2
Classification:Serious Bug Reproducible:Always
 
Summary:
This peculiar bug affects Xcode's determination of the implied target that needs to be built to satisfy a unit testing target that has specified a "Test Host".

The situation that leads to the confusion is when two application targets exist in the same project, and each target produces an application with the same product name. This may sound far-fetched, but it's ordinary for projects where for example a different target is used for building an app for the Mac App Store and for direct sale/distribution.

The gist of the problem is Xcode fails to reliably list as the dependency for the test build the correct version of the app, leading to at best duplicated dependency builds at test time, and at worst weird conflicts that seem to crop up from having both of the targets build at the same time.

The attached project demonstrates the problem. Please bear with me and step through the large number of steps ... it's not as complicated as it appears, I'm just trying to be very explicit about how to observe the bug.

1. Open attached Test App.xcodeproj
2. Open the Scheme Editor and confirm that the App 2 Tests scheme’s "Build" section contains two hard-coded targets: App 2 and App 2 Tests.
3. Select the App 2 Tests *target* and click the General tab.
4. Change the "Host Application" setting from App 2 to App 1.
5. Click the "Build Phases" tab.
6. Change theTarget Dependencies to remove App 2 from the list of dependencies.
7. Open the Scheme Editor and observe that the App 2 Tests scheme’s "Build" section still erroneously shows "App 2" as a dependency build.
8. Quit and relaunch Xcode, opening the same project.
9. Open the Scheme Editor and observe the dependencies now shows "App 1" as the sole app dependency.
10. Now repeat the process with steps 3-6, this time switching the host app for App 2 Tests to BACK to "App 2", and removing App 1 from the list of explicit dependencies.
11. Open the Scheme Editor and observe that, again, the wrong dependent target is listed, now showing App 1 when it should have changed to App 2.
12. Quit and relaunch again.

Expected result: quitting and relaunching should have cleared out the dust, or whatever, and gotten the scheme into line, but it doesn’t.

Workaround: It sometimes seems that quitting Xcode and then deleting any xcuserdata in the project before reopening Xcode causes it to refigure the dependent target correctly, and it sticks:

find . -name xcuserdata -exec rm -rf {} \;

HOWEVER: if you delete the xcuserdata again, it perplexingly toggles BACK to favoring the other target, and seems to toggle in this way each time you delete the xcuserdata. Furthermore, I don’t always see this work as expected so maybe there’s a component of randomness.

Steps to Reproduce:


Expected Results:


Actual Results:


Version:
Version 6.3 (6D520o)

Notes:


Configuration:


Attachments:
'TestAppSchemes.zip' was successfully uploaded.

[Direct download link for the sample I submitted to Apple:]

http://indiestack.com/wp-content/uploads/2015/02/TestAppSchemes.zip

Comments

Sadly this bug still affects iOS 8.2.1

Additional testing confirms it will match partial file names too. For instance if I have MyApp.app and Flavour1MyApp.app then the tests for Flavour1 gain a dependency on MyApp.app.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!