Support core GCC formula as a GCC compiler.

It is activated by the same mechanism as the Homebrew/versions compilers
which now check if the GCC formula uses the same, correct version.

References Homebrew/homebrew#28418.
This commit is contained in:
Mike McQuaid 2014-04-19 09:11:52 +01:00
parent 593702c70b
commit 55d277c335
5 changed files with 37 additions and 16 deletions

View File

@ -185,11 +185,29 @@ module SharedEnvExtension
append "LDFLAGS", "-B#{ld64.bin}/"
end
def gcc_version_formula(version)
gcc_formula = Formulary.factory("gcc")
return gcc_formula if gcc_formula.version.to_s.include?(version)
gcc_name = 'gcc' + version.delete('.')
Formulary.factory(gcc_name)
end
def warn_about_non_apple_gcc(gcc)
gcc_name = 'gcc' + gcc.delete('.')
begin
gcc_name = 'gcc' + gcc.delete('.')
gcc = Formulary.factory(gcc_name)
if !gcc.opt_prefix.exist?
gcc_formula = gcc_version_formula(gcc)
if gcc_formula.name == "gcc"
return if gcc_formula.opt_prefix.exist?
raise <<-EOS.undent
The Homebrew GCC was not installed.
You must:
brew install gcc
EOS
end
if !gcc_formula.opt_prefix.exist?
raise <<-EOS.undent
The requested Homebrew GCC, #{gcc_name}, was not installed.
You must:

View File

@ -73,9 +73,8 @@ module Stdenv
if cc =~ GNU_GCC_REGEXP
warn_about_non_apple_gcc($1)
gcc_name = 'gcc' + $1.delete('.')
gcc = Formulary.factory(gcc_name)
self.append_path('PATH', gcc.opt_prefix/'bin')
gcc_formula = gcc_version_formula($1)
self.append_path('PATH', gcc_formula.opt_prefix/'bin')
end
# Add lib and include etc. from the current macosxsdk to compiler flags:

View File

@ -135,9 +135,8 @@ module Superenv
end
if self['HOMEBREW_CC'] =~ GNU_GCC_REGEXP
gcc_name = 'gcc' + $1.delete('.')
gcc = Formulary.factory(gcc_name)
paths << gcc.opt_prefix/'bin'
gcc_formula = gcc_version_formula($1)
paths << gcc_formula.opt_prefix/'bin'
end
paths.to_path_s

View File

@ -131,8 +131,9 @@ module OS
def gcc_42_build_version
@gcc_42_build_version ||=
begin
gcc = MacOS.locate('gcc-4.2') || Formula.factory('apple-gcc42').opt_prefix/'bin/gcc-4.2'
raise unless gcc.exist?
gcc = MacOS.locate('gcc-4.2')
gcc ||= Formula.factory('apple-gcc42').opt_prefix/'bin/gcc-4.2' rescue nil
raise if gcc.nil? || !gcc.exist?
rescue
gcc = nil
end
@ -167,13 +168,16 @@ module OS
end
def non_apple_gcc_version(cc)
return unless path = locate(cc)
path = Formula.factory("gcc").opt_prefix/"bin/#{cc}"
path = nil unless path.exist?
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)
`#{path} --version` =~ /gcc(-\d\.\d \(GCC\))? (\d\.\d\.\d)/
instance_variable_set(ivar, $2)
end
# See these issues for some history:

View File

@ -23,6 +23,7 @@ class CxxStdlibTests < Test::Unit::TestCase
end
def test_compatibility_same_compilers_and_type
assert @gcc.compatible_with?(@gcc)
assert @gcc48.compatible_with?(@gcc48)
assert @clang.compatible_with?(@clang)
end
@ -33,8 +34,8 @@ class CxxStdlibTests < Test::Unit::TestCase
end
def test_gnu_cross_version_incompatibility
assert !@clang.compatible_with?(@gcc48)
assert !@gcc48.compatible_with?(@clang)
assert !@gcc48.compatible_with?(@gcc49)
assert !@gcc49.compatible_with?(@gcc48)
end
def test_libstdcxx_libcxx_incompatibility