From 5ce1caa1f3679244ed120e3f091001c5afabcf74 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Fri, 14 Sep 2012 13:24:28 -0500 Subject: [PATCH] Improve Xcode and CLT config reporting We support three configurations: Xcode-only, CLT-only, and Xcode with CLT. Our configuration output should correctly reflect this. While MacOS::Xcode.version has to continue to return a guess if Xcode is not installed in order to maintain backwards compatibility, this is an implementation detail that we don't need to expose to the user. And it makes `brew --config` output confusing. So let's only print the "Xcode" line when an actual Xcode installation is present. This makes it easy to quickly figure out which of the three possible configurations the user is running. Addresses Homebrew/homebrew#14941, more or less. --- Library/Homebrew/cmd/--config.rb | 42 ++++++++++++++------------------ Library/Homebrew/macos/xcode.rb | 8 ++++++ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Library/Homebrew/cmd/--config.rb b/Library/Homebrew/cmd/--config.rb index 1781d33a76..342d837f0c 100644 --- a/Library/Homebrew/cmd/--config.rb +++ b/Library/Homebrew/cmd/--config.rb @@ -29,24 +29,22 @@ module Homebrew extend self @clang_build ||= MacOS.clang_build_version end - def describe_xcode - @describe_xcode ||= begin - default_prefix = case MacOS.version - when 10.5, 10.6 then '/Developer' - else '/Applications/Xcode.app/Contents/Developer' - end - - guess = '(guessed)' unless MacOS::Xcode.installed? - prefix = if MacOS::Xcode.installed? - "=> #{MacOS::Xcode.prefix}" unless MacOS::Xcode.prefix.to_s == default_prefix - end - - [MacOS::Xcode.version, guess, prefix].compact.join(' ') + def xcode + if instance_variable_defined?(:@xcode) + @xcode + elsif MacOS::Xcode.installed? + @xcode = MacOS::Xcode.version + @xcode += " => #{MacOS::Xcode.prefix}" unless MacOS::Xcode.default_prefix? + @xcode end end - def describe_clt - @describe_clt ||= if MacOS::CLT.installed? then MacOS::CLT.version else 'N/A' end + def clt + if instance_variable_defined?(:@clt) + @clt + elsif MacOS::CLT.installed? && MacOS::Xcode.version.to_f >= 4.3 + @clt = MacOS::CLT.version + end end def head @@ -95,8 +93,8 @@ module Homebrew extend self puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}" if HOMEBREW_CELLAR.to_s != "#{HOMEBREW_PREFIX}/Cellar" puts hardware puts "OS X: #{MACOS_FULL_VERSION}-#{kernel}" - puts "Xcode: #{describe_xcode}" - puts "CLT: #{describe_clt}" if MacOS::Xcode.version.to_f >= 4.3 + puts "Xcode: #{xcode}" if xcode + puts "CLT: #{clt}" if clt puts "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby:\n #{RUBY_VERSION}-#{RUBY_PATCHLEVEL}" if RUBY_VERSION.to_f != 1.8 unless MacOS.compilers_standard? @@ -127,8 +125,8 @@ module Homebrew extend self puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}" puts hardware puts "OS X: #{MACOS_FULL_VERSION}-#{kernel}" - puts "Xcode: #{describe_xcode}" - puts "CLT: #{describe_clt}\n" if MacOS::Xcode.version.to_f >= 4.3 + puts "Xcode: #{xcode}" if xcode + puts "CLT: #{clt}" if clt puts "GCC-4.0: build #{gcc_40}" if gcc_40 puts "GCC-4.2: build #{gcc_42}" if gcc_42 puts "LLVM-GCC: #{llvm ? "build #{llvm}" : "N/A"}" @@ -147,11 +145,7 @@ module Homebrew extend self print MACOS_FULL_VERSION print "-#{kernel}" if MacOS.version < :lion print ' ' - if MacOS::Xcode.version > "4.3" - print MacOS::Xcode.prefix unless MacOS::Xcode.prefix.to_s =~ %r{^/Applications/Xcode.app} - else - print MacOS::Xcode.prefix unless MacOS::Xcode.prefix.to_s =~ %r{^/Developer} - end + print MacOS::Xcode.prefix unless MacOS::Xcode.default_prefix? print "#{MacOS::Xcode.version}" print "-noclt" unless MacOS::CLT.installed? print " clang-#{clang_build} llvm-#{llvm} " diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/macos/xcode.rb index 3640f1a684..ab297f2c5c 100644 --- a/Library/Homebrew/macos/xcode.rb +++ b/Library/Homebrew/macos/xcode.rb @@ -147,6 +147,14 @@ module MacOS::Xcode extend self def provides_gcc? version.to_f < 4.3 end + + def default_prefix? + if version.to_f < 4.3 + %r{^/Developer} === prefix + else + %r{^/Applications/Xcode.app} === prefix + end + end end module MacOS::CLT extend self