Skip to content

Commit

Permalink
Support core GCC formula as a GCC compiler.
Browse files Browse the repository at this point in the history
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#28418.
  • Loading branch information
MikeMcQuaid committed Apr 23, 2014
1 parent c3dd9fe commit 94be72a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
24 changes: 21 additions & 3 deletions Library/Homebrew/extend/ENV/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,29 @@ def ld64
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:
Expand Down
5 changes: 2 additions & 3 deletions Library/Homebrew/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def setup_build_environment(formula=nil)

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:
Expand Down
5 changes: 2 additions & 3 deletions Library/Homebrew/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ def determine_path
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
Expand Down
14 changes: 9 additions & 5 deletions Library/Homebrew/os/mac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ def gcc_40_build_version
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
Expand Down Expand Up @@ -167,13 +168,16 @@ def clang_build_version
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:
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/test/test_stdlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_apple_libstdcxx_intercompatibility
end

def test_compatibility_same_compilers_and_type
assert @gcc.compatible_with?(@gcc)
assert @gcc48.compatible_with?(@gcc48)
assert @clang.compatible_with?(@clang)
end
Expand All @@ -33,8 +34,8 @@ def test_apple_gnu_libstdcxx_incompatibility
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
Expand Down

0 comments on commit 94be72a

Please sign in to comment.