From d579dbb4cadefb732a907fdda97d400a0cef2f2d Mon Sep 17 00:00:00 2001 From: Martin Afanasjew Date: Wed, 4 May 2016 20:44:19 +0200 Subject: [PATCH] xcode: avoid invoking 'xcodebuild -version' twice This primarily benefits CLT-only systems where invoking the `xcodebuild` wrapper in `/usr/bin` will fail (twice) with the following message: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance Closes #198. Signed-off-by: Martin Afanasjew --- Library/Homebrew/os/mac/xcode.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index f85cea9f5c..fc27626557 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -81,14 +81,19 @@ module OS return nil if !MacOS::Xcode.installed? && !MacOS::CLT.installed? - %W[#{prefix}/usr/bin/xcodebuild #{which("xcodebuild")}].uniq.each do |path| - if File.file? path - Utils.popen_read(path, "-version") =~ /Xcode (\d(\.\d)*)/ - return $1 if $1 + %W[ + #{prefix}/usr/bin/xcodebuild + #{which("xcodebuild")} + ].uniq.each do |xcodebuild_path| + if File.executable? xcodebuild_path + xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version") + next unless $?.success? + + xcode_version = xcodebuild_output[/Xcode (\d(\.\d)*)/, 1] + return xcode_version if xcode_version # Xcode 2.x's xcodebuild has a different version string - Utils.popen_read(path, "-version") =~ /DevToolsCore-(\d+\.\d)/ - case $1 + case xcodebuild_output[/DevToolsCore-(\d+\.\d)/, 1] when "515.0" then return "2.0" when "798.0" then return "2.5" end