Skip to content

Commit

Permalink
Refactor isSwiftFramework(_:) not to use SignalProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Dec 13, 2017
1 parent eb47e90 commit c94d90e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
16 changes: 7 additions & 9 deletions Source/CarthageKit/VersionFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,15 @@ struct VersionFile: Codable {
.flatMap(.concat) { cachedFramework -> SignalProducer<Bool, CarthageError> in
let frameworkURL = self.frameworkURL(for: cachedFramework, platform: platform, binariesDirectoryURL: binariesDirectoryURL)

return isSwiftFramework(frameworkURL)
.flatMap(.concat) { isSwift -> SignalProducer<Bool, SwiftVersionError> in
if !isSwift {
return SignalProducer(value: true)
}

return frameworkSwiftVersion(frameworkURL).map { swiftVersion -> Bool in
if !isSwiftFramework(frameworkURL) {
return SignalProducer(value: true)
} else {
return frameworkSwiftVersion(frameworkURL)
.map { swiftVersion -> Bool in
return swiftVersion == localSwiftVersion
}
}
.flatMapError { _ in SignalProducer<Bool, CarthageError>(value: false) }
.flatMapError { _ in SignalProducer<Bool, CarthageError>(value: false) }
}
}
}

Expand Down
15 changes: 7 additions & 8 deletions Source/CarthageKit/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ internal func frameworkSwiftVersion(_ frameworkURL: URL) -> SignalProducer<Strin
}

/// Determines whether a framework was built with Swift
internal func isSwiftFramework(_ frameworkURL: URL) -> SignalProducer<Bool, SwiftVersionError> {
return SignalProducer(value: frameworkURL.swiftmoduleURL() != nil)
internal func isSwiftFramework(_ frameworkURL: URL) -> Bool {
return frameworkURL.swiftmoduleURL() != nil
}

/// Emits the framework URL if it matches the local Swift version and errors if not.
Expand All @@ -81,12 +81,11 @@ internal func checkSwiftFrameworkCompatibility(_ frameworkURL: URL, usingToolcha

/// Emits the framework URL if it is compatible with the build environment and errors if not.
internal func checkFrameworkCompatibility(_ frameworkURL: URL, usingToolchain toolchain: String?) -> SignalProducer<URL, SwiftVersionError> {
return isSwiftFramework(frameworkURL)
.flatMap(.merge) { isSwift in
return isSwift
? checkSwiftFrameworkCompatibility(frameworkURL, usingToolchain: toolchain)
: SignalProducer(value: frameworkURL)
}
if isSwiftFramework(frameworkURL) {
return checkSwiftFrameworkCompatibility(frameworkURL, usingToolchain: toolchain)
} else {
return SignalProducer(value: frameworkURL)
}
}

/// Creates a task description for executing `xcodebuild` with the given
Expand Down
8 changes: 2 additions & 6 deletions Tests/CarthageKitTests/XcodeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ class XcodeSpec: QuickSpec {

#if !SWIFT_PACKAGE
it("should determine that a Swift framework is a Swift framework") {
let result = isSwiftFramework(testSwiftFrameworkURL).single()

expect(result?.value) == true
expect(isSwiftFramework(testSwiftFrameworkURL)) == true
}
#endif

it("should determine that an ObjC framework is not a Swift framework") {
let frameworkURL = Bundle(for: type(of: self)).url(forResource: "FakeOldObjc.framework", withExtension: nil)!
let result = isSwiftFramework(frameworkURL).single()

expect(result?.value) == false
expect(isSwiftFramework(frameworkURL)) == false
}

it("should determine a value for the local swift version") {
Expand Down

0 comments on commit c94d90e

Please sign in to comment.