xcodebuild nondeterministically selects implicit dependencies for the wrong platform

Originator:rix.rob
Number:rdar://20490378 Date Originated:09-Apr-2015 06:35 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.3 (6D570)
Classification:Serious Bug Reproducible:Always
 
Summary:
Given a workspace building a framework for iOS & Mac, with two dependency frameworks (also both for iOS & Mac), xcodebuild nondeterministically selects the wrong target (i.e. iOS for Mac, or Mac for iOS) for one or both dependencies. It still seems to build for the Mac (although how is unclear), but it fails when building for iOS, because code signing isn’t enabled in the Mac targets.

Possibly relevant details:
- all 3 frameworks are built by targets whose names have the platform name as a suffix, e.g. Either-iOS, Either-Mac.
- all 3 frameworks use the same product name for Mac & iOS, e.g. Prelude.framework.
- all 6 schemes have “find implicit dependencies” enabled.


Steps to Reproduce:
1. Clone https://github.com/robrix/Either & its dependencies

    git clone --recursive https://github.com/robrix/Either.git

2. cd into the repo.

3. Build the Mac scheme a few times, paying attention to which targets it builds:

    xcodebuild -configuration Release -sdk (xcrun --show-sdk-path --sdk macosx) -workspace Either.xcworkspace/ -scheme Either-Mac

4. Build the iOS scheme a few times, paying attention to which targets it builds:

    xcodebuild -configuration Release -sdk (xcrun --show-sdk-path --sdk iphoneos) -workspace Either.xcworkspace/ -scheme Either-iOS


Expected Results:
I expected it to build the targets for the platform I specified, and no other platform. I expected all builds to succeed.


Actual Results:
It builds the target for the specified platform for the root framework, but arbitrarily selects between iOS and Mac for the dependency targets. On iOS builds, this means that 3/4 builds fail.


Regression:
N/A


Notes:
Sample output follows;

Mac:

Build settings from command line:
    SDKROOT = macosx10.10

=== BUILD TARGET Prelude-iOS OF PROJECT Prelude WITH CONFIGURATION Release ===

Check dependencies

=== BUILD TARGET Box-iOS OF PROJECT Box WITH CONFIGURATION Release ===

Check dependencies

=== BUILD TARGET Either-Mac OF PROJECT Either WITH CONFIGURATION Release ===

Check dependencies

** BUILD SUCCEEDED **


iOS:

Build settings from command line:
    SDKROOT = iphoneos8.3

=== BUILD TARGET Box-Mac OF PROJECT Box WITH CONFIGURATION Release ===

Check dependencies
CodeSign error: code signing is required for product type 'Framework' in SDK 'iOS 8.3'

=== BUILD TARGET Prelude-Mac OF PROJECT Prelude WITH CONFIGURATION Release ===
Check dependencies
CodeSign error: code signing is required for product type 'Framework' in SDK 'iOS 8.3'

** BUILD FAILED **


The following build commands failed:
	Check dependencies
	Check dependencies
(2 failures)



This is a serious blocker for Carthage (cf https://github.com/Carthage/Carthage/issues/418 ). It’s possible that renaming the products per-platform would work around this issue, but migrating a _very_ large number of targets & every project using them is intractable. Other workarounds would be greatly appreciated, however :)

Thank you!

Comments

I filed this Radar for it: http://www.cocoanetics.com/2015/07/radar-xcode-framework-for-wrong-platform/ - http://www.openradar.me/22008701

I found that Implicit Dependencies would only mess up if I didn't have all dependencies explicitly configured. I I made sure that all dependencies where explicit, the problem would go away.

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

I filed this same bug in November. Here's what I got back

"This is because Xcode is trying to find the implicit dependency that iOSFramework depends on by name, and there are two targets with products of the same name, so it winds up picking one at random. You can resolve this ambiguity by making an explicit dependency on the correct one in the "Target Dependencies" build phase.

We are continuing to work on this issue and will follow up again."

I discovered later that you also have to disable implicit dependancies in the scheme to stop this from happening.


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!