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

'carthage build' failed to copy frameworks for macOS. #1513

Closed
aalenliang opened this issue Oct 4, 2016 · 4 comments
Closed

'carthage build' failed to copy frameworks for macOS. #1513

aalenliang opened this issue Oct 4, 2016 · 4 comments
Labels

Comments

@aalenliang
Copy link

  • carthage version: 0.18
  • xcodebuild -version: Xcode 8.0, Build version 8A218a
  • Are you using --no-build? No
  • Are you using --no-use-binaries? No
  • Are you using --use-submodules? No

Cartfile

github "madebybowtie/FlagKit" "swift3"

Carthage Output

*** xcodebuild output can be found in /var/folders/nt/lsvh10qs52s65kdw5bn126m40000gn/T/carthage-xcodebuild.1vB5wa.log
*** Building scheme "FlagKit" in FlagKit.xcodeproj
Failed to write to /Users/liangalen/Documents/Projects/SeedLab/AccessControlExample/Carthage/Build/Mac/FlagKit.framework: Error Domain=NSCocoaErrorDomain Code=260 "The file “FlagKit.framework” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/liangalen/Library/Developer/Xcode/DerivedData/FlagKit-fwwepxalaneinngomftamewytxrp/Build/Products/Release-iphoneos/FlagKit.framework, NSUnderlyingError=0x7faabc14fd00 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Issue Description
The framework I used (FlagKit) has only one target with Base SDK: iOS 10.0, supported platforms: macosx iphonesimulator iphoneos appletvsimulator appletvos:
screen shot 2016-10-05 at 1 30 22 am

Carthage always tries to copy the framework in base sdk folder (Release-iphoneos) to /Build/Mac. Hence it failed to build because:

Failed to write to .../Carthage/Build/Mac/FlagKit.framework: Error Domain=NSCocoaErrorDomain Code=260 "
The file “FlagKit.framework” couldn’t be opened because there is no such file."UserInfo={NSFilePath=
.../Xcode/DerivedData/FlagKit-fwwepxalaneinngomftamewytxrp/Build/Products/Release-iphoneos/FlagKit.framework, NSUnderlyingError=0x7faabc14fd00 
{Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

I tried to set the baseSDK to tvOS 10.0 for FlagKit project in /Checkout/FlagKit folder, and run 'carthage build', the output turns out to be

Failed to write to .../Carthage/Build/Mac/FlagKit.framework: Error Domain=NSCocoaErrorDomain Code=260 "
The file “FlagKit.framework” couldn’t be opened because there is no such file."UserInfo={NSFilePath=
.../Xcode/DerivedData/FlagKit-fwwepxalaneinngomftamewytxrp/Build/Products/Release-appletvos/FlagKit.framework, NSUnderlyingError=0x7faabc14fd00 
{Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Though I can using 'carthage build --platform iOS' to force build a framework file in the base sdk folder, after 'carthage build' successful, I drag the framework in '/Build/Mac' to my project, it won't build due to the error:

UIKit is not found.

Because the framework carthage copy to '/Build/Mac' is still under '/DerivedData/FlagKit-x/Build/Products/Release-iphoneos/FlagKit.framework'.

Reason
After clone the carthage project, I find #922 causing this issue.
in Xcode.swift:

if let sdk = sdk {
    // Passing in -sdk macosx appears to break implicit dependency
    // resolution (see Carthage/Carthage#347).
    //
    // Since we wouldn't be trying to build this target unless it were
    // for OS X already, just let xcodebuild figure out the SDK on its
    // own.
    if sdk != .MacOSX {
        args += [ "-sdk", sdk.rawValue ]
    }
}

I think it means, when platform is macOS, don't pass '-sdk' arguments, build with projects base sdk, which doesn't works when the project's base sdk isn't macOS.

Solution
I think the codes really should be just like:

if let sdk = sdk {
    args += [ "-sdk", sdk.rawValue ]
}
@ikesyo
Copy link
Member

ikesyo commented Oct 4, 2016

This should not be a Carthage's issue. Looks like the project is not correctly setup as a universal framework target. Just setting SUPPORTED_PLATFORMS is not sufficient and you should set up VALID_ARCHS (Valid Architectures) and TARGETED_DEVICE_FAMILY as well. Please check something like https://github.com/mrackwitz/xcconfigs for correct universal framework settings. Closing.

@ikesyo ikesyo closed this as completed Oct 4, 2016
@aalenliang
Copy link
Author

I tried to use the xcconfigs files in this project (https://github.com/SeedLabIO/FlagKit/commits/swift3)
Removed the Carthage/ folder and tried carthage update.

It builds successfully, however, after I drag the framework under /Build/Mac to my project, still build failed due to:

.../Carthage/Build/Mac/FlagKit.framework/Headers/FlagKit-Swift.h:113:9: Module 'UIKit' not found

I thought the copy framework still did something wrong, so I add some log in Xcode.swift

public func copyFileURLsIntoDirectory(directoryURL: NSURL) -> SignalProducer<NSURL, CarthageError> {
    return producer
        .filter { fileURL in fileURL.checkResourceIsReachableAndReturnError(nil) }
        .flatMap(.Merge) { fileURL -> SignalProducer<NSURL, CarthageError> in
            let fileName = fileURL.lastPathComponent!
            let destinationURL = directoryURL.appendingPathComponent(fileName, isDirectory: false)
            let resolvedDestinationURL = destinationURL.URLByResolvingSymlinksInPath!

            print("* fileURL: " + fileURL.absoluteString!)
            print("* resolvedDestinationURL: " + resolvedDestinationURL.absoluteString!)
            return copyProduct(fileURL, resolvedDestinationURL)
        }
}

And run carthage update it logged:

* fileURL: file:///Users/liangalen/Library/Developer/Xcode/DerivedData/
FlagKit-fwwepxalaneinngomftamewytxrp/Build/Products/Release-iphoneos/
A4D3FD88-007B-3160-B07F-2A1569B43300.bcsymbolmap
* resolvedDestinationURL: file:///Users/liangalen/Documents/Projects/SeedLab/
AccessControlExample/Carthage/Build/Mac/A4D3FD88-007B-3160-B07F-2A1569B43300.bcsymbolmap

I think carthage still copy the framework build from /Release-iphonos (the base sdk is iOS 10.0) to Build/Mac, which still an issue.

@ikesyo
Copy link
Member

ikesyo commented Oct 11, 2016

Hmm, so looks like currently SDKROOT should be macosx for a universal framework target. But passing in -sdk flag when building with macOS SDK should be avoided as written in the comment:

// Passing in -sdk macosx appears to break implicit dependency
// resolution (see Carthage/Carthage#347).
//
// Since we wouldn't be trying to build this target unless it were
// for OS X already, just let xcodebuild figure out the SDK on its
// own.

So the following is not the solution:

if let sdk = sdk {
    args += [ "-sdk", sdk.rawValue ]
}

Overriding SDKROOT build setting instead of passing in -sdk flag might be a solution on Carthage side.

@aalenliang
Copy link
Author

Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants