1

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?

zaph
  • 111,848
  • 21
  • 189
  • 228
MichalMoskala
  • 887
  • 1
  • 12
  • 25
  • You'll need to quote that device name if it contains spaces. – trojanfoe Jul 16 '15 at 12:33
  • println() destination and arguments so you can see exactly the commands, that is basic debugging. My guess is the space in "iPhone 4s" is the problem. – zaph Jul 16 '15 at 12:33
  • I also thought `xcodebuild` cared about *current directory* as well. – trojanfoe Jul 16 '15 at 12:37
  • destination parameter is one string so it is: -destination 'platform=iOS Simulator,name=iPhone4s,OS=9.0'. In that case there is no problem with quotes – MichalMoskala Jul 16 '15 at 13:45
  • Got this message: dyld: Symbol not found: _OBJC_CLASS_$_OS_object Referenced from: /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/system/libxpc.dylib Expected in: /usr/lib/system/introspection/libdispatch.dylib in /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/system/libxpc.dylib cdtool exited abnormally – MichalMoskala Jul 16 '15 at 14:24
  • The question has: "iPhone 4s", the comment has: "name=iPhone4s", the name is not the same. – zaph Jul 16 '15 at 14:32
  • Oh sorry, it was my mistake but after correction nothing changes. Even if i run script that has hardcoded arguments if fails. The same script that was executed from terminal runs well. – MichalMoskala Jul 16 '15 at 15:23
  • @MichalMoskala Any updates here? I encountered the same error when archiving my project... – Itachi Jun 16 '16 at 09:45
  • @Itachi unfortunately I haven't fixed it – MichalMoskala Jun 16 '16 at 09:48

0 Answers0