开发者

Find Xcode installation path by version

开发者 https://www.devze.com 2023-03-04 06:36 出处:网络
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 determi开发者_Pyt

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 determi开发者_Python百科ne 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.

So far I am trying to query system_profiler's xml output.

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.


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'

This will not work as expected when multiple versions of XCode3 are installed.


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.

To find all Xcode3 installation paths, run:

/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:

/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.


This will find Xcode with given version in Applications folder assuming its name starts with 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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消