diff --git a/apous.xcodeproj/project.pbxproj b/apous.xcodeproj/project.pbxproj index 80985da..7c9ba22 100644 --- a/apous.xcodeproj/project.pbxproj +++ b/apous.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ 7D3AC3451B49F99B0068CC83 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; }; 7D3AC3471B49FE170068CC83 /* ErrorCodes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorCodes.swift; sourceTree = "<group>"; }; 7D3AC3491B4A37BC0068CC83 /* Tools.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tools.swift; sourceTree = "<group>"; }; + 7DC546B91B4C55640070A858 /* samples */ = {isa = PBXFileReference; lastKnownFileType = folder; path = samples; sourceTree = SOURCE_ROOT; }; 7DF997431B4B33A200E90F56 /* VersionInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionInfo.swift; sourceTree = "<group>"; }; 7DF9974F1B4B356700E90F56 /* version.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = version.sh; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -127,6 +128,7 @@ 7D0F00921B4AF32F003B6EF0 /* test */ = { isa = PBXGroup; children = ( + 7DC546B91B4C55640070A858 /* samples */, 7D0F00931B4AF32F003B6EF0 /* Samples.swift */, 7D0F00951B4AF32F003B6EF0 /* Info.plist */, ); diff --git a/samples/carthage/main.swift b/samples/carthage/main.swift index 073312b..fdfbe84 100644 --- a/samples/carthage/main.swift +++ b/samples/carthage/main.swift @@ -1,4 +1,4 @@ import Argo import Runes -print("dependencies import properly") \ No newline at end of file +print("dependencies imported properly") \ No newline at end of file diff --git a/samples/cocoapods/main.swift b/samples/cocoapods/main.swift index 073312b..fdfbe84 100644 --- a/samples/cocoapods/main.swift +++ b/samples/cocoapods/main.swift @@ -1,4 +1,4 @@ import Argo import Runes -print("dependencies import properly") \ No newline at end of file +print("dependencies imported properly") \ No newline at end of file diff --git a/src/Tools.swift b/src/Tools.swift index 8e916de..3350939 100644 --- a/src/Tools.swift +++ b/src/Tools.swift @@ -23,25 +23,28 @@ typealias Tool = (args: String...) throws -> TaskResult /// by `output` and `error`. func runTask(launchPath: String, args: [String] = [], outputToStandardOut: Bool = true) throws -> TaskResult { - // Ok, so stdout sucks the big one. If your NSTask actually does any redirection to another - // tool that then outputs to stdout, that is going to be buffered and will only come back in - // chunks. - - var master: Int32 = 0 - var slave: Int32 = 0 - if openpty(&master, &slave, nil, nil, nil) == -1 { - throw ErrorCode.PTYCreationFailed - } - defer { - close(master) - close(slave) - } - - let output = NSFileHandle(fileDescriptor: master) - // This is the buffered output that will be returned. var out = "" - + +// It turns out this code is not robust; it does not seem to always get all of the stream data. +// BUG #12 - https://github.com/owensd/apous/issues/12 +// +// // Ok, so stdout sucks the big one. If your NSTask actually does any redirection to another +// // tool that then outputs to stdout, that is going to be buffered and will only come back in +// // chunks. +// +// var master: Int32 = 0 +// var slave: Int32 = 0 +// if openpty(&master, &slave, nil, nil, nil) == -1 { +// throw ErrorCode.PTYCreationFailed +// } +// defer { +// close(master) +// close(slave) +// } +// +// let output = NSFileHandle(fileDescriptor: master) + func stream(handle: NSFileHandle) -> String { let data = handle.availableData let str = NSString(data: data, encoding: NSUTF8StringEncoding) as? String ?? "" @@ -85,8 +88,10 @@ func runTask(launchPath: String, args: [String] = [], outputToStandardOut: Bool return stripped } + + let output = NSPipe() - output.readabilityHandler = { out += stream($0) } + output.fileHandleForReading.readabilityHandler = { out += stream($0) } let task = NSTask() task.launchPath = try canonicalPath(launchPath) @@ -122,11 +127,17 @@ extension tools { static func pod(args: String...) throws -> TaskResult { guard let path = try launchPathForTool("pod") else { throw ErrorCode.CocoaPodsNotInstalled } + + let info = args.reduce("") { $0 + $1 + " " } + print("Running pod \(info)") return try runTask(path, args: args) } static func carthage(args: String...) throws -> TaskResult { guard let path = try launchPathForTool("carthage") else { throw ErrorCode.CarthageNotInstalled } + + let info = args.reduce("") { $0 + $1 + " " } + print("Running carthage \(info)") return try runTask(path, args: args) } diff --git a/src/Utils.swift b/src/Utils.swift index 92b3ff8..4316025 100644 --- a/src/Utils.swift +++ b/src/Utils.swift @@ -31,8 +31,9 @@ func filesAtPath(path: String) -> [String] { }() return items - .filter() { $0.pathExtension == "swift" } + .filter() { + let root = $0.pathComponents[0] + return $0.pathExtension == "swift" && (root != "Carthage" && root != "Rome" && root != "Pods") + } .map() { path.stringByAppendingPathComponent($0) } } - - diff --git a/test/Samples.swift b/test/Samples.swift index 354d465..1673b74 100644 --- a/test/Samples.swift +++ b/test/Samples.swift @@ -43,12 +43,12 @@ class SamplesTest : XCTestCase { } func testMulti() { - let output = "foo: 2\r\nbar: 1" + let output = "foo: 2\nbar: 1" validateSampleToolOutput("multi", output: output) } func testNested() { - let output = "Testing Nested Directories\r\nabspath: abspath!\r\nbasename: basename!" + let output = "Testing Nested Directories\nabspath: abspath!\nbasename: basename!" validateSampleToolOutput("nested", output: output) } }