Skip to content

Commit

Permalink
Renamed print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Werner Altewischer committed Nov 11, 2019
1 parent bc3d765 commit e41da3f
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 137 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
},
{
"package": "Commandant",
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"repositoryURL": "https://github.com/nsoperations/Commandant.git",
"state": {
"branch": null,
"revision": "2cd0210f897fe46c6ce42f52ccfa72b3bbb621a0",
"version": "0.16.0"
"branch": "feature/success-handler",
"revision": "52f74502b2a06a89dffb5c29164fa7a408133225",
"version": null
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/antitypical/Result.git", from: "4.1.0"),
.package(url: "https://github.com/Carthage/Commandant.git", .exact("0.16.0")),
.package(url: "https://github.com/nsoperations/Commandant.git", .branch("feature/success-handler")),
.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"),
Expand Down
28 changes: 28 additions & 0 deletions Source/ReactiveTask/Cache.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation
import ReactiveSwift

public protocol Cache {
associatedtype Key: Hashable
associatedtype Value
subscript(_ key: Key) -> Value? { get set }
}

extension Dictionary: Cache {

}

extension Atomic where Value: Cache {
public subscript(_ key: Value.Key) -> Value.Value? {
get {
return self.withValue { map -> Value.Value? in
return map[key]
}
}

set {
self.modify { map in
map[key] = newValue
}
}
}
}
69 changes: 3 additions & 66 deletions Source/ReactiveTask/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,6 @@ import Foundation
import ReactiveSwift
import Result

/// An error originating from ReactiveTask.
public enum TaskError: Error, Equatable {

/// A shell task failed to launch
case launchFailed(Task, reason: String?)

/// A shell task exited unsuccessfully.
case shellTaskFailed(Task, exitCode: Int32, standardError: String?)

/// An error was returned from a POSIX API.
case posixError(Int32)
}

extension TaskError: CustomStringConvertible {
public var description: String {
switch self {
case let .launchFailed(task, reason: reason):
var description = "A shell task (\(task)) failed to launch"
if let reason = reason {
description += ":\n\(reason)"
}
return description

case let .shellTaskFailed(task, exitCode, standardError):
var description = "A shell task (\(task)) failed with exit code \(exitCode)"
if let standardError = standardError {
description += ":\n\(standardError)"
}
return description

case let .posixError(code):
return NSError(domain: NSPOSIXErrorDomain, code: Int(code), userInfo: nil).description
}
}
}

/// Describes how to execute a shell command.
public struct Task {
/// The path to the executable that should be launched.
Expand Down Expand Up @@ -74,7 +38,7 @@ public struct Task {

private static let counter = Atomic(0)

fileprivate let identifier: Int
public let identifier: Int

/// A GCD group which to wait completion
fileprivate static let group = DispatchGroup()
Expand Down Expand Up @@ -431,7 +395,6 @@ extension Task {
public static var history: [Task: TimeInterval] {
return taskHistory.value
}

#endif

public static var debugLoggingEnabled = false
Expand Down Expand Up @@ -583,7 +546,7 @@ extension Task {
// through stdout.

if Task.debugLoggingEnabled {
print(String(format: "Task #\(self.identifier) finished successfully in %.2f s.", duration))
print(String(format: "Task #\(self.identifier) finished successfully in %.2fs.", duration))
}

lifetime += stderrAggregated
Expand All @@ -598,7 +561,7 @@ extension Task {
} else {

if Task.debugLoggingEnabled {
print(String(format: "Task #\(self.identifier) failed with exit code \(terminationStatus) in %.2f s.", duration))
print(String(format: "Task #\(self.identifier) failed with exit code \(terminationStatus) in %.2fs.", duration))
}
// Wait for stdout to finish, then pass
// through stderr.
Expand Down Expand Up @@ -654,29 +617,3 @@ extension Task {
}
}
}

public protocol Cache {
associatedtype Key: Hashable
associatedtype Value
subscript(_ key: Key) -> Value? { get set }
}

extension Dictionary: Cache {

}

extension Atomic where Value: Cache {
public subscript(_ key: Value.Key) -> Value.Value? {
get {
return self.withValue { map -> Value.Value? in
return map[key]
}
}

set {
self.modify { map in
map[key] = newValue
}
}
}
}
37 changes: 37 additions & 0 deletions Source/ReactiveTask/TaskError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation

/// An error originating from ReactiveTask.
public enum TaskError: Error, Equatable {

/// A shell task failed to launch
case launchFailed(Task, reason: String?)

/// A shell task exited unsuccessfully.
case shellTaskFailed(Task, exitCode: Int32, standardError: String?)

/// An error was returned from a POSIX API.
case posixError(Int32)
}

extension TaskError: CustomStringConvertible {
public var description: String {
switch self {
case let .launchFailed(task, reason: reason):
var description = "A shell task (\(task)) failed to launch"
if let reason = reason {
description += ":\n\(reason)"
}
return description

case let .shellTaskFailed(task, exitCode, standardError):
var description = "A shell task (\(task)) failed with exit code \(exitCode)"
if let standardError = standardError {
description += ":\n\(standardError)"
}
return description

case let .posixError(code):
return NSError(domain: NSPOSIXErrorDomain, code: Int(code), userInfo: nil).description
}
}
}
4 changes: 2 additions & 2 deletions Source/carthage/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public struct ArchiveCommand: CommandProtocol {
let frameworkNames = options.frameworkNames
let directoryURL = URL(fileURLWithPath: options.directoryPath)
return Archive.archiveFrameworks(frameworkNames: frameworkNames, dependencyName: nil, directoryURL: directoryURL, customOutputPath: options.outputPath, frameworkFoundHandler: { path in
carthage.println(formatting.bullets + "Found " + formatting.path(path))
carthage.printOut(formatting.bullets + "Found " + formatting.path(path))
}).on(value: { outputURL in
carthage.println(formatting.bullets + "Created " + formatting.path(outputURL.path))
carthage.printOut(formatting.bullets + "Created " + formatting.path(outputURL.path))
})
}
}
2 changes: 1 addition & 1 deletion Source/carthage/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct BootstrapCommand: CommandProtocol {
.flatMap(.merge) { project -> SignalProducer<(), CarthageError> in
if !FileManager.default.fileExists(atPath: project.resolvedCartfileURL.path) {
let formatting = options.checkoutOptions.colorOptions.formatting
carthage.println(formatting.bullets + "No Cartfile.resolved found, updating dependencies")
carthage.printOut(formatting.bullets + "No Cartfile.resolved found, updating dependencies")
return project.updateDependencies(
shouldCheckout: options.checkoutAfterUpdate,
buildOptions: options.buildOptions).then(options.buildProducer(project: project))
Expand Down
4 changes: 2 additions & 2 deletions Source/carthage/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public struct BuildCommand: CommandProtocol {
.on(
started: {
if let path = temporaryURL?.path {
carthage.println(formatting.bullets + "xcodebuild output can be found in " + formatting.path(path))
carthage.printOut(formatting.bullets + "xcodebuild output can be found in " + formatting.path(path))
}
},
value: { taskEvent in
Expand All @@ -156,7 +156,7 @@ public struct BuildCommand: CommandProtocol {
stderrHandle.write(data)

case let .success(project, scheme):
carthage.println(formatting.bullets + "Building scheme " + formatting.quote(scheme.name) + " in " + formatting.projectName(project.description))
carthage.printOut(formatting.bullets + "Building scheme " + formatting.quote(scheme.name) + " in " + formatting.projectName(project.description))
}
}
)
Expand Down
10 changes: 5 additions & 5 deletions Source/carthage/CopyFrameworks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct CopyFrameworksCommand: CommandProtocol {
let symbolsFolder: URL = try self.appropriateDestinationFolder().get()

let waitHandler: (URL) -> Void = { url in
carthage.println("Waiting for lock on url: \(url)")
carthage.printOut("Waiting for lock on url: \(url)")
}

return inputFiles(options)
Expand All @@ -43,11 +43,11 @@ public struct CopyFrameworksCommand: CommandProtocol {
.on(value: { event in
switch event {
case .copied(let frameworkName):
carthage.println("Copied \(frameworkName)")
carthage.printOut("Copied \(frameworkName)")
case .ignored(let frameworkName):
carthage.println("Ignoring \(frameworkName) because it does not support the current architecture")
carthage.printOut("Ignoring \(frameworkName) because it does not support the current architecture")
case .skipped(let frameworkName):
carthage.println("Skipped \(frameworkName) because it was already copied before")
carthage.printOut("Skipped \(frameworkName) because it was already copied before")
}
})
.waitOnCommand()
Expand Down Expand Up @@ -165,7 +165,7 @@ public struct CopyFrameworksCommand: CommandProtocol {
.on(
value: { url in
let name = url.lastPathComponent
carthage.println("Automatically discovered framework \(name) at: \"\(url.path)\"")
carthage.printOut("Automatically discovered framework \(name) at: \"\(url.path)\"")
}
)
)
Expand Down
8 changes: 4 additions & 4 deletions Source/carthage/Diagnose.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public struct DiagnoseCommand: CommandProtocol {

let repositoryUrl = baseUrl.appendingPathComponent("Repository")

carthage.println(formatting.bullets + "Started storing diagnosis info into directory: \(baseUrl.path)")
carthage.printOut(formatting.bullets + "Started storing diagnosis info into directory: \(baseUrl.path)")

let repository = LocalDependencyStore(directoryURL: repositoryUrl)
var dependencyMappings: [Dependency: Dependency]?
if let mappingsFilePath = options.mappingsFilePath {
carthage.println(formatting.bullets + "Using dependency mappings from file: \(mappingsFilePath)")
carthage.printOut(formatting.bullets + "Using dependency mappings from file: \(mappingsFilePath)")
dependencyMappings = try self.mappings(from: mappingsFilePath)
}
let logger = ResolverEventLogger(colorOptions: options.colorOptions, verbose: options.isVerbose)
Expand All @@ -94,8 +94,8 @@ public struct DiagnoseCommand: CommandProtocol {
}
return cartfileURL
}.map { cartfileURL -> URL in
carthage.println(formatting.bullets + "Finished storing diagnosis info into directory: \(baseUrl.path)")
carthage.println(formatting.bullets + "Please submit the contents of this directory to the Carthage team for review")
carthage.printOut(formatting.bullets + "Finished storing diagnosis info into directory: \(baseUrl.path)")
carthage.printOut(formatting.bullets + "Please submit the contents of this directory to the Carthage team for review")
return cartfileURL
}
} catch let error {
Expand Down
16 changes: 4 additions & 12 deletions Source/carthage/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,15 @@ private let outputQueue = { () -> DispatchQueue in
}()

/// A thread-safe version of Swift's standard println().
internal func println() {
internal func printOut(_ object: Any) {
outputQueue.async {
Swift.print()
fputs(String(describing: object) + "\n", stdout)
}
}

/// A thread-safe version of Swift's standard println().
internal func println<T>(_ object: T) {
outputQueue.async {
Swift.print(object)
}
}

/// A thread-safe version of Swift's standard print().
internal func print<T>(_ object: T) {
internal func printErr(_ object: Any) {
outputQueue.async {
Swift.print(object, terminator: "")
fputs(String(describing: object) + "\n", stderr)
}
}

Expand Down
Loading

0 comments on commit e41da3f

Please sign in to comment.