按版本查找Xcode安装路径

时间:2011-05-08 07:34:09

标签: xcode command-line makefile installation-path

没有标准路径可以在一个系统上保留不同的XCode副本(XCode3和XCode4)。对于我的Makefile或其他基于命令行的构建过程,我正在寻找一种方法来确定特定版本的XCode的安装路径($ DEVELOPER_DIR),将此路径导出为DEVELOPER_DIR或使用xcode-select使其激活。

到目前为止,我正在尝试查询system_profiler的xml输出。

还有其他(更方便)的选择吗?

基本上我需要一个脚本来告诉系统使用Xcode3(或Xcode4)而不知道它们的安装路径。

3 个答案:

答案 0 :(得分:1)

这是我到目前为止所提出的:

DEVELOPER_DIR=`system_profiler SPDeveloperToolsDataType -xml |\
xpath "//*[text()='spdevtools_version']/following-sibling::string[starts-with(text(),'3')]/../*[text()='spdevtools_path']/following-sibling::string[1]/text()"`

这将DEVELOPER_DIR设置为Xcode3的安装路径。对于Xcode4,只需将'3'替换为'4'

安装多个版本的XCode3时,这将无法正常工作。

答案 1 :(得分:0)

您可以通过使用lsregister命令查询Launch Services数据库,从命令行找到所有已安装Xcode版本的安装路径。

要查找所有Xcode3安装路径,请运行:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister  -dump | grep --before-context=2 "com.apple.Xcode" | grep --only-matching "/.*\.app"

要查找所有Xcode4安装路径,请运行:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister  -dump | grep --before-context=2 "com.apple.dt.Xcode" | grep --only-matching "/.*\.app"

另见question

答案 2 :(得分:0)

假设名称以Xcode开头,它将在Applications文件夹中找到具有给定版本的Xcode:

for xcode in ls /Applications/Xcode*; do
  if grep -q -s -E "<string>$1\.[0-9.]+</string>" "$xcode/Contents/version.plist"; then
    echo "$xcode/Contents/Developer\c"
    break
  fi
done

将其另存为findxcode.sh,然后像这样启动:./findxcode.sh 9,它将打印Xcode 9的路径,您可以将其放入DEVELOPER_DIR。如果需要使用其他脚本/快速通道或其他内容捕获输出,则末尾的\c会在末尾删除新行。

相关问题