Xcode randomly builds dependent framework for wrong platform

Originator:oliver.drobnik
Number:rdar://22008701 Date Originated:27 July 2015
Status:Duplicate/17310873 Resolved:
Product:Xcode Product Version:6.4 (6E35b)
Classification:Serious Bug Reproducible:Always
 
Summary:
Building a project randomly fails if it refers to a module which exists for both iOS and OS X with the same name. Sometimes it would correctly build the iOS version and succeed. Sometimes it would incorrectly try to build the OS X version which fails because the OS X cannot be compiled with iOS headers.

I have tried different variants of "enabling modules", "defines module" and enabling framework auto-linking. As far as I can tell, the problem goes away if I disable "defines module" for the OS X framework, but that cannot be the solution.

As a developer I would expect for xcodebuild to always build the same dependent targets and not make non-deterministic/incorrect choices.

Steps to Reproduce:
1. Clone the DTRichTextEditor project from github

git clone --recursive https://github.com/Cocoanetics/DTRichTextEditor.git 

2. Change into the cloned folder

cd DTRichTextEditor

3. Build the demo app:

xcodebuild -project DTRichTextEditor.xcodeproj -scheme "Demo App" build -sdk iphonesimulator -arch x86_64 | grep "^=\|^*"

4. Repeat step 3 a couple of times

Expected Results:
- The build should always show ** BUILD SUCCEEDED **
- It should do that every time
- The output of step 3 should be:

=== BUILD TARGET Resource Bundle OF PROJECT DTLoupe WITH CONFIGURATION Debug ===
=== BUILD TARGET Static Library OF PROJECT DTLoupe WITH CONFIGURATION Debug ===
=== BUILD TARGET DTFoundation (iOS) OF PROJECT DTFoundation WITH CONFIGURATION Debug ===
=== BUILD TARGET Static Library OF PROJECT DTWebArchive WITH CONFIGURATION Debug ===
=== BUILD TARGET DTCoreText (iOS) OF PROJECT DTCoreText WITH CONFIGURATION Debug ===
=== BUILD TARGET DTRichTextEditor (iOS) OF PROJECT DTRichTextEditor WITH CONFIGURATION Debug ===
=== BUILD TARGET Demo App OF PROJECT DTRichTextEditor WITH CONFIGURATION Debug ===
** BUILD SUCCEEDED **

Actual Results:
- Some builds succeed, some builds fail
- when the build fails you can see in the output that "DTFoundation (OS X)" is included there
- when a build fails the output of step 3 is:

=== BUILD TARGET Resource Bundle OF PROJECT DTLoupe WITH CONFIGURATION Debug ===
=== BUILD TARGET Static Library OF PROJECT DTLoupe WITH CONFIGURATION Debug ===
=== BUILD TARGET DTFoundation (OSX) OF PROJECT DTFoundation WITH CONFIGURATION Debug ===
=== BUILD TARGET DTFoundation (iOS) OF PROJECT DTFoundation WITH CONFIGURATION Debug ===
=== BUILD TARGET Static Library OF PROJECT DTWebArchive WITH CONFIGURATION Debug ===
=== BUILD TARGET DTCoreText (iOS) OF PROJECT DTCoreText WITH CONFIGURATION Debug ===
** BUILD FAILED **

Version:
Xcode 6.4 (6E35b), OS X 10.10.5 (14F6a)

Notes:
Here's a Travis-CI build that worked, with an easier to read xctool log: https://travis-ci.org/Cocoanetics/DTRichTextEditor/builds/72820037

And here's a Travis-CI that didn't just before. See line 683 where it fails to build a category on NSDocument which of course couldn't be built for iOS:
https://travis-ci.org/Cocoanetics/DTRichTextEditor/builds/72819401

Comments

I found - after filing this - that I didn't have one dependency implicit. Use the following line before step 3 to get to a state of the repository where the dependency is still implicit:

git checkout e7a8ed5e9524df1ce732fe7568cd490486505369

After I added the explicit dependency building also seems to be generally work. So the workaround is to disable implicit dependencies (and fixing all build errors that result from that). Once you have all dependencies explicit you can re-enable implicit dependencies as those don't seem to be doing anything, at least for frameworks.

By oliver.drobnik at July 27, 2015, 2:33 p.m. (reply...)

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!