-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Skip building static frameworks by checking Mach-O type #894
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,6 +468,52 @@ public enum ProductType: String { | |
} | ||
} | ||
|
||
/// Describes the type of Mach-O files. | ||
/// See https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW73. | ||
public enum MachOType: String { | ||
/// Executable binary. | ||
case Executable = "mh_executable" | ||
|
||
/// Bundle binary. | ||
case Bundle = "mh_bundle" | ||
|
||
/// Relocatable object file. | ||
case Object = "mh_object" | ||
|
||
/// Dynamic library binary. | ||
case Dylib = "mh_dylib" | ||
|
||
/// Static library binary. | ||
case Staticlib = "staticlib" | ||
|
||
/// Attempts to parse a Mach-O type from a string returned from `xcodebuild`. | ||
public static func fromString(string: String) -> Result<MachOType, CarthageError> { | ||
return Result(self.init(rawValue: string), failWith: .ParseError(description: "unexpected Mach-O type \"\(string)\"")) | ||
} | ||
} | ||
|
||
/// Describes the type of frameworks. | ||
private enum FrameworkType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced this should be private or public. |
||
/// A dynamic framework. | ||
case Dynamic | ||
|
||
/// A static framework. | ||
case Static | ||
|
||
init?(productType: ProductType, machOType: MachOType) { | ||
switch (productType, machOType) { | ||
case (.Framework, .Dylib): | ||
self = .Dynamic | ||
|
||
case (.Framework, .Staticlib): | ||
self = .Static | ||
|
||
case _: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
/// A map of build settings and their values, as generated by Xcode. | ||
public struct BuildSettings { | ||
/// The target to which these settings apply. | ||
|
@@ -586,6 +632,16 @@ public struct BuildSettings { | |
} | ||
} | ||
|
||
/// Attempts to determine the MachOType specified in these build settings. | ||
public var machOType: Result<MachOType, CarthageError> { | ||
return self["MACH_O_TYPE"].flatMap(MachOType.fromString) | ||
} | ||
|
||
/// Attempts to determine the FrameworkType identified by these build settings. | ||
private var frameworkType: Result<FrameworkType?, CarthageError> { | ||
return (productType &&& machOType).map(FrameworkType.init) | ||
} | ||
|
||
/// Attempts to determine the URL to the built products directory. | ||
public var builtProductsDirectoryURL: Result<NSURL, CarthageError> { | ||
return self["BUILT_PRODUCTS_DIR"].map { productsDir in | ||
|
@@ -728,31 +784,31 @@ private func mergeModuleIntoModule(sourceModuleDirectoryURL: NSURL, _ destinatio | |
} | ||
} | ||
|
||
/// Determines whether the specified product type should be built automatically. | ||
private func shouldBuildProductType(productType: ProductType) -> Bool { | ||
return productType == .Framework | ||
/// Determines whether the specified framework type should be built automatically. | ||
private func shouldBuildFrameworkType(frameworkType: FrameworkType?) -> Bool { | ||
return frameworkType == .Dynamic | ||
} | ||
|
||
/// Determines whether the given scheme should be built automatically. | ||
private func shouldBuildScheme(buildArguments: BuildArguments, _ forPlatforms: Set<Platform>) -> SignalProducer<Bool, CarthageError> { | ||
precondition(buildArguments.scheme != nil) | ||
|
||
return BuildSettings.loadWithArguments(buildArguments) | ||
.flatMap(.Concat) { settings -> SignalProducer<ProductType, CarthageError> in | ||
let productType = SignalProducer(result: settings.productType) | ||
.flatMap(.Concat) { settings -> SignalProducer<FrameworkType?, CarthageError> in | ||
let frameworkType = SignalProducer(result: settings.frameworkType) | ||
|
||
if forPlatforms.isEmpty { | ||
return productType | ||
return frameworkType | ||
.flatMapError { _ in .empty } | ||
} else { | ||
return settings.buildSDKs | ||
.filter { forPlatforms.contains($0.platform) } | ||
.flatMap(.Merge) { _ in productType } | ||
.flatMap(.Merge) { _ in frameworkType } | ||
.flatMapError { _ in .empty } | ||
} | ||
} | ||
.filter(shouldBuildProductType) | ||
// If we find any framework target, we should indeed build this scheme. | ||
.filter(shouldBuildFrameworkType) | ||
// If we find any dynamic framework target, we should indeed build this scheme. | ||
.map { _ in true } | ||
// Otherwise, nope. | ||
.concat(SignalProducer(value: false)) | ||
|
@@ -908,9 +964,9 @@ public func buildScheme(scheme: String, withConfiguration configuration: String, | |
|
||
return BuildSettings.loadWithArguments(argsForLoading) | ||
.filter { settings in | ||
// Only copy build products for the product types we care about. | ||
if let productType = settings.productType.value { | ||
return shouldBuildProductType(productType) | ||
// Only copy build products for the framework type we care about. | ||
if let frameworkType = settings.frameworkType.value { | ||
return shouldBuildFrameworkType(frameworkType) | ||
} else { | ||
return false | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$5 says this link won't work in a year. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, you should leave it in. I was just joking because it's frustrating how Apple breaks these links all the time.☺️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, forgive my misunderstanding. 😝