Refactor Xcode/CLT version checks

This commit is contained in:
Jack Nagel 2013-05-22 22:26:09 -05:00
parent b2ff6e934b
commit 3755b33a97
3 changed files with 40 additions and 30 deletions

View File

@ -215,33 +215,38 @@ def check_for_broken_symlinks
end end
end end
def check_for_latest_xcode def check_xcode_clt
if not MacOS::Xcode.installed? if MacOS::Xcode.installed?
if MacOS.version >= 10.7 __check_xcode_up_to_date
if not MacOS::CLT.installed? elsif MacOS.version >= 10.7
<<-EOS.undent __check_clt_up_to_date
No developer tools installed else <<-EOS.undent
You should install the Command Line Tools: http://connect.apple.com Xcode not installed
EOS Most stuff needs Xcode to build: http://developer.apple.com/xcode/
elsif not MacOS::CLT.latest_version? EOS
<<-EOS.undent end
A newer Command Line Tools for Xcode release is available end
You should install the latest version from: http://connect.apple.com
EOS def __check_xcode_up_to_date
end if MacOS::Xcode.outdated? then <<-EOS.undent
else
<<-EOS.undent
Xcode not installed
Most stuff needs Xcode to build: http://developer.apple.com/xcode/
EOS
end
elsif MacOS::Xcode.version < MacOS::Xcode.latest_version then <<-EOS.undent
Your Xcode (#{MacOS::Xcode.version}) is outdated Your Xcode (#{MacOS::Xcode.version}) is outdated
Please install Xcode #{MacOS::Xcode.latest_version}. Please install Xcode #{MacOS::Xcode.latest_version}.
EOS EOS
end end
end end
def __check_clt_up_to_date
if not MacOS::CLT.installed? then <<-EOS.undent
No developer tools installed
You should install the Command Line Tools: http://connect.apple.com
EOS
elsif MacOS::CLT.outdated? then <<-EOS.undent
A newer Command Line Tools for Xcode release is available
You should install the latest version from: http://connect.apple.com
EOS
end
end
def check_for_stray_developer_directory def check_for_stray_developer_directory
# if the uninstaller script isn't there, it's a good guess neither are # if the uninstaller script isn't there, it's a good guess neither are
# any troublesome leftover Xcode files # any troublesome leftover Xcode files
@ -271,7 +276,7 @@ def check_cc
end end
def check_standard_compilers def check_standard_compilers
return if check_for_latest_xcode # only check if Xcode is up to date return if check_xcode_clt # only check if Xcode is up to date
compiler_status = MacOS.compilers_standard? compiler_status = MacOS.compilers_standard?
if not compiler_status and not compiler_status.nil? then <<-EOS.undent if not compiler_status and not compiler_status.nil? then <<-EOS.undent
Your compilers are different from the standard versions for your Xcode. Your compilers are different from the standard versions for your Xcode.

View File

@ -42,7 +42,7 @@ module Homebrew extend self
def check_xcode def check_xcode
require 'cmd/doctor' require 'cmd/doctor'
checks = Checks.new checks = Checks.new
%w{check_for_latest_xcode check_xcode_license_approved}.each do |check| %w{check_xcode_clt check_xcode_license_approved}.each do |check|
out = checks.send(check) out = checks.send(check)
opoo out unless out.nil? opoo out unless out.nil?
end end

View File

@ -19,17 +19,18 @@ module MacOS::Xcode extend self
def latest_version def latest_version
case MacOS.version case MacOS.version
when 10.5 then "3.1.4" when 10.5 then "3.1.4"
when 10.6 then "3.2.6" when 10.6 then "3.2.6"
when 10.7..10.8 then "4.6.2"
else else
if MacOS.version >= 10.7 raise "Mac OS X '#{MacOS.version}' is invalid"
"4.6.2"
else
raise "Mac OS X `#{MacOS.version}' is invalid"
end
end end
end end
def outdated?
version < latest_version
end
def prefix def prefix
@prefix ||= begin @prefix ||= begin
path = Pathname.new(folder) path = Pathname.new(folder)
@ -158,6 +159,10 @@ module MacOS::CLT extend self
$1.to_i >= 425 and $3.to_i >= 28 $1.to_i >= 425 and $3.to_i >= 28
end end
def outdated?
!latest_version?
end
def version def version
# The pkgutils calls are slow, don't repeat if no CLT installed. # The pkgutils calls are slow, don't repeat if no CLT installed.
return @version if @version_determined return @version if @version_determined