xcode 按版本查找Xcode安装路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5926232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find Xcode installation path by version
提问by tonklon
There are no standard paths to keep different copies of XCode (XCode3 and XCode4) on one system. For my Makefile or other commandline based build process, I am searching for a way to determine to installation path ($DEVELOPER_DIR) of XCode of a specific version, to export this path as DEVELOPER_DIR or use xcode-select to make it active.
没有标准路径可以在一个系统上保存不同的 XCode(XCode3 和 XCode4)副本。对于我的 Makefile 或其他基于命令行的构建过程,我正在寻找一种方法来确定特定版本的 XCode 的安装路径 ($DEVELOPER_DIR),将此路径导出为 DEVELOPER_DIR 或使用 xcode-select 使其处于活动状态。
So far I am trying to query system_profiler's xml output.
到目前为止,我正在尝试查询 system_profiler 的 xml 输出。
Are there any other (more convenient) options?
还有其他(更方便)的选择吗?
Basically I need a script to tell the system to use Xcode3 (or Xcode4) without knowing their installation paths.
基本上我需要一个脚本来告诉系统在不知道它们的安装路径的情况下使用 Xcode3(或 Xcode4)。
回答by tonklon
Here's what I have come up with so far:
到目前为止,这是我想出的:
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()"`
This sets DEVELOPER_DIR to the installation path of Xcode3. For Xcode4 just replace the '3' by '4'
这会将 DEVELOPER_DIR 设置为 Xcode3 的安装路径。对于 Xcode4,只需将 '3' 替换为 '4'
This will not work as expected when multiple versions of XCode3 are installed.
当安装了多个版本的 XCode3 时,这将无法正常工作。
回答by sakra
You can find out the installation paths of all installed Xcode versions from the command line by querying the Launch Services database with the lsregister
command.
您可以通过使用该lsregister
命令查询 Launch Services 数据库,从命令行中找出所有已安装 Xcode 版本的安装路径。
To find all Xcode3 installation paths, run:
要查找所有 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"
To find all Xcode4 installation paths, run:
要查找所有 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"
Also see this question.
另请参阅此问题。
回答by Leszek Szary
This will find Xcode with given version in Applications folder assuming its name starts with Xcode:
这将在 Applications 文件夹中找到具有给定版本的 Xcode,假设其名称以 Xcode 开头:
for xcode in ls /Applications/Xcode*; do
if grep -q -s -E "<string>\.[0-9.]+</string>" "$xcode/Contents/version.plist"; then
echo "$xcode/Contents/Developer\c"
break
fi
done
Save this as findxcode.sh and then launch like this: ./findxcode.sh 9
and it will print you the path of Xcode 9 which you can put into DEVELOPER_DIR. The \c
at the end is there to remove new line at the end if you need to capture the output with other script/fastlane or something.
将其另存为 findxcode.sh,然后像这样启动:./findxcode.sh 9
它会为您打印 Xcode 9 的路径,您可以将其放入 DEVELOPER_DIR。将\c
在年底有没有在年底消除新行,如果您需要捕获与其他脚本/ FASTLANE什么的输出。