通过 AppleScript 构建并运行 xcode 项目

发布于 2024-08-06 19:13:26 字数 652 浏览 4 评论 0 原文

我正在尝试构建一个 xcode 项目并通过 applescript 通过 iPhone 模拟器运行它。我知道 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

...但是构建命令似乎不遵守 active SDK 属性,它始终默认为项目的基本 SDK 设置(例如iPhoneOS3.0 而不是 iPhonesimulator3.0)

有没有办法告诉构建命令使用特定的 SDK?我在雪豹上使用 xcode 3.2。

I'm trying to build an xcode project and run it through the iPhone Simulator via applescript. I'm aware of xcodebuild but it doesn't let you run the app in the simulator. I've gotten pretty close with the script below...

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

... but the build command doesn't seem to obey the active SDK property, it always defaults to the project's base SDK setting (such as the iPhoneOS3.0 instead of iPhonesimulator3.0)

Is there a way to tell the build command to use a specific SDK? I'm using xcode 3.2 on snow leopard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

场罚期间 2024-08-13 19:13:26

这是技巧...您必须设置 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

Here is the trick... you have to set the SDKROOT build setting. Here is a zsh script I use to find the xcode project within the current hierarchy, build it, and run it via 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
拥醉 2024-08-13 19:13:26

另一个需要考虑的选择是使用 Applescript 启动一个执行 xcodebuild 程序。 xcodebuild 允许您指定特定目标、配置、sdk 等内容。当我必须通过 SSH 连接到构建服务器并重建项目时,我总是使用它。

Another option to consider is to use Applescript to launch a shell script that executes the xcodebuild program. xcodebuild allows you to specify things like a specific target, configuration, sdk, etc. I use this all the time when I have to SSH into a build server and rebuild a project.

两相知 2024-08-13 19:13:26

iphonesim 项目为您提供了 iPhone 模拟器的命令行启动器。

The iphonesim project gives you a command-line launcher for the iPhone simulator.

雪落纷纷 2024-08-13 19:13:26

如果 set active SDK 命令未按预期工作,解决方法是创建另一个名为“Debug-Simulator”的构建配置(在 Xcode 的项目设置中),并在iphonesimulator3.0的新配置。这将允许您通过选择构建配置来选择 SDK(如果适用于 AppleScript)。

If the set active SDK command does not work as expected, a workaround would be to create another build configuration named "Debug-Simulator" (in Xcode in the project settings), and to set the base SDK in the new configuration to iphonesimulator3.0. This would allow you to select the SDK by selecting the build configuration (if that works in AppleScript).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文