From 8b986f77f94d597e1d808c9c8ed53b3b61ae022d Mon Sep 17 00:00:00 2001 From: aomathwift Date: Wed, 21 Apr 2021 22:58:59 +0900 Subject: [PATCH 1/2] Use the version.plist instead of the xcodebuild command to detect Xcode version in fetch_version --- lib/xcode/install.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index c54dbb8..7bbbef6 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -706,11 +706,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 From 9f68f5819136f3f7e5efc755912e4fad6710b793 Mon Sep 17 00:00:00 2001 From: aomathwift Date: Wed, 21 Apr 2021 23:22:04 +0900 Subject: [PATCH 2/2] Update spec --- lib/xcode/install.rb | 2 +- spec/installed_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 7bbbef6..f0e53f9 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -709,7 +709,7 @@ def install_components def fetch_version output = `/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "#{@path}/Contents/version.plist"` return '0.0' if output.nil? || output.empty? # ¯\_(ツ)_/¯ - output.sub("\n", "") + 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