Skip to content

Commit

Permalink
Finally migrate to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Jan 28, 2017
1 parent 96af5b6 commit cf02955
Show file tree
Hide file tree
Showing 37 changed files with 309 additions and 297 deletions.
8 changes: 4 additions & 4 deletions Carthage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@
GCC_NO_COMMON_BLOCKS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
ONLY_ACTIVE_ARCH = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -859,7 +859,7 @@
buildSettings = {
GCC_NO_COMMON_BLOCKS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -931,7 +931,7 @@
buildSettings = {
GCC_NO_COMMON_BLOCKS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Profile;
};
Expand Down Expand Up @@ -972,7 +972,7 @@
buildSettings = {
GCC_NO_COMMON_BLOCKS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Test;
};
Expand Down
6 changes: 3 additions & 3 deletions Source/CarthageKit/Algorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public func topologicalSort<Node: Comparable>(_ graph: Dictionary<Node, Set<Node

// Maintain a working graph with all sources removed.
var workingGraph = graph
sources.forEach { node in workingGraph.removeValueForKey(node) }
sources.forEach { node in workingGraph.removeValue(forKey: node) }

var sorted: [Node] = []

while !sources.isEmpty {
sources.sortInPlace(>)
sources.sort(by: >)

let lastSource = sources.removeLast()
sorted.append(lastSource)
Expand All @@ -58,7 +58,7 @@ public func topologicalSort<Node: Comparable>(_ graph: Dictionary<Node, Set<Node

if incomingEdges.isEmpty {
sources.append(node)
workingGraph.removeValueForKey(node)
workingGraph.removeValue(forKey: node)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Source/CarthageKit/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import ReactiveTask

/// Zips the given input paths (recursively) into an archive that will be
/// located at the given URL.
public func zip(paths paths: [String], into archiveURL: URL, workingDirectory: String) -> SignalProducer<(), CarthageError> {
public func zip(paths: [String], into archiveURL: URL, workingDirectory: String) -> SignalProducer<(), CarthageError> {
precondition(!paths.isEmpty)
precondition(archiveURL.isFileURL)

let task = Task("/usr/bin/env", workingDirectoryPath: workingDirectory, arguments: [ "zip", "-q", "-r", "--symlinks", archiveURL.carthage_path ] + paths)
let task = Task("/usr/bin/env", arguments: [ "zip", "-q", "-r", "--symlinks", archiveURL.carthage_path ] + paths, workingDirectoryPath: workingDirectory)

return task.launch()
.mapError(CarthageError.taskError)
.then(.empty)
.then(SignalProducer<(), CarthageError>.empty)
}

/// Unzips the archive at the given file URL, extracting into the given
Expand All @@ -37,15 +37,15 @@ public func unzip(archive fileURL: URL, to destinationDirectoryURL: URL) -> Sign
let task = Task("/usr/bin/env", arguments: [ "unzip", "-qq", "-d", destinationDirectoryURL.carthage_path, fileURL.carthage_path ])
return task.launch()
.mapError(CarthageError.taskError)
.then(.empty)
.then(SignalProducer<(), CarthageError>.empty)
}

/// Unzips the archive at the given file URL into a temporary directory, then
/// sends the file URL to that directory.
public func unzip(archive fileURL: URL) -> SignalProducer<URL, CarthageError> {
return SignalProducer.attempt { () -> Result<String, CarthageError> in
var temporaryDirectoryTemplate: [CChar] = (NSTemporaryDirectory() as NSString).appendingPathComponent("carthage-archive.XXXXXX").nulTerminatedUTF8.map { CChar($0) }
let result = temporaryDirectoryTemplate.withUnsafeMutableBufferPointer { (inout template: UnsafeMutableBufferPointer<CChar>) -> UnsafeMutablePointer<CChar> in
var temporaryDirectoryTemplate: ContiguousArray<CChar> = (NSTemporaryDirectory() as NSString).appendingPathComponent("carthage-archive.XXXXXX").utf8CString
let result: UnsafeMutablePointer<Int8>? = temporaryDirectoryTemplate.withUnsafeMutableBufferPointer { (template: inout UnsafeMutableBufferPointer<CChar>) -> UnsafeMutablePointer<CChar> in
return mkdtemp(template.baseAddress)
}

Expand All @@ -54,14 +54,14 @@ public func unzip(archive fileURL: URL) -> SignalProducer<URL, CarthageError> {
}

let temporaryPath = temporaryDirectoryTemplate.withUnsafeBufferPointer { (ptr: UnsafeBufferPointer<CChar>) -> String in
return String.fromCString(ptr.baseAddress)!
return String(validatingUTF8: ptr.baseAddress!)!
}

return .success(temporaryPath)
}
.map { URL(fileURLWithPath: $0, isDirectory: true) }
.flatMap(.merge) { directoryURL in
return unzip(archive: fileURL, to: directoryURL)
.then(SignalProducer(value: directoryURL))
.then(SignalProducer<URL, CarthageError>(value: directoryURL))
}
}
36 changes: 18 additions & 18 deletions Source/CarthageKit/Availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,84 @@ import Result

// MARK: - Archive.swift

@available(*, unavailable, renamed="zip(paths:into:workingDirectory:)")
@available(*, unavailable, renamed: "zip(paths:into:workingDirectory:)")
public func zipIntoArchive(_ destinationArchiveURL: URL, workingDirectory: String, inputPaths: [String]) -> SignalProducer<(), CarthageError> { fatalError() }

@available(*, unavailable, renamed="unzip(archive:to:)")
@available(*, unavailable, renamed: "unzip(archive:to:)")
public func unzipArchiveToDirectory(_ fileURL: URL, _ destinationDirectoryURL: URL) -> SignalProducer<(), CarthageError> { fatalError() }

@available(*, unavailable, renamed="unzip(archive:)")
@available(*, unavailable, renamed: "unzip(archive:)")
public func unzipArchiveToTemporaryDirectory(_ fileURL: URL) -> SignalProducer<URL, CarthageError> { fatalError() }

// MARK: - Cartfile.swift

extension Cartfile {
@available(*, unavailable, renamed="url(in:)")
@available(*, unavailable, renamed: "url(in:)")
public static func urlInDirectory(_ directoryURL: URL) -> URL { fatalError() }

@available(*, unavailable, renamed="from(string:)")
@available(*, unavailable, renamed: "from(string:)")
public static func fromString(_ string: String) -> Result<Cartfile, CarthageError> { fatalError() }

@available(*, unavailable, renamed="from(file:)")
@available(*, unavailable, renamed: "from(file:)")
public static func fromFile(_ cartfileURL: URL) -> Result<Cartfile, CarthageError> { fatalError() }
}

extension ResolvedCartfile {
@available(*, unavailable, renamed="url(in:)")
@available(*, unavailable, renamed: "url(in:)")
public static func urlInDirectory(_ directoryURL: URL) -> URL { fatalError() }

@available(*, unavailable, renamed="from(string:)")
@available(*, unavailable, renamed: "from(string:)")
public static func fromString(_ string: String) -> Result<ResolvedCartfile, CarthageError> { fatalError() }

@available(*, unavailable, renamed="append(_:)")
@available(*, unavailable, renamed: "append(_:)")
public mutating func appendCartfile(_ cartfile: Cartfile) { fatalError() }
}

@available(*, unavailable, renamed="duplicateProjectsIn(_:_:)")
@available(*, unavailable, renamed: "duplicateProjectsIn(_:_:)")
public func duplicateProjectsInCartfiles(_ cartfile1: Cartfile, _ cartfile2: Cartfile) -> [ProjectIdentifier] { fatalError() }

// MARK: - Git.swift

@available(*, unavailable, renamed="cloneRepository(_:_:isBare:)")
@available(*, unavailable, renamed: "cloneRepository(_:_:isBare:)")
public func cloneRepository(_ cloneURL: GitURL, _ destinationURL: URL, bare: Bool = true) -> SignalProducer<String, CarthageError> { fatalError() }

// MARK: - MachOType.swift

extension MachOType {
@available(*, unavailable, renamed="from(string:)")
@available(*, unavailable, renamed: "from(string:)")
public static func fromString(_ string: String) -> Result<MachOType, CarthageError> { fatalError() }
}

// MARK: - ProductType.swift

extension ProductType {
@available(*, unavailable, renamed="from(string:)")
@available(*, unavailable, renamed: "from(string:)")
public static func fromString(_ string: String) -> Result<ProductType, CarthageError> { fatalError() }
}

// MARK: - SDK.swift

extension SDK {
@available(*, unavailable, renamed="from(string:)")
@available(*, unavailable, renamed: "from(string:)")
public static func fromString(_ string: String) -> Result<SDK, CarthageError> { fatalError() }
}

// MARK: - Version.swift

extension SemanticVersion {
@available(*, unavailable, renamed="from(_:)")
@available(*, unavailable, renamed: "from(_:)")
public static func fromPinnedVersion(_ pinnedVersion: PinnedVersion) -> Result<SemanticVersion, CarthageError> { fatalError() }
}

extension VersionSpecifier {
@available(*, unavailable, renamed="isSatisfied(by:)")
@available(*, unavailable, renamed: "isSatisfied(by:)")
public func satisfiedBy(_ version: PinnedVersion) -> Bool { fatalError() }
}

// MARK: - Xcode.swift

@available(*, unavailable, renamed="ProjectLocator.locate(in:)")
@available(*, unavailable, renamed: "ProjectLocator.locate(in:)")
public func locateProjectsInDirectory(_ directoryURL: URL) -> SignalProducer<ProjectLocator, CarthageError> { fatalError() }

@available(*, unavailable, renamed="ProjectLocator.schemes(self:)")
@available(*, unavailable, renamed: "ProjectLocator.schemes(self:)")
public func schemesInProject(_ project: ProjectLocator) -> SignalProducer<String, CarthageError> { fatalError() }
2 changes: 1 addition & 1 deletion Source/CarthageKit/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct BuildSettings {
// can sometimes hang indefinitely on projects that don't
// share any schemes, so automatically bail out if it looks
// like that's happening.
.timeout(after: 60, raising: .xcodebuildTimeout(arguments.project), on: QueueScheduler(qos: QOS_CLASS_DEFAULT))
.timeout(after: 60, raising: .xcodebuildTimeout(arguments.project), on: QueueScheduler(qos: .default))
.retry(upTo: 5)
.map { data in
return String(data: data, encoding: .utf8)!
Expand Down
22 changes: 11 additions & 11 deletions Source/CarthageKit/Cartfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct Cartfile {
}

/// Attempts to parse Cartfile information from a string.
public static func from(string string: String) -> Result<Cartfile, CarthageError> {
public static func from(string: String) -> Result<Cartfile, CarthageError> {
var dependencies: [Dependency<VersionSpecifier>] = []
var result: Result<(), CarthageError> = .success(())

Expand All @@ -54,10 +54,10 @@ public struct Cartfile {
}

switch Dependency<VersionSpecifier>.from(scanner) {
case let .Success(dep):
case let .success(dep):
dependencies.append(dep)

case let .Failure(error):
case let .failure(error):
result = .failure(error)
stop = true
}
Expand Down Expand Up @@ -128,7 +128,7 @@ extension Cartfile: CustomStringConvertible {
public func duplicateProjectsIn(_ cartfile1: Cartfile, _ cartfile2: Cartfile) -> [ProjectIdentifier] {
let projects1 = cartfile1.dependencies.map { $0.project }
let projects2 = cartfile2.dependencies.map { $0.project }
return Array(Set(projects1).intersect(projects2))
return Array(Set(projects1).intersection(Set(projects2)))
}

/// Represents a parsed Cartfile.resolved, which specifies which exact version was
Expand Down Expand Up @@ -157,17 +157,17 @@ public struct ResolvedCartfile {
}

/// Attempts to parse Cartfile.resolved information from a string.
public static func from(string string: String) -> Result<ResolvedCartfile, CarthageError> {
public static func from(string: String) -> Result<ResolvedCartfile, CarthageError> {
var cartfile = self.init(dependencies: [])
var result: Result<(), CarthageError> = .success(())

let scanner = Scanner(string: string)
scannerLoop: while !scanner.isAtEnd {
switch Dependency<PinnedVersion>.from(scanner) {
case let .Success(dep):
case let .success(dep):
cartfile.dependencies.insert(dep)

case let .Failure(error):
case let .failure(error):
result = .failure(error)
break scannerLoop
}
Expand All @@ -180,7 +180,7 @@ public struct ResolvedCartfile {
extension ResolvedCartfile: CustomStringConvertible {
public var description: String {
return dependencies
.sort { $0.project.description < $1.project.description }
.sorted { $0.project.description < $1.project.description }
.map { $0.description + "\n" }
.joined(separator: "")
}
Expand Down Expand Up @@ -281,11 +281,11 @@ extension ProjectIdentifier: CustomStringConvertible {
case let .gitHub(repo):
let repoDescription: String
switch repo.server {
case .DotCom:
case .dotCom:
repoDescription = "\(repo.owner)/\(repo.name)"

case .Enterprise:
repoDescription = "\(repo.URL)"
case .enterprise:
repoDescription = "\(repo.url)"
}
return "github \"\(repoDescription)\""

Expand Down
6 changes: 3 additions & 3 deletions Source/CarthageKit/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ReactiveTask
import Tentacle

/// Possible errors that can originate from Carthage.
public enum CarthageError: ErrorType, Equatable {
public enum CarthageError: Error, Equatable {
public typealias VersionRequirement = (specifier: VersionSpecifier, fromProject: ProjectIdentifier?)

/// One or more arguments was invalid.
Expand Down Expand Up @@ -280,7 +280,7 @@ extension CarthageError: CustomStringConvertible {

case let .buildFailed(taskError, log):
var message = "Build Failed\n"
if case let .ShellTaskFailed(task, exitCode, _) = taskError {
if case let .shellTaskFailed(task, exitCode, _) = taskError {
message += "\tTask failed with exit code \(exitCode):\n"
message += "\t\(task)\n"
} else {
Expand Down Expand Up @@ -312,7 +312,7 @@ public struct DuplicateDependency: Comparable {
// test case.
public init(project: ProjectIdentifier, locations: [String]) {
self.project = project
self.locations = locations.sort(<)
self.locations = locations.sorted(by: <)
}
}

Expand Down
Loading

0 comments on commit cf02955

Please sign in to comment.