我正在尝试构建一个xcode项目并通过iPhone模拟器通过AppleScript运行它。我知道 xcodebuild 但它不允许你在模拟器中运行应用程序。我已经非常接近下面的剧本......
tell application "Xcode"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "iphonesimulator3.0"
end tell
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
end if
end tell
...但是build命令似乎没有服从活动SDK 属性,它总是默认为项目的基本SDK设置(例如iPhoneOS3.0而不是iPhonesimulator3.0)
有没有办法告诉build命令使用特定的SDK?我在雪豹上使用xcode 3.2。
答案 0 :(得分:12)
这是诀窍......您必须设置SDKROOT构建设置。这是一个zsh脚本,用于在当前层次结构中查找xcode项目,构建它,并通过xcode运行它。
#!/bin/zsh
BUILD_PATH=$(dirname $0)
while [[ -z $BUILD_FILE && $BUILD_PATH != "/" ]]; do
BUILD_FILE=$(find $BUILD_PATH -name '*.xcodeproj' -maxdepth 1)
BUILD_PATH=$(dirname $BUILD_PATH)
done
if [[ -z $BUILD_FILE ]]; then
echo "Couldn't find an xcode project file in directory"
exit 1
fi
# Applescript likes's : instead of / (because it's insane)
BUILD_FILE=${BUILD_FILE//\//:}
# Find the latest Simulator SDK
SIMULATOR_SDKS=( /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/*.sdk )
SIMULATOR_SDK=${SIMULATOR_SDKS[-1]}
SIMULATOR_SDK_STRING=$(basename ${(L)SIMULATOR_SDK%.[a-z]*})
if [[ -z $SIMULATOR_SDK ]]; then
echo "Couldn't find a simulator SDK"
exit 1
fi
osascript <<SCRIPT
application "iPhone Simulator" quit
application "iPhone Simulator" activate
tell application "Xcode"
open "$BUILD_FILE"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "$SIMULATOR_SDK_STRING"
set value of build setting "SDKROOT" of build configuration "Debug" of active target to "$SIMULATOR_SDK"
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
else
application "iPhone Simulator" quit
end if
end tell
end tell
SCRIPT
答案 1 :(得分:3)
要考虑的另一个选择是使用Applescript启动执行xcodebuild
程序的shell脚本。 xcodebuild
允许您指定特定目标,配置,sdk等内容。当我必须SSH到构建服务器并重建项目时,我会一直使用它。
答案 2 :(得分:2)
iphonesim项目为您提供了iPhone模拟器的命令行启动器。
答案 3 :(得分:1)
如果set active SDK
命令无法按预期工作,则解决方法是创建另一个名为“Debug-Simulator”的构建配置(在项目设置中的Xcode中),并在新的中设置基本SDK配置到iphonesimulator3.0。这将允许您通过选择构建配置(如果在AppleScript中有效)来选择SDK。