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

Swift 5.2 migration #2972

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -12,13 +12,13 @@ matrix:
include:
- os: osx
language: objective-c
osx_image: xcode10.1
osx_image: xcode11.4
script:
- make test
env: JOB=CI_TEST_10_1
env: JOB=CI_TEST_11_4
- os: osx
language: objective-c
osx_image: xcode10.1
osx_image: xcode11.4
script:
- brew uninstall carthage
- HOMEBREW_NO_AUTO_UPDATE=1 brew install bats
Expand Down
35 changes: 13 additions & 22 deletions Package.resolved
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"state": {
"branch": null,
"revision": "2cd0210f897fe46c6ce42f52ccfa72b3bbb621a0",
"version": "0.16.0"
"revision": "ab68611013dec67413628ac87c1f29e8427bc8e4",
"version": "0.17.0"
}
},
{
Expand All @@ -24,8 +24,8 @@
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "f8657642dfdec9973efc79cc68bcef43a653a2bc",
"version": "8.0.2"
"revision": "7fd118ec8795888bcbbebc1a41f6984454c4cd6f",
"version": "8.0.7"
}
},
{
Expand All @@ -42,44 +42,35 @@
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37",
"version": "2.1.0"
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
"version": "2.2.0"
}
},
{
"package": "ReactiveSwift",
"repositoryURL": "https://github.com/ReactiveCocoa/ReactiveSwift.git",
"state": {
"branch": null,
"revision": "c37950dc5020544c58d4bf47c0d028893686b9e6",
"version": "5.0.1"
"revision": "e27ccdbf4ec36f154b60b91a0d7e0110c4e882cb",
"version": "6.2.1"
}
},
{
"package": "ReactiveTask",
"repositoryURL": "https://github.com/Carthage/ReactiveTask.git",
"state": {
"branch": null,
"revision": "df1bf7625684180b9377a8ba3c076db08d98757e",
"version": "0.16.0"
}
},
{
"package": "Result",
"repositoryURL": "https://github.com/antitypical/Result.git",
"state": {
"branch": null,
"revision": "2ca499ba456795616fbc471561ff1d963e6ae160",
"version": "4.1.0"
"branch": "master",
"revision": "e1396a56055812234e97aeda78731d7228e0bbc7",
"version": null
}
},
{
"package": "Tentacle",
"repositoryURL": "https://github.com/mdiep/Tentacle.git",
"state": {
"branch": null,
"revision": "578edd088b03bc749c49253b15ae2d5aaa9aa7df",
"version": "0.13.1"
"revision": "fb9f20c3cc094103799e271dd664e1ee1b76211e",
"version": "0.14.0"
}
}
]
Expand Down
14 changes: 7 additions & 7 deletions Package.swift
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.2
import PackageDescription

let package = Package(
Expand All @@ -9,20 +9,20 @@ let package = Package(
.executable(name: "carthage", targets: ["carthage"]),
],
dependencies: [
.package(url: "https://github.com/antitypical/Result.git", from: "4.1.0"),
.package(url: "https://github.com/Carthage/ReactiveTask.git", from: "0.16.0"),
// .package(url: "https://github.com/Carthage/ReactiveTask.git", from: "0.16.0"),
.package(url: "https://github.com/Carthage/ReactiveTask.git", .branch("master")),
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
.package(url: "https://github.com/jdhealy/PrettyColors.git", from: "5.0.2"),
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", from: "5.0.0"),
.package(url: "https://github.com/mdiep/Tentacle.git", from: "0.13.1"),
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", from: "6.2.0"),
.package(url: "https://github.com/mdiep/Tentacle.git", from: "0.14.0"),
.package(url: "https://github.com/thoughtbot/Curry.git", from: "4.0.2"),
.package(url: "https://github.com/Quick/Quick.git", from: "2.1.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "8.0.1"),
],
targets: [
.target(
name: "XCDBLD",
dependencies: ["Result", "ReactiveSwift", "ReactiveTask"]
dependencies: ["ReactiveSwift", "ReactiveTask"]
),
.testTarget(
name: "XCDBLDTests",
Expand All @@ -43,5 +43,5 @@ let package = Package(
exclude: ["swift-is-crashy.c"]
),
],
swiftLanguageVersions: [.v4_2]
swiftLanguageVersions: [.version("5.2")]
)
1 change: 0 additions & 1 deletion Source/CarthageKit/Archive.swift
@@ -1,5 +1,4 @@
import Foundation
import Result
import ReactiveSwift
import ReactiveTask

Expand Down
1 change: 0 additions & 1 deletion Source/CarthageKit/Availability.swift
@@ -1,6 +1,5 @@
import Foundation
import ReactiveSwift
import Result
import XCDBLD

// swiftlint:disable missing_docs fatal_error_message
5 changes: 2 additions & 3 deletions Source/CarthageKit/BinaryProject.swift
@@ -1,5 +1,4 @@
import Foundation
import Result

/// Represents a binary dependency
public struct BinaryProject: Equatable {
Expand All @@ -8,8 +7,8 @@ public struct BinaryProject: Equatable {
public var versions: [PinnedVersion: URL]

public static func from(jsonData: Data) -> Result<BinaryProject, BinaryJSONError> {
return Result<[String: String], AnyError>(attempt: { try jsonDecoder.decode([String: String].self, from: jsonData) })
.mapError { .invalidJSON($0.error) }
return Result<[String: String], Error> { try jsonDecoder.decode([String: String].self, from: jsonData) }
.mapError { .invalidJSON($0) }
.flatMap { json -> Result<BinaryProject, BinaryJSONError> in
var versions = [PinnedVersion: URL]()

Expand Down
1 change: 0 additions & 1 deletion Source/CarthageKit/BuildSettings.swift
@@ -1,5 +1,4 @@
import Foundation
import Result
import ReactiveSwift
import XCDBLD

Expand Down
3 changes: 1 addition & 2 deletions Source/CarthageKit/Cartfile.swift
@@ -1,5 +1,4 @@
import Foundation
import Result

/// Represents a Cartfile, which is a specification of a project's dependencies
/// and any other settings Carthage needs to build it.
Expand Down Expand Up @@ -94,7 +93,7 @@ public struct Cartfile {
/// Attempts to parse a Cartfile from a file at a given URL.
public static func from(file cartfileURL: URL) -> Result<Cartfile, CarthageError> {
return Result(catching: { try String(contentsOf: cartfileURL, encoding: .utf8) })
.mapError { .readFailed(cartfileURL, $0) }
.mapError { .readFailed(cartfileURL, $0 as NSError) }
.flatMap(Cartfile.from(string:))
.mapError { error in
guard case let .duplicateDependencies(dupes) = error else { return error }
Expand Down
5 changes: 2 additions & 3 deletions Source/CarthageKit/CompatibilityInfo.swift
@@ -1,5 +1,4 @@
import Foundation
import Result

/// Identifies a dependency, its pinned version, and its compatible and incompatible requirements
public struct CompatibilityInfo: Equatable {
Expand Down Expand Up @@ -40,14 +39,14 @@ public struct CompatibilityInfo: Equatable {
var requirements = invertedRequirements[requiredDependency] ?? [:]

if requirements[dependency] != nil {
return .init(error: .duplicateDependencies([DuplicateDependency(dependency: dependency, locations: [])]))
return .failure(.duplicateDependencies([DuplicateDependency(dependency: dependency, locations: [])]))
}

requirements[dependency] = requiredVersion
invertedRequirements[requiredDependency] = requirements
}
}
return .init(invertedRequirements)
return .success(invertedRequirements)
}

/// Constructs CompatibilityInfo objects for dependencies with incompatibilities
Expand Down
7 changes: 3 additions & 4 deletions Source/CarthageKit/Constants.swift
@@ -1,5 +1,4 @@
import Foundation
import Result

/// A struct including all constants.
public struct Constants {
Expand Down Expand Up @@ -31,18 +30,18 @@ public struct Constants {
private static let userCachesURL: URL = {
let fileManager = FileManager.default

let urlResult: Result<URL, NSError> = Result(catching: {
let urlResult: Result<URL, Error> = Result(catching: {
try fileManager.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
}).flatMap { cachesURL in
let dependenciesURL = cachesURL.appendingPathComponent(Constants.bundleIdentifier, isDirectory: true)
let dependenciesPath = dependenciesURL.absoluteString

if fileManager.fileExists(atPath: dependenciesPath, isDirectory: nil) {
if fileManager.isWritableFile(atPath: dependenciesPath) {
return Result(value: dependenciesURL)
return .success(dependenciesURL)
} else {
let error = NSError(domain: Constants.bundleIdentifier, code: 0, userInfo: nil)
return Result(error: error)
return .failure(error)
}
} else {
return Result(catching: {
Expand Down
4 changes: 2 additions & 2 deletions Source/CarthageKit/Dependency.swift
@@ -1,5 +1,4 @@
import Foundation
import Result
import Tentacle

/// Uniquely identifies a Binary Spec's resolved URL and its description
Expand Down Expand Up @@ -72,7 +71,8 @@ extension Dependency {
let ownerAndNameSubstring = String(urlString[urlString.index(urlString.startIndex, offsetBy: startOfOwnerAndNameSubstring)..<urlString.endIndex])

switch Repository.fromIdentifier(ownerAndNameSubstring as String) {
case .success(let server, let repository):
case .success(let success):
let (server, repository) = success
self = Dependency.gitHub(server, repository)

default:
Expand Down
9 changes: 4 additions & 5 deletions Source/CarthageKit/FrameworkExtensions.swift
@@ -1,11 +1,10 @@
import Foundation
import Result
import ReactiveSwift

extension String {
/// Returns a producer that will enumerate each line of the receiver, then
/// complete.
internal var linesProducer: SignalProducer<String, NoError> {
internal var linesProducer: SignalProducer<String, Never> {
return SignalProducer { observer, lifetime in
self.enumerateLines { line, stop in
observer.send(value: line)
Expand Down Expand Up @@ -124,7 +123,7 @@ extension SignalProducer {
}

/// Sends a boolean of whether the producer succeeded or failed.
internal func succeeded() -> SignalProducer<Bool, NoError> {
internal func succeeded() -> SignalProducer<Bool, Never> {
return self
.then(SignalProducer<Bool, Error>(value: true))
.flatMapError { _ in .init(value: false) }
Expand Down Expand Up @@ -447,14 +446,14 @@ extension Reactive where Base: URLSession {
/// - note: This method will not send an error event in the case of a server
/// side error (i.e. when a response with status code other than
/// 200...299 is received).
internal func download(with request: URLRequest) -> SignalProducer<(URL, URLResponse), AnyError> {
internal func download(with request: URLRequest) -> SignalProducer<(URL, URLResponse), Error> {
return SignalProducer { [base = self.base] observer, lifetime in
let task = base.downloadTask(with: request) { url, response, error in
if let url = url, let response = response {
observer.send(value: (url, response))
observer.sendCompleted()
} else {
observer.send(error: AnyError(error ?? defaultSessionError))
observer.send(error: error.map { $0 as NSError } ?? defaultSessionError)
}
}

Expand Down
19 changes: 9 additions & 10 deletions Source/CarthageKit/Git.swift
@@ -1,5 +1,4 @@
import Foundation
import Result
import ReactiveSwift
import ReactiveTask

Expand Down Expand Up @@ -55,7 +54,7 @@ public struct FetchCache {
public func launchGitTask(
_ arguments: [String],
repositoryFileURL: URL? = nil,
standardInput: SignalProducer<Data, NoError>? = nil,
standardInput: SignalProducer<Data, Never>? = nil,
environment: [String: String]? = nil
) -> SignalProducer<String, CarthageError> {
// See https://github.com/Carthage/Carthage/issues/219.
Expand Down Expand Up @@ -181,7 +180,7 @@ public func checkoutRepositoryToDirectory(
CarthageError.repositoryCheckoutFailed(
workingDirectoryURL: workingDirectoryURL,
reason: "Could not create working directory",
underlyingError: $0
underlyingError: $0 as NSError
)
}
}
Expand Down Expand Up @@ -270,7 +269,7 @@ private func checkoutSubmodule(_ submodule: Submodule, _ submoduleWorkingDirecto

/// Parses each key/value entry from the given config file contents, optionally
/// stripping a known prefix/suffix off of each key.
private func parseConfigEntries(_ contents: String, keyPrefix: String = "", keySuffix: String = "") -> SignalProducer<(String, String), NoError> {
private func parseConfigEntries(_ contents: String, keyPrefix: String = "", keySuffix: String = "") -> SignalProducer<(String, String), Never> {
let entries = contents.split(omittingEmptySubsequences: true) { $0 == "\0" }

return SignalProducer { observer, lifetime in
Expand Down Expand Up @@ -367,7 +366,7 @@ internal func gitmodulesEntriesInRepository(
}

return launchGitTask(baseArguments + [ "--get-regexp", "submodule\\..*\\.path" ], repositoryFileURL: repositoryFileURL)
.flatMapError { _ in SignalProducer<String, NoError>.empty }
.flatMapError { _ in SignalProducer<String, Never>.empty }
.flatMap(.concat) { value in parseConfigEntries(value, keyPrefix: "submodule.", keySuffix: ".path") }
.flatMap(.concat) { name, path -> SignalProducer<(name: String, path: String, url: GitURL), CarthageError> in
return launchGitTask(baseArguments + [ "--get", "submodule.\(name).url" ], repositoryFileURL: repositoryFileURL)
Expand Down Expand Up @@ -425,10 +424,10 @@ public func submodulesInRepository(_ repositoryFileURL: URL, revision: String =
///
/// If the specified file URL does not represent a valid Git repository, `false`
/// will be sent.
internal func branchExistsInRepository(_ repositoryFileURL: URL, pattern: String) -> SignalProducer<Bool, NoError> {
internal func branchExistsInRepository(_ repositoryFileURL: URL, pattern: String) -> SignalProducer<Bool, Never> {
return ensureDirectoryExistsAtURL(repositoryFileURL)
.succeeded()
.flatMap(.concat) { exists -> SignalProducer<Bool, NoError> in
.flatMap(.concat) { exists -> SignalProducer<Bool, Never> in
if !exists { return .init(value: false) }
return SignalProducer.zip(
launchGitTask([ "show-ref", pattern ], repositoryFileURL: repositoryFileURL).succeeded(),
Expand All @@ -444,10 +443,10 @@ internal func branchExistsInRepository(_ repositoryFileURL: URL, pattern: String
///
/// If the specified file URL does not represent a valid Git repository, `false`
/// will be sent.
public func commitExistsInRepository(_ repositoryFileURL: URL, revision: String = "HEAD") -> SignalProducer<Bool, NoError> {
public func commitExistsInRepository(_ repositoryFileURL: URL, revision: String = "HEAD") -> SignalProducer<Bool, Never> {
return ensureDirectoryExistsAtURL(repositoryFileURL)
.then(launchGitTask([ "rev-parse", "\(revision)^{commit}" ], repositoryFileURL: repositoryFileURL))
.then(SignalProducer<Bool, NoError>(value: true))
.then(SignalProducer<Bool, Never>(value: true))
.flatMapError { _ in .init(value: false) }
}

Expand Down Expand Up @@ -493,7 +492,7 @@ internal func resolveTagInRepository(_ repositoryFileURL: URL, _ tag: String) ->

/// Attempts to determine whether the given directory represents a Git
/// repository.
public func isGitRepository(_ directoryURL: URL) -> SignalProducer<Bool, NoError> {
public func isGitRepository(_ directoryURL: URL) -> SignalProducer<Bool, Never> {
return ensureDirectoryExistsAtURL(directoryURL)
.then(launchGitTask([ "rev-parse", "--git-dir" ], repositoryFileURL: directoryURL))
.map { outputIncludingLineEndings in
Expand Down
1 change: 0 additions & 1 deletion Source/CarthageKit/GitHub.swift
@@ -1,5 +1,4 @@
import Foundation
import Result
import ReactiveSwift
import Tentacle

Expand Down
4 changes: 2 additions & 2 deletions Source/CarthageKit/GitURL.swift
Expand Up @@ -24,12 +24,12 @@ public struct GitURL {
// scp syntax.
var strippedURLString = urlString

if let index = strippedURLString.index(of: "@") {
if let index = strippedURLString.firstIndex(of: "@") {
strippedURLString.removeSubrange(strippedURLString.startIndex...index)
}

var host = ""
if let index = strippedURLString.index(of: ":") {
if let index = strippedURLString.firstIndex(of: ":") {
host = String(strippedURLString[strippedURLString.startIndex..<index])
strippedURLString.removeSubrange(strippedURLString.startIndex...index)
}
Expand Down