CompilerSelector: raise when no compatible compiler
This replaces the old behaviour of falling back to the original compiler with no messaging. Fixes Homebrew/homebrew#19170. Fixes mistydemeo/tigerbrew#45.
This commit is contained in:
parent
c9ce32d0f1
commit
4fdbb2d685
@ -115,7 +115,11 @@ def install f
|
|||||||
end
|
end
|
||||||
|
|
||||||
if f.fails_with? ENV.compiler
|
if f.fails_with? ENV.compiler
|
||||||
ENV.send CompilerSelector.new(f, ENV.compiler).compiler
|
begin
|
||||||
|
ENV.send CompilerSelector.new(f, ENV.compiler).compiler
|
||||||
|
rescue CompilerSelectionError => e
|
||||||
|
raise e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
f.brew do
|
f.brew do
|
||||||
|
@ -53,11 +53,18 @@ class CompilerSelector
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Attempts to select an appropriate alternate compiler, but
|
||||||
|
# if none can be found raises CompilerError instead
|
||||||
def compiler
|
def compiler
|
||||||
begin
|
begin
|
||||||
cc = @compilers.pop
|
cc = @compilers.pop
|
||||||
end while @f.fails_with?(cc)
|
end while @f.fails_with?(cc)
|
||||||
cc.nil? ? @old_compiler : cc.name
|
|
||||||
|
if cc.nil?
|
||||||
|
raise CompilerSelectionError
|
||||||
|
else
|
||||||
|
cc.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -160,6 +160,26 @@ class BuildError < Homebrew::InstallationError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# raised by CompilerSelector if the formula fails with all of
|
||||||
|
# the compilers available on the user's system
|
||||||
|
class CompilerSelectionError < StandardError
|
||||||
|
def message
|
||||||
|
if MacOS.version > :tiger then <<-EOS.undent
|
||||||
|
This formula cannot be built with any available compilers.
|
||||||
|
To install this formula, you may need to:
|
||||||
|
brew tap homebrew/dupes
|
||||||
|
brew install apple-gcc42
|
||||||
|
EOS
|
||||||
|
# tigerbrew has a separate apple-gcc42 for Xcode 2.5
|
||||||
|
else <<-EOS.undent
|
||||||
|
This formula cannot be built with any available compilers.
|
||||||
|
To install this formula, you need to:
|
||||||
|
brew install apple-gcc42
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# raised in CurlDownloadStrategy.fetch
|
# raised in CurlDownloadStrategy.fetch
|
||||||
class CurlDownloadStrategyError < RuntimeError
|
class CurlDownloadStrategyError < RuntimeError
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ class CompilerSelectorTests < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_all_compiler_failures
|
def test_all_compiler_failures
|
||||||
@f << :clang << :llvm << :gcc
|
@f << :clang << :llvm << :gcc
|
||||||
assert_equal @cc, actual_cc
|
assert_raise(CompilerSelectionError) { actual_cc }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_compiler_failures
|
def test_no_compiler_failures
|
||||||
@ -77,13 +77,13 @@ class CompilerSelectorTests < Test::Unit::TestCase
|
|||||||
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
|
||||||
assert_equal @cc, 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
|
||||||
assert_equal @cc, actual_cc
|
assert_raise(CompilerSelectionError) { actual_cc }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user