aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisty De Meo2013-05-20 19:35:07 -0500
committerMisty De Meo2013-05-20 23:25:15 -0500
commit7780e131820aab12ead852cd489e774ce764c247 (patch)
treef394e5d23cd27118bbaa2d65b10979b4b0b28f99
parent29590171230e4a60d0aa43480825de4b131753be (diff)
downloadhomebrew-7780e131820aab12ead852cd489e774ce764c247.tar.bz2
CompilerSelector: raise when no compatible compiler
This replaces the old behaviour of falling back to the original compiler with no messaging. Fixes #19170. Fixes mistydemeo/tigerbrew#45.
-rwxr-xr-xLibrary/Homebrew/build.rb6
-rw-r--r--Library/Homebrew/compilers.rb9
-rw-r--r--Library/Homebrew/exceptions.rb20
-rw-r--r--Library/Homebrew/test/test_compiler_selector.rb6
4 files changed, 36 insertions, 5 deletions
diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb
index 9b501d4b3..6c8d60a14 100755
--- a/Library/Homebrew/build.rb
+++ b/Library/Homebrew/build.rb
@@ -115,7 +115,11 @@ def install f
end
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
f.brew do
diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb
index b871e1aeb..37ce6cdb2 100644
--- a/Library/Homebrew/compilers.rb
+++ b/Library/Homebrew/compilers.rb
@@ -53,11 +53,18 @@ class CompilerSelector
end
end
+ # Attempts to select an appropriate alternate compiler, but
+ # if none can be found raises CompilerError instead
def compiler
begin
cc = @compilers.pop
end while @f.fails_with?(cc)
- cc.nil? ? @old_compiler : cc.name
+
+ if cc.nil?
+ raise CompilerSelectionError
+ else
+ cc.name
+ end
end
private
diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb
index 4f1fafdce..0dbdb8b1d 100644
--- a/Library/Homebrew/exceptions.rb
+++ b/Library/Homebrew/exceptions.rb
@@ -160,6 +160,26 @@ class BuildError < Homebrew::InstallationError
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
class CurlDownloadStrategyError < RuntimeError
end
diff --git a/Library/Homebrew/test/test_compiler_selector.rb b/Library/Homebrew/test/test_compiler_selector.rb
index 6e3a36366..4ce682c96 100644
--- a/Library/Homebrew/test/test_compiler_selector.rb
+++ b/Library/Homebrew/test/test_compiler_selector.rb
@@ -31,7 +31,7 @@ class CompilerSelectorTests < Test::Unit::TestCase
def test_all_compiler_failures
@f << :clang << :llvm << :gcc
- assert_equal @cc, actual_cc
+ assert_raise(CompilerSelectionError) { actual_cc }
end
def test_no_compiler_failures
@@ -77,13 +77,13 @@ class CompilerSelectorTests < Test::Unit::TestCase
def test_missing_gcc
MacOS.stubs(:gcc_build_version).returns(nil)
@f << :clang << :llvm
- assert_equal @cc, actual_cc
+ assert_raise(CompilerSelectionError) { actual_cc }
end
def test_missing_llvm_and_gcc
MacOS.stubs(:gcc_build_version).returns(nil)
MacOS.stubs(:llvm_build_version).returns(nil)
@f << :clang
- assert_equal @cc, actual_cc
+ assert_raise(CompilerSelectionError) { actual_cc }
end
end