How do I run a Cocoa app after building it from the command line with xcodebuild?

别说谁变了你拦得住时间么 提交于 2019-12-02 00:16:54

问题


I'm building a Mac OS X Cocoa application from the command line using an Xcode project like this:

xcodebuild -scheme MyApp -configuration Debug

How do I run it once it's done building?


回答1:


I wrote a script to do this:

#!/bin/bash

x=$( xcodebuild -showBuildSettings -project MyApp.xcodeproj | grep ' BUILD_DIR =' | sed -e 's/.*= *//' )

DYLD_FRAMEWORK_PATH=$x/Debug DYLD_LIBRARY_PATH=$x/Debug $x/Debug/MyApp.app/Contents/MacOS/MyApp

(I figured this out by running the application from Xcode and then ps -wwE -p on the process to see its environment variables.)




回答2:


I've had the same question and the answer from a paid nerd was helpful.

After doing some research I did find a cleaner solution, which I will provide as an answer here. It's mainly the parsing code that is cleaner and made re-usable for retrieving other build settings as well.

#!/bin/bash

WORKSPACE_PATH='/Volumes/Development/MyApp/MyApp.xcworkspace'
CONFIGURATION='Debug'
SCHEME='macOS'

getBuildSetting() { 
    echo $(xcodebuild -showBuildSettings -workspace "$WORKSPACE_PATH" -scheme "$SCHEME" -configuration "$CONFIGURATION" | grep " $1" | awk '{print $3}' )
}

BUILT_PRODUCTS_DIR=$(getBuildSetting "BUILT_PRODUCTS_DIR")
FULL_PRODUCT_NAME=$(getBuildSetting "FULL_PRODUCT_NAME")
open -a "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME" &

Of course this approach makes use of a workspace instead of a project, though it can be easily changed. Also I've just used the open command to open the app.



来源:https://stackoverflow.com/questions/29632757/how-do-i-run-a-cocoa-app-after-building-it-from-the-command-line-with-xcodebuild

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