Skip to content

Commit

Permalink
improve version fetching command performance by reading Xcode's versi…
Browse files Browse the repository at this point in the history
…on.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
  • Loading branch information
aomathwift authored Jun 15, 2021
1 parent 87a603c commit eeb8a07
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/xcode/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/installed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eeb8a07

Please sign in to comment.