diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 6b40a30..0eefb97 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -710,11 +710,10 @@ def install_components `touch #{cache_dir}com.apple.dt.Xcode.InstallCheckCache_#{osx_build_version}_#{tools_version}` end - # This method might take a few ms, this could be improved by implementing https://github.com/KrauseFx/xcode-install/issues/273 def fetch_version - output = `DEVELOPER_DIR='' "#{@path}/Contents/Developer/usr/bin/xcodebuild" -version` + output = `/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "#{@path}/Contents/version.plist"` return '0.0' if output.nil? || output.empty? # ¯\_(ツ)_/¯ - output.split("\n").first.split(' ')[1] + output.sub("\n", '') end def verify_integrity diff --git a/spec/installed_spec.rb b/spec/installed_spec.rb index 1c02afd..3b6d442 100644 --- a/spec/installed_spec.rb +++ b/spec/installed_spec.rb @@ -5,13 +5,13 @@ module XcodeInstall describe InstalledXcode do it 'finds the current Xcode version with whitespace chars' do - InstalledXcode.any_instance.expects(:`).with("DEVELOPER_DIR='' \"#{xcode_path}/Contents/Developer/usr/bin/xcodebuild\" -version").returns("Xcode 6.3.1\nBuild version 6D1002") + InstalledXcode.any_instance.expects(:`).with("/usr/libexec/PlistBuddy -c \"Print :CFBundleShortVersionString\" \"#{xcode_path}/Contents/version.plist\"").returns('6.3.1') installed = InstalledXcode.new(xcode_path) installed.version.should == '6.3.1' end it 'is robust against broken Xcode installations' do - InstalledXcode.any_instance.expects(:`).with("DEVELOPER_DIR='' \"#{xcode_path}/Contents/Developer/usr/bin/xcodebuild\" -version").returns(nil) + InstalledXcode.any_instance.expects(:`).with("/usr/libexec/PlistBuddy -c \"Print :CFBundleShortVersionString\" \"#{xcode_path}/Contents/version.plist\"").returns(nil) installed = InstalledXcode.new(xcode_path) installed.version.should == '0.0' end