From 9af3917ebf9fcfdad05f5a810815cba9a7df377a Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Fri, 4 Apr 2014 21:16:09 -0700 Subject: [PATCH] Formula: provide compiler failure collections `needs` allows formulae to specify dependencies on cross-compiler dependencies, allowing multiple failures to be specified in a single statement. For instance, `needs :cxx11` adds seven compiler failures. Closes Homebrew/homebrew#22912. --- Library/Homebrew/compilers.rb | 29 +++++++++++++++++++++++++++++ Library/Homebrew/formula.rb | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index bd3fde6989..7473f12a7f 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -28,6 +28,35 @@ class CompilerFailure attr_reader :compiler, :major_version attr_rw :cause, :version + MESSAGES = { + :cxx11 => 'This compiler does not support C++11' + } + + COLLECTIONS = { + :cxx11 => [ + [:gcc_4_0, proc { cause MESSAGES[:cxx11] }], + [:gcc, proc { cause MESSAGES[:cxx11] }], + [:clang, proc { build 425; cause MESSAGES[:cxx11] }], + [{:gcc => '4.3'}, proc { cause MESSAGES[:cxx11] }], + [{:gcc => '4.4'}, proc { cause MESSAGES[:cxx11] }], + [{:gcc => '4.5'}, proc { cause MESSAGES[:cxx11] }], + [{:gcc => '4.6'}, proc { cause MESSAGES[:cxx11] }] + ], + :openmp => [ + [:clang, proc { cause 'clang does not support OpenMP' }] + ] + } + + def self.for_standard standard + failures = COLLECTIONS.fetch(standard) do + raise ArgumentError, "\"#{standard}\" is not a recognized standard" + end + + failures.map do |compiler, block| + CompilerFailure.new(compiler, &block) + end + end + def initialize compiler, &block # Non-Apple compilers are in the format fails_with compiler => version if compiler.is_a? Hash diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 49271b76d8..2fe4859091 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -761,6 +761,13 @@ class Formula @cc_failures << CompilerFailure.new(compiler, &block) end + def needs *standards + @cc_failures ||= Set.new + standards.each do |standard| + @cc_failures.merge CompilerFailure.for_standard standard + end + end + def require_universal_deps specs.each { |spec| spec.build.universal = true } end