From 0822907d6d7452f2b7af093bc193d01b489478d7 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 26 Aug 2011 14:21:37 +0100 Subject: [PATCH] Some more sanity with ENV.compiler Deprecated use_clang? etc. since the logic was such that multiple states could be set, when in reality only one compiler can be set. Changed fails_with_llvm handling so if HOMEBREW_USE_LLVM is set then it tries to build even if the formula has fails_with_llvm set. Rationale: mostly they will no longer fail and we need to catch these cases. --- Library/Homebrew/extend/ENV.rb | 58 ++++++++++++++++++++++++++-------- Library/Homebrew/formula.rb | 25 ++++++--------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 019b8ae863..38852b817b 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -25,14 +25,10 @@ module HomebrewEnvExtension self['CC'] = '/usr/bin/cc' self['CXX'] = '/usr/bin/c++' - if MACOS_VERSION >= 10.6 - if self.use_clang? - self.clang - elsif self.use_llvm? - self.llvm - elsif self.use_gcc? - self.gcc - end + case self.compiler + when :clang then self.clang + when :llvm then self.llvm + when :gcc then self.gcc end # In rare cases this may break your builds, as the tool for some reason wants @@ -141,7 +137,9 @@ module HomebrewEnvExtension alias_method :gcc_4_2, :gcc def llvm - if MacOS.xcode_version < '4.1' + if MacOS.xcode_version < '4' + self.gcc + elsif MacOS.xcode_version < '4.1' self['CC'] = "#{MacOS.xcode_prefix}/usr/bin/llvm-gcc" self['CXX'] = "#{MacOS.xcode_prefix}/usr/bin/llvm-g++" else @@ -151,8 +149,12 @@ module HomebrewEnvExtension end def clang - self['CC'] = "#{MacOS.xcode_prefix}/usr/bin/clang" - self['CXX'] = "#{MacOS.xcode_prefix}/usr/bin/clang++" + if MacOS.xcode_version > '4' + self['CC'] = "#{MacOS.xcode_prefix}/usr/bin/clang" + self['CXX'] = "#{MacOS.xcode_prefix}/usr/bin/clang++" + else + self.gcc + end end def fortran @@ -310,14 +312,42 @@ Please take one of the following actions: remove 'CXXFLAGS', f end + def compiler + # TODO seems that ENV.clang in a Formula.install should warn when called + # if the user has set something that is tested here + + # test for --flags first so that installs can be overridden on a per + # install basis + if ARGV.include? '--use-gcc' + :gcc + elsif ARGV.include? '--use-llvm' + :llvm + elsif ARGV.include? '--use-clang' + :clang + end + + # test for ENVs in inverse order to flags, this is sensible, trust me + if self['HOMEBREW_USE_CLANG'] + :clang + elsif self['HOMEBREW_USE_LLVM'] + :llvm + elsif self['HOMEBREW_USE_GCC'] + :gcc + else + :gcc + end + end + + # don't use in new code + # don't remove though, but do add to compatibility.rb def use_clang? - self['HOMEBREW_USE_CLANG'] or ARGV.include? '--use-clang' + compiler == :clang end def use_gcc? - self['HOMEBREW_USE_GCC'] or ARGV.include? '--use-gcc' + compiler == :gcc end def use_llvm? - self['HOMEBREW_USE_LLVM'] or ARGV.include? '--use-llvm' + compiler == :llvm end def make_jobs diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 51e5dd397c..add8279799 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -296,23 +296,18 @@ class Formula end def handle_llvm_failure llvm - unless ENV.use_llvm? or ENV.use_clang? - ENV.gcc_4_2 if MacOS.default_cc =~ /llvm/ + case ENV.compiler + case :llvm, :clang + opoo "LLVM was requested, but this formula is reported to not work with LLVM:" + puts llvm.reason + puts + puts "We are continuing anyway so the build succeeds, please let us know so we can" + puts "update the formula. If it doesn't work you can: brew install --use-gcc" + puts + else + ENV.gcc if MacOS.default_cc =~ /llvm/ return end - - opoo "LLVM was requested, but this formula is reported as not working with LLVM:" - puts llvm.reason - - if ARGV.force? - puts "Continuing anyway.\n" + - "If this works, let us know so we can update the formula to remove the warning." - else - puts "Continuing with GCC 4.2 instead.\n"+ - "(Use `brew install --force #{name}` to force use of LLVM.)" - ENV.gcc_4_2 - end - puts end def self.class_s name