Add xpmcore target
This commit is contained in:
parent
21f246ea96
commit
ea095fe3e7
|
@ -17,12 +17,21 @@ let package = Package(
|
||||||
.package(url: "https://github.com/apple/swift-package-manager", from: "0.2.0"),
|
.package(url: "https://github.com/apple/swift-package-manager", from: "0.2.0"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
|
.target(
|
||||||
|
name: "xpmcore",
|
||||||
|
dependencies: ["Utility"]),
|
||||||
|
.target(
|
||||||
|
name: "xpmcoreTesting",
|
||||||
|
dependencies: ["xpmcore"]),
|
||||||
|
.testTarget(
|
||||||
|
name: "xpmcoreTests",
|
||||||
|
dependencies: ["xpmcore"]),
|
||||||
.target(
|
.target(
|
||||||
name: "xpmkit",
|
name: "xpmkit",
|
||||||
dependencies: ["xcodeproj", "Utility"]),
|
dependencies: ["xcodeproj", "Utility", "xpmcore"]),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "xpmkitTests",
|
name: "xpmkitTests",
|
||||||
dependencies: ["xpmkit"]),
|
dependencies: ["xpmkit", "xpmcoreTesting"]),
|
||||||
.target(
|
.target(
|
||||||
name: "xpm",
|
name: "xpm",
|
||||||
dependencies: ["xpmkit"]),
|
dependencies: ["xpmkit"]),
|
||||||
|
@ -31,10 +40,10 @@ let package = Package(
|
||||||
dependencies: ["xpmkit"]),
|
dependencies: ["xpmkit"]),
|
||||||
.target(
|
.target(
|
||||||
name: "xpmenvkit",
|
name: "xpmenvkit",
|
||||||
dependencies: ["Utility"]),
|
dependencies: ["Utility", "xpmcore"]),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "xpmenvkitTests",
|
name: "xpmenvkitTests",
|
||||||
dependencies: ["xpm"]),
|
dependencies: ["xpm", "xpmcoreTesting"]),
|
||||||
.target(
|
.target(
|
||||||
name: "xpmenv",
|
name: "xpmenv",
|
||||||
dependencies: ["xpmenvkit"]),
|
dependencies: ["xpmenvkit"]),
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Basic
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// Protocol that represents an object that can print messages.
|
/// Protocol that represents an object that can print messages.
|
||||||
protocol Printing: AnyObject {
|
public protocol Printing: AnyObject {
|
||||||
/// Prints a message on the console.
|
/// Prints a message on the console.
|
||||||
///
|
///
|
||||||
/// - Parameter text: message to be printed.
|
/// - Parameter text: message to be printed.
|
||||||
|
@ -25,15 +25,17 @@ protocol Printing: AnyObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default printer that conforms the printing protocol.
|
/// Default printer that conforms the printing protocol.
|
||||||
class Printer: Printing {
|
public class Printer: Printing {
|
||||||
// swiftlint:disable force_cast
|
// swiftlint:disable force_cast
|
||||||
let terminalController: TerminalController = TerminalController(stream: stdoutStream as! LocalFileOutputByteStream)!
|
let terminalController: TerminalController = TerminalController(stream: stdoutStream as! LocalFileOutputByteStream)!
|
||||||
// swiftlint:enable force_cast
|
// swiftlint:enable force_cast
|
||||||
|
|
||||||
|
public init() {}
|
||||||
|
|
||||||
/// Prints a message on the console.
|
/// Prints a message on the console.
|
||||||
///
|
///
|
||||||
/// - Parameter text: message to be printed.
|
/// - Parameter text: message to be printed.
|
||||||
func print(_ text: String) {
|
public func print(_ text: String) {
|
||||||
let writer = InteractiveWriter.stdout
|
let writer = InteractiveWriter.stdout
|
||||||
writer.write(text)
|
writer.write(text)
|
||||||
writer.write("\n")
|
writer.write("\n")
|
||||||
|
@ -42,7 +44,7 @@ class Printer: Printing {
|
||||||
/// Prints an error.
|
/// Prints an error.
|
||||||
///
|
///
|
||||||
/// - Parameter error: error to be printed.
|
/// - Parameter error: error to be printed.
|
||||||
func print(error: Error) {
|
public func print(error: Error) {
|
||||||
let writer = InteractiveWriter.stderr
|
let writer = InteractiveWriter.stderr
|
||||||
writer.write("Error: ", inColor: .red, bold: true)
|
writer.write("Error: ", inColor: .red, bold: true)
|
||||||
writer.write(error.localizedDescription)
|
writer.write(error.localizedDescription)
|
||||||
|
@ -52,7 +54,7 @@ class Printer: Printing {
|
||||||
/// Prints an error message.
|
/// Prints an error message.
|
||||||
///
|
///
|
||||||
/// - Parameter errorMessage: error message.
|
/// - Parameter errorMessage: error message.
|
||||||
func print(errorMessage: String) {
|
public func print(errorMessage: String) {
|
||||||
let writer = InteractiveWriter.stderr
|
let writer = InteractiveWriter.stderr
|
||||||
writer.write("Error: ", inColor: .red, bold: true)
|
writer.write("Error: ", inColor: .red, bold: true)
|
||||||
writer.write(errorMessage)
|
writer.write(errorMessage)
|
||||||
|
@ -62,7 +64,7 @@ class Printer: Printing {
|
||||||
/// Prints an error.
|
/// Prints an error.
|
||||||
///
|
///
|
||||||
/// - Parameter error: error to be printed.
|
/// - Parameter error: error to be printed.
|
||||||
func print(section: String) {
|
public func print(section: String) {
|
||||||
let writer = InteractiveWriter.stdout
|
let writer = InteractiveWriter.stdout
|
||||||
writer.write("\(section)", inColor: .green, bold: true)
|
writer.write("\(section)", inColor: .green, bold: true)
|
||||||
writer.write("\n")
|
writer.write("\n")
|
|
@ -0,0 +1,25 @@
|
||||||
|
import Foundation
|
||||||
|
@testable import xpmcore
|
||||||
|
|
||||||
|
public final class MockPrinter: Printing {
|
||||||
|
public var printArgs: [String] = []
|
||||||
|
public var printErrorArgs: [Error] = []
|
||||||
|
public var printSectionArgs: [String] = []
|
||||||
|
public var printErrorMessageArgs: [String] = []
|
||||||
|
|
||||||
|
public func print(_ text: String) {
|
||||||
|
printArgs.append(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func print(section: String) {
|
||||||
|
printSectionArgs.append(section)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func print(errorMessage: String) {
|
||||||
|
printErrorMessageArgs.append(errorMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func print(error: Error) {
|
||||||
|
printErrorArgs.append(error)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import xpmenvkit
|
import xpmenvkit
|
||||||
|
|
||||||
XPMEnvCommand().execute()
|
var registry = CommandRegistry()
|
||||||
|
try registry.run()
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import Foundation
|
||||||
|
import Utility
|
||||||
|
|
||||||
|
protocol Command {
|
||||||
|
static var command: String { get }
|
||||||
|
static var overview: String { get }
|
||||||
|
init(parser: ArgumentParser)
|
||||||
|
func run(with arguments: ArgumentParser.Result) throws
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import Basic
|
||||||
|
import Foundation
|
||||||
|
import Utility
|
||||||
|
|
||||||
|
public final class CommandRegistry {
|
||||||
|
public init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public func run() throws {
|
||||||
|
// let parsedArguments = try parse()
|
||||||
|
// try process(arguments: parsedArguments)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
//
|
||||||
|
// GlobalCommand.swift
|
||||||
|
// xpmenvkit
|
||||||
|
//
|
||||||
|
// Created by Pedro Piñera Buendía on 14.07.18.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
|
@ -58,9 +58,17 @@ public class XPMEnvCommand {
|
||||||
|
|
||||||
let cliPath = path.appending(component: "xpm")
|
let cliPath = path.appending(component: "xpm")
|
||||||
|
|
||||||
|
var arguments: [String] = [cliPath.asString]
|
||||||
/// We drop the first element, which is the path to this executable.
|
/// We drop the first element, which is the path to this executable.
|
||||||
let exitStatus = Process.run(path: cliPath.asString, arguments: Array(CommandLine.arguments.dropFirst()))
|
arguments.append(contentsOf: Array(CommandLine.arguments.dropFirst()))
|
||||||
exit(exitStatus)
|
let status: ProcessResult.ExitStatus = try Process.popen(arguments: arguments).exitStatus
|
||||||
|
if case let ProcessResult.ExitStatus.signalled(code) = status {
|
||||||
|
exit(code)
|
||||||
|
} else if case let ProcessResult.ExitStatus.terminated(code) = status {
|
||||||
|
exit(code)
|
||||||
|
} else {
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
} catch let error as FatalError {
|
} catch let error as FatalError {
|
||||||
let message = """
|
let message = """
|
||||||
\("Error:".bold().red()) \(error.errorDescription)
|
\("Error:".bold().red()) \(error.errorDescription)
|
|
@ -0,0 +1 @@
|
||||||
|
import Foundation
|
|
@ -1,39 +0,0 @@
|
||||||
import Foundation
|
|
||||||
|
|
||||||
extension Process {
|
|
||||||
/// Runs the file at the given path with the given arguments.
|
|
||||||
/// It forwards the intputs/outputs from and to the standard input and output.
|
|
||||||
/// This method blocks the thread until the execution of the process finishes, and then returns the termination status.
|
|
||||||
///
|
|
||||||
/// - Parameters:
|
|
||||||
/// - path: path to the file to be executed.
|
|
||||||
/// - arguments: arguments to be passed.
|
|
||||||
/// - Returns: the termination status.
|
|
||||||
static func run(path: String, arguments: [String] = []) -> Int32 {
|
|
||||||
let process = Process()
|
|
||||||
process.launchPath = path
|
|
||||||
process.arguments = arguments
|
|
||||||
|
|
||||||
let outputPipe = Pipe()
|
|
||||||
let errorPipe = Pipe()
|
|
||||||
let inputPipe = Pipe()
|
|
||||||
process.standardOutput = outputPipe
|
|
||||||
process.standardError = errorPipe
|
|
||||||
process.standardInput = inputPipe
|
|
||||||
|
|
||||||
outputPipe.fileHandleForReading.readabilityHandler = { handler in
|
|
||||||
FileHandle.standardOutput.write(handler.availableData)
|
|
||||||
}
|
|
||||||
errorPipe.fileHandleForReading.readabilityHandler = { handler in
|
|
||||||
FileHandle.standardError.write(handler.availableData)
|
|
||||||
}
|
|
||||||
FileHandle.standardInput.readabilityHandler = { handler in
|
|
||||||
inputPipe.fileHandleForWriting.write(handler.availableData)
|
|
||||||
}
|
|
||||||
|
|
||||||
process.launch()
|
|
||||||
process.waitUntilExit()
|
|
||||||
|
|
||||||
return process.terminationStatus
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import xpmcore
|
||||||
|
|
||||||
/// Utils class that contains dependencies used by commands.
|
/// Utils class that contains dependencies used by commands.
|
||||||
protocol CommandsContexting: Contexting {
|
protocol CommandsContexting: Contexting {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import xpmcore
|
||||||
|
|
||||||
/// Error handling protocol.
|
/// Error handling protocol.
|
||||||
protocol ErrorHandling: AnyObject {
|
protocol ErrorHandling: AnyObject {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import xpmcore
|
||||||
|
|
||||||
/// Generator context protocol.
|
/// Generator context protocol.
|
||||||
protocol GeneratorContexting: Contexting {
|
protocol GeneratorContexting: Contexting {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Basic
|
import Basic
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import xpmcore
|
||||||
|
|
||||||
/// Protocol that defines the interface of the context that is used during the graph loading.
|
/// Protocol that defines the interface of the context that is used during the graph loading.
|
||||||
protocol GraphLoaderContexting: Contexting {
|
protocol GraphLoaderContexting: Contexting {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import xpmcore
|
||||||
|
|
||||||
/// Context protocol.
|
/// Context protocol.
|
||||||
protocol Contexting: AnyObject {
|
protocol Contexting: AnyObject {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import xpmkit
|
||||||
|
|
||||||
var registry = CommandRegistry()
|
var registry = CommandRegistry()
|
||||||
try registry.run()
|
try registry.run()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Basic
|
||||||
import Foundation
|
import Foundation
|
||||||
import Utility
|
import Utility
|
||||||
import XCTest
|
import XCTest
|
||||||
|
@testable import xpmcoreTesting
|
||||||
@testable import xpmkit
|
@testable import xpmkit
|
||||||
|
|
||||||
final class DumpCommandTests: XCTestCase {
|
final class DumpCommandTests: XCTestCase {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Foundation
|
||||||
import Utility
|
import Utility
|
||||||
@testable import xcodeproj
|
@testable import xcodeproj
|
||||||
import XCTest
|
import XCTest
|
||||||
|
@testable import xpmcoreTesting
|
||||||
@testable import xpmkit
|
@testable import xpmkit
|
||||||
|
|
||||||
final class GenerateCommandTests: XCTestCase {
|
final class GenerateCommandTests: XCTestCase {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import XCTest
|
import XCTest
|
||||||
|
@testable import xpmcoreTesting
|
||||||
@testable import xpmkit
|
@testable import xpmkit
|
||||||
|
|
||||||
fileprivate struct TestError: FatalError {
|
fileprivate struct TestError: FatalError {
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
import Foundation
|
|
||||||
@testable import xpmkit
|
|
||||||
|
|
||||||
final class MockPrinter: Printing {
|
|
||||||
var printArgs: [String] = []
|
|
||||||
var printErrorArgs: [Error] = []
|
|
||||||
var printSectionArgs: [String] = []
|
|
||||||
var printErrorMessageArgs: [String] = []
|
|
||||||
|
|
||||||
func print(_ text: String) {
|
|
||||||
printArgs.append(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func print(section: String) {
|
|
||||||
printSectionArgs.append(section)
|
|
||||||
}
|
|
||||||
|
|
||||||
func print(errorMessage: String) {
|
|
||||||
printErrorMessageArgs.append(errorMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
func print(error: Error) {
|
|
||||||
printErrorArgs.append(error)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue