From 4eff378d09563b6ce8612f480cb7f5f51fb818b5 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 14 Aug 2020 03:39:31 +0200 Subject: [PATCH] Refactor and document `CxxStdlib`. --- Library/Homebrew/cxxstdlib.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index 1b279c28b9..e2754c51b7 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -2,9 +2,11 @@ require "compilers" +# Combination of C++ standard library and compiler. class CxxStdlib include CompilerConstants + # Error for when a formula's dependency was built with a different C++ standard library. class CompatibilityError < StandardError def initialize(formula, dep, stdlib) super <<~EOS @@ -17,8 +19,8 @@ class CxxStdlib def self.create(type, compiler) raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type) - klass = (compiler.to_s =~ GNU_GCC_REGEXP) ? GnuStdlib : AppleStdlib - klass.new(type, compiler) + apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true + CxxStdlib.new(type, compiler, apple_compiler) end def self.check_compatibility(formula, deps, keg, compiler) @@ -35,9 +37,10 @@ class CxxStdlib attr_reader :type, :compiler - def initialize(type, compiler) + def initialize(type, compiler, apple_compiler) @type = type @compiler = compiler.to_sym + @apple_compiler = apple_compiler end # If either package doesn't use C++, all is well. @@ -72,15 +75,7 @@ class CxxStdlib "#<#{self.class.name}: #{compiler} #{type}>" end - class AppleStdlib < CxxStdlib - def apple_compiler? - true - end - end - - class GnuStdlib < CxxStdlib - def apple_compiler? - false - end + def apple_compiler? + @apple_compiler end end