From 733076ec22a21bcc481afc38fc79fd0ea40700a0 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Fri, 28 Jun 2013 01:38:09 -0500 Subject: Implement fails_with for non-Apple compilers This adds support for non-Apple GCC compilers in the fails_with code. A fails_with block for a non-Apple compiler looks like: fails_with :gcc => '4.8.1' do cause 'Foo' end Non-Apple compilers don't have build numbers, so compiler failures are based on version strings instead. Internally non-Apple compilers can be distinguished because they are passed around as strings instead of symbols. In addition, this alters the priority list for compilers, with the following changes: * Apple GCC 4.2 and LLVM-GCC swap positions, with GCC now taking priority. (Maybe LLVM-GCC should just go away.) * Non-Apple GCC compilers are ranked below GCC 4.2 but above LLVM-GCC and Apple GCC 4.0. --- Library/Homebrew/compilers.rb | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'Library/Homebrew/compilers.rb') diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index 3aaaecbc8..8eb6d56fb 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -2,16 +2,28 @@ class Compiler < Struct.new(:name, :priority) def build MacOS.send("#{name}_build_version") end + + def version + MacOS.non_apple_gcc_version(name) if name.is_a? String + end end class CompilerFailure - attr_reader :compiler + attr_reader :compiler, :version attr_rw :build, :cause def initialize compiler, &block - @compiler = compiler + # Non-Apple compilers are in the format fails_with compiler => version + if compiler.is_a? Hash + # currently the only compiler for this case is GCC + _, @version = compiler.shift + @compiler = 'gcc-' + @version.match(/(\d\.\d)/)[0] + else + @compiler = compiler + end + instance_eval(&block) if block_given? - @build = (@build || 9999).to_i + @build = (@build || 9999).to_i unless compiler.is_a? Hash end end @@ -43,6 +55,14 @@ class CompilerSelector @compilers << Compiler.new(cc, priority_for(cc)) end end + + # non-Apple GCC 4.x + SharedEnvExtension::GNU_GCC_VERSIONS.each do |v| + unless MacOS.non_apple_gcc_version("gcc-4.#{v}").nil? + # priority is based on version, with newest preferred first + @compilers << Compiler.new("gcc-4.#{v}", 1.0 + v/10.0) + end + end end # Attempts to select an appropriate alternate compiler, but @@ -64,9 +84,11 @@ class CompilerSelector def priority_for(cc) case cc when :clang then MacOS.clang_build_version >= 318 ? 3 : 0.5 - when :llvm then 2 - when :gcc then 1 + when :gcc then 2 + when :llvm then 1 when :gcc_4_0 then 0.25 + # non-Apple gcc compilers + else 1.5 end end end -- cgit v1.2.3