Calling xcodebuild from Swift command line tool fails

牧云@^-^@ 提交于 2020-01-16 01:11:06

问题


I'm writing simple swift command line tool application that automates some of my iOS Dev work. Everything is working except one thing - calling xcodebuild script.

My method looks like this:

func runTest(deviceName: String, os: String) {
        killAllSimulators()
        let sdk = "iphonesimulator"
        let destination = "platform=iOS Simulator,name=" + deviceName + ",OS=" + os
        let arguments = ["-workspace", workspace, "-scheme", scheme, "-sdk", sdk, "-destination", destination, "test"]
        executor.executeCommand("xcodebuild", arguments: arguments)
    }

deviceName is equal to "iPhone 4s", os is equal to "9.0", workspace and scheme variables are properly set.

My execute command has simple implementation:

func executeCommand(command: String, arguments: [String]) -> NSString?  {
        _ = NSProcessInfo.processInfo().processIdentifier
        let pipe = NSPipe()
        let fileHandle = pipe.fileHandleForReading

        let task = NSTask()
        task.launchPath = "/usr/bin/" + command
        task.arguments = arguments
        task.standardOutput = pipe

        task.launch()
        let data = fileHandle.readDataToEndOfFile()
        fileHandle.closeFile()

        return NSString(data: data, encoding: NSUTF8StringEncoding)
    }

i got error that test failed because cdtool cannot compile. Thats very weird because exactly the same script called from terminal works..

Any ideas?

来源:https://stackoverflow.com/questions/31454008/calling-xcodebuild-from-swift-command-line-tool-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!