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.
This commit is contained in:
parent
71268b7f16
commit
ef1d9c0cd0
@ -2,16 +2,28 @@ class Compiler < Struct.new(:name, :priority)
|
|||||||
def build
|
def build
|
||||||
MacOS.send("#{name}_build_version")
|
MacOS.send("#{name}_build_version")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def version
|
||||||
|
MacOS.non_apple_gcc_version(name) if name.is_a? String
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class CompilerFailure
|
class CompilerFailure
|
||||||
attr_reader :compiler
|
attr_reader :compiler, :version
|
||||||
attr_rw :build, :cause
|
attr_rw :build, :cause
|
||||||
|
|
||||||
def initialize compiler, &block
|
def initialize compiler, &block
|
||||||
|
# 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
|
@compiler = compiler
|
||||||
|
end
|
||||||
|
|
||||||
instance_eval(&block) if block_given?
|
instance_eval(&block) if block_given?
|
||||||
@build = (@build || 9999).to_i
|
@build = (@build || 9999).to_i unless compiler.is_a? Hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -43,6 +55,14 @@ class CompilerSelector
|
|||||||
@compilers << Compiler.new(cc, priority_for(cc))
|
@compilers << Compiler.new(cc, priority_for(cc))
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
# Attempts to select an appropriate alternate compiler, but
|
# Attempts to select an appropriate alternate compiler, but
|
||||||
@ -64,9 +84,11 @@ class CompilerSelector
|
|||||||
def priority_for(cc)
|
def priority_for(cc)
|
||||||
case cc
|
case cc
|
||||||
when :clang then MacOS.clang_build_version >= 318 ? 3 : 0.5
|
when :clang then MacOS.clang_build_version >= 318 ? 3 : 0.5
|
||||||
when :llvm then 2
|
when :gcc then 2
|
||||||
when :gcc then 1
|
when :llvm then 1
|
||||||
when :gcc_4_0 then 0.25
|
when :gcc_4_0 then 0.25
|
||||||
|
# non-Apple gcc compilers
|
||||||
|
else 1.5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -167,6 +167,16 @@ module Stdenv
|
|||||||
end
|
end
|
||||||
alias_method :gcc_4_2, :gcc
|
alias_method :gcc_4_2, :gcc
|
||||||
|
|
||||||
|
GNU_GCC_VERSIONS.each do |n|
|
||||||
|
define_method(:"gcc-4.#{n}") do
|
||||||
|
gcc = "gcc-4.#{n}"
|
||||||
|
self.cc = self['OBJC'] = gcc
|
||||||
|
self.cxx = self['OBJCXX'] = gcc.gsub('c', '+')
|
||||||
|
set_cpu_cflags
|
||||||
|
@compiler = gcc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def llvm
|
def llvm
|
||||||
self.cc = MacOS.locate("llvm-gcc")
|
self.cc = MacOS.locate("llvm-gcc")
|
||||||
self.cxx = MacOS.locate("llvm-g++")
|
self.cxx = MacOS.locate("llvm-g++")
|
||||||
|
|||||||
@ -266,6 +266,13 @@ module Superenv
|
|||||||
self.cc = self['HOMEBREW_CC'] = "clang"
|
self.cc = self['HOMEBREW_CC'] = "clang"
|
||||||
self.cxx = "clang++"
|
self.cxx = "clang++"
|
||||||
end
|
end
|
||||||
|
GNU_GCC_VERSIONS.each do |n|
|
||||||
|
define_method(:"gcc-4.#{n}") do
|
||||||
|
gcc = "gcc-4.#{n}"
|
||||||
|
self.cc = self['HOMEBREW_CC'] = gcc
|
||||||
|
self.cxx = gcc.gsub('c', '+')
|
||||||
|
end
|
||||||
|
end
|
||||||
def make_jobs
|
def make_jobs
|
||||||
self['MAKEFLAGS'] =~ /-\w*j(\d)+/
|
self['MAKEFLAGS'] =~ /-\w*j(\d)+/
|
||||||
[$1.to_i, 1].max
|
[$1.to_i, 1].max
|
||||||
|
|||||||
@ -212,9 +212,14 @@ class Formula
|
|||||||
def fails_with? cc
|
def fails_with? cc
|
||||||
cc = Compiler.new(cc) unless cc.is_a? Compiler
|
cc = Compiler.new(cc) unless cc.is_a? Compiler
|
||||||
(self.class.cc_failures || []).any? do |failure|
|
(self.class.cc_failures || []).any? do |failure|
|
||||||
|
if cc.version
|
||||||
|
# non-Apple GCCs don't have builds, just version numbers
|
||||||
|
failure.compiler == cc.name && failure.version >= cc.version
|
||||||
|
else
|
||||||
failure.compiler == cc.name && failure.build >= cc.build
|
failure.compiler == cc.name && failure.build >= cc.build
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# sometimes the clean process breaks things
|
# sometimes the clean process breaks things
|
||||||
# skip cleaning paths in a formula with a class method like this:
|
# skip cleaning paths in a formula with a class method like this:
|
||||||
|
|||||||
@ -151,6 +151,16 @@ module MacOS extend self
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def non_apple_gcc_version(cc)
|
||||||
|
return unless path = locate(cc)
|
||||||
|
|
||||||
|
ivar = "@#{cc.gsub(/(-|\.)/, '')}_version"
|
||||||
|
return instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
||||||
|
|
||||||
|
`#{path} --version` =~ /gcc-\d.\d \(GCC\) (\d\.\d\.\d)/
|
||||||
|
instance_variable_set(ivar, $1)
|
||||||
|
end
|
||||||
|
|
||||||
# See these issues for some history:
|
# See these issues for some history:
|
||||||
# http://github.com/mxcl/homebrew/issues/#issue/13
|
# http://github.com/mxcl/homebrew/issues/#issue/13
|
||||||
# http://github.com/mxcl/homebrew/issues/#issue/41
|
# http://github.com/mxcl/homebrew/issues/#issue/41
|
||||||
|
|||||||
@ -22,16 +22,29 @@ class CompilerSelectorTests < Test::Unit::TestCase
|
|||||||
MacOS.stubs(:gcc_build_version).returns(5666)
|
MacOS.stubs(:gcc_build_version).returns(5666)
|
||||||
MacOS.stubs(:llvm_build_version).returns(2336)
|
MacOS.stubs(:llvm_build_version).returns(2336)
|
||||||
MacOS.stubs(:clang_build_version).returns(425)
|
MacOS.stubs(:clang_build_version).returns(425)
|
||||||
|
# Yes, this is ugly - we only want one GCC version to be available.
|
||||||
|
MacOS.send(:alias_method, :old_non_apple_gcc_version, :non_apple_gcc_version)
|
||||||
|
MacOS.send(:define_method, :non_apple_gcc_version) do |name|
|
||||||
|
if name == 'gcc-4.8'
|
||||||
|
'4.8.1'
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
@f = Double.new
|
@f = Double.new
|
||||||
@cc = :clang
|
@cc = :clang
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
MacOS.send(:alias_method, :non_apple_gcc_version, :old_non_apple_gcc_version)
|
||||||
|
end
|
||||||
|
|
||||||
def actual_cc
|
def actual_cc
|
||||||
CompilerSelector.new(@f).compiler
|
CompilerSelector.new(@f).compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_all_compiler_failures
|
def test_all_compiler_failures
|
||||||
@f << :clang << :llvm << :gcc
|
@f << :clang << :llvm << :gcc << 'gcc-4.8'
|
||||||
assert_raise(CompilerSelectionError) { actual_cc }
|
assert_raise(CompilerSelectionError) { actual_cc }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,7 +54,7 @@ class CompilerSelectorTests < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_fails_with_clang
|
def test_fails_with_clang
|
||||||
@f << :clang
|
@f << :clang
|
||||||
assert_equal :llvm, actual_cc
|
assert_equal :gcc, actual_cc
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fails_with_llvm
|
def test_fails_with_llvm
|
||||||
@ -54,13 +67,18 @@ class CompilerSelectorTests < Test::Unit::TestCase
|
|||||||
assert_equal :clang, actual_cc
|
assert_equal :clang, actual_cc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_fails_with_non_apple_gcc
|
||||||
|
@f << "gcc-4.8"
|
||||||
|
assert_equal :clang, actual_cc
|
||||||
|
end
|
||||||
|
|
||||||
def test_mixed_failures_1
|
def test_mixed_failures_1
|
||||||
@f << :clang << :llvm
|
@f << :clang << :llvm
|
||||||
assert_equal :gcc, actual_cc
|
assert_equal :gcc, actual_cc
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mixed_failures_2
|
def test_mixed_failures_2
|
||||||
@f << :gcc << :clang
|
@f << :gcc << :clang << 'gcc-4.8'
|
||||||
assert_equal :llvm, actual_cc
|
assert_equal :llvm, actual_cc
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -69,22 +87,32 @@ class CompilerSelectorTests < Test::Unit::TestCase
|
|||||||
assert_equal :clang, actual_cc
|
assert_equal :clang, actual_cc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_mixed_failures_4
|
||||||
|
@f << :clang << "gcc-4.8"
|
||||||
|
assert_equal :gcc, actual_cc
|
||||||
|
end
|
||||||
|
|
||||||
def test_older_clang_precedence
|
def test_older_clang_precedence
|
||||||
MacOS.stubs(:clang_build_version).returns(211)
|
MacOS.stubs(:clang_build_version).returns(211)
|
||||||
@f << :gcc
|
@f << :gcc << 'gcc-4.8'
|
||||||
assert_equal :llvm, actual_cc
|
assert_equal :llvm, actual_cc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_non_apple_gcc_precedence
|
||||||
|
@f << :clang << :gcc
|
||||||
|
assert_equal 'gcc-4.8', actual_cc
|
||||||
|
end
|
||||||
|
|
||||||
def test_missing_gcc
|
def test_missing_gcc
|
||||||
MacOS.stubs(:gcc_build_version).returns(nil)
|
MacOS.stubs(:gcc_build_version).returns(nil)
|
||||||
@f << :clang << :llvm
|
@f << :clang << :llvm << 'gcc-4.8'
|
||||||
assert_raise(CompilerSelectionError) { actual_cc }
|
assert_raise(CompilerSelectionError) { actual_cc }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_missing_llvm_and_gcc
|
def test_missing_llvm_and_gcc
|
||||||
MacOS.stubs(:gcc_build_version).returns(nil)
|
MacOS.stubs(:gcc_build_version).returns(nil)
|
||||||
MacOS.stubs(:llvm_build_version).returns(nil)
|
MacOS.stubs(:llvm_build_version).returns(nil)
|
||||||
@f << :clang
|
@f << :clang << 'gcc-4.8'
|
||||||
assert_raise(CompilerSelectionError) { actual_cc }
|
assert_raise(CompilerSelectionError) { actual_cc }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'test/testball'
|
|||||||
|
|
||||||
class FailsWithTests < Test::Unit::TestCase
|
class FailsWithTests < Test::Unit::TestCase
|
||||||
class Double < Compiler
|
class Double < Compiler
|
||||||
attr_accessor :name, :build
|
attr_accessor :name, :build, :version
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_fails_with(cc)
|
def assert_fails_with(cc)
|
||||||
@ -18,10 +18,11 @@ class FailsWithTests < Test::Unit::TestCase
|
|||||||
@f.send(:fails_with, *args, &block)
|
@f.send(:fails_with, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_cc(sym, build)
|
def build_cc(sym, build, version=nil)
|
||||||
cc = Double.new
|
cc = Double.new
|
||||||
cc.name = sym
|
cc.name = sym
|
||||||
cc.build = build
|
cc.build = build
|
||||||
|
cc.version = version
|
||||||
cc
|
cc
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,6 +48,12 @@ class FailsWithTests < Test::Unit::TestCase
|
|||||||
assert_fails_with cc
|
assert_fails_with cc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_non_apple_gcc_version
|
||||||
|
fails_with(:gcc => '4.8.2')
|
||||||
|
cc = build_cc("gcc-4.8", nil, "4.8.1")
|
||||||
|
assert_fails_with cc
|
||||||
|
end
|
||||||
|
|
||||||
def test_multiple_failures
|
def test_multiple_failures
|
||||||
fails_with(:llvm)
|
fails_with(:llvm)
|
||||||
fails_with(:clang)
|
fails_with(:clang)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user