ENV: mark gcc-6 as supporting C++11 (#349)

Add SharedEnvExtension#gcc_with_cxx11_support? to centralise the
logic for checking whether a compiler is known to support C++11.

Update logic to accept GCC 4.8 and above (including 6). Thereby also
address oversight in #163 where support for GCC 6 was added without
updating the C++11 compiler whitelist.

Add tests for Superenv#cxx11.

Closes #346.
This commit is contained in:
msbit 2016-06-16 22:15:28 +10:00 committed by Martin Afanasjew
parent 62dd4b14ba
commit 01e8e180a8
4 changed files with 37 additions and 4 deletions

View File

@ -322,4 +322,9 @@ module SharedEnvExtension
raise "Non-Apple GCC can't build universal binaries"
end
end
def gcc_with_cxx11_support?(cc)
version = cc[/^gcc-(\d+(?:\.\d+)?)$/, 1]
version && Version.new(version) >= Version.new("4.8")
end
end

View File

@ -287,7 +287,7 @@ module Stdenv
if compiler == :clang
append "CXX", "-std=c++11"
append "CXX", "-stdlib=libc++"
elsif compiler =~ /gcc-(4\.(8|9)|5)/
elsif gcc_with_cxx11_support?(compiler)
append "CXX", "-std=c++11"
else
raise "The selected compiler doesn't support C++11: #{compiler}"

View File

@ -303,11 +303,10 @@ module Superenv
end
def cxx11
case homebrew_cc
when "clang"
if homebrew_cc == "clang"
append "HOMEBREW_CCCFG", "x", ""
append "HOMEBREW_CCCFG", "g", ""
when /gcc-(4\.(8|9)|5)/
elsif gcc_with_cxx11_support?(homebrew_cc)
append "HOMEBREW_CCCFG", "x", ""
else
raise "The selected compiler doesn't support C++11: #{homebrew_cc}"

View File

@ -141,4 +141,33 @@ class SuperenvTests < Homebrew::TestCase
assert_equal [], @env.deps
assert_equal [], @env.keg_only_deps
end
def test_unsupported_cxx11
%w[gcc gcc-4.7].each do |compiler|
@env["HOMEBREW_CC"] = compiler
assert_raises do
@env.cxx11
end
refute_match "x", @env["HOMEBREW_CCCFG"]
end
end
def test_supported_cxx11_gcc_5
@env["HOMEBREW_CC"] = "gcc-5"
@env.cxx11
assert_match "x", @env["HOMEBREW_CCCFG"]
end
def test_supported_cxx11_gcc_6
@env["HOMEBREW_CC"] = "gcc-6"
@env.cxx11
assert_match "x", @env["HOMEBREW_CCCFG"]
end
def test_supported_cxx11_clang
@env["HOMEBREW_CC"] = "clang"
@env.cxx11
assert_match "x", @env["HOMEBREW_CCCFG"]
assert_match "g", @env["HOMEBREW_CCCFG"]
end
end