Skip to content

Commit eeb8a07

Browse files
authored
improve version fetching command performance by reading Xcode's version.plist instead of using the xcodebuild command (#427)
* Use the version.plist instead of the xcodebuild command to detect Xcode version in fetch_version * Update spec
1 parent 87a603c commit eeb8a07

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

lib/xcode/install.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,10 @@ def install_components
710710
`touch #{cache_dir}com.apple.dt.Xcode.InstallCheckCache_#{osx_build_version}_#{tools_version}`
711711
end
712712

713-
# This method might take a few ms, this could be improved by implementing https://github.com/KrauseFx/xcode-install/issues/273
714713
def fetch_version
715-
output = `DEVELOPER_DIR='' "#{@path}/Contents/Developer/usr/bin/xcodebuild" -version`
714+
output = `/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "#{@path}/Contents/version.plist"`
716715
return '0.0' if output.nil? || output.empty? # ¯\_(ツ)_/¯
717-
output.split("\n").first.split(' ')[1]
716+
output.sub("\n", '')
718717
end
719718

720719
def verify_integrity

spec/installed_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module XcodeInstall
55

66
describe InstalledXcode do
77
it 'finds the current Xcode version with whitespace chars' do
8-
InstalledXcode.any_instance.expects(:`).with("DEVELOPER_DIR='' \"#{xcode_path}/Contents/Developer/usr/bin/xcodebuild\" -version").returns("Xcode 6.3.1\nBuild version 6D1002")
8+
InstalledXcode.any_instance.expects(:`).with("/usr/libexec/PlistBuddy -c \"Print :CFBundleShortVersionString\" \"#{xcode_path}/Contents/version.plist\"").returns('6.3.1')
99
installed = InstalledXcode.new(xcode_path)
1010
installed.version.should == '6.3.1'
1111
end
1212

1313
it 'is robust against broken Xcode installations' do
14-
InstalledXcode.any_instance.expects(:`).with("DEVELOPER_DIR='' \"#{xcode_path}/Contents/Developer/usr/bin/xcodebuild\" -version").returns(nil)
14+
InstalledXcode.any_instance.expects(:`).with("/usr/libexec/PlistBuddy -c \"Print :CFBundleShortVersionString\" \"#{xcode_path}/Contents/version.plist\"").returns(nil)
1515
installed = InstalledXcode.new(xcode_path)
1616
installed.version.should == '0.0'
1717
end

0 commit comments

Comments
 (0)