Merge pull request #4995 from sjackman/gcc
Default compiler is gcc on Linux
This commit is contained in:
commit
b41d2e5254
@ -3,6 +3,7 @@ module CompilerConstants
|
|||||||
GNU_GCC_VERSIONS = %w[4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 6 7 8].freeze
|
GNU_GCC_VERSIONS = %w[4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 6 7 8].freeze
|
||||||
GNU_GCC_REGEXP = /^gcc-(4\.[3-9]|[5-8])$/
|
GNU_GCC_REGEXP = /^gcc-(4\.[3-9]|[5-8])$/
|
||||||
COMPILER_SYMBOL_MAP = {
|
COMPILER_SYMBOL_MAP = {
|
||||||
|
"gcc" => :gcc,
|
||||||
"gcc-4.0" => :gcc_4_0,
|
"gcc-4.0" => :gcc_4_0,
|
||||||
"gcc-4.2" => :gcc_4_2,
|
"gcc-4.2" => :gcc_4_2,
|
||||||
"clang" => :clang,
|
"clang" => :clang,
|
||||||
@ -101,6 +102,7 @@ class CompilerSelector
|
|||||||
clang: [:clang, :gcc_4_2, :gnu, :gcc_4_0, :llvm_clang],
|
clang: [:clang, :gcc_4_2, :gnu, :gcc_4_0, :llvm_clang],
|
||||||
gcc_4_2: [:gcc_4_2, :gnu, :clang, :gcc_4_0],
|
gcc_4_2: [:gcc_4_2, :gnu, :clang, :gcc_4_0],
|
||||||
gcc_4_0: [:gcc_4_0, :gcc_4_2, :gnu, :clang],
|
gcc_4_0: [:gcc_4_0, :gcc_4_2, :gnu, :clang],
|
||||||
|
gcc: [:gnu, :gcc, :llvm_clang, :clang, :gcc_4_2, :gcc_4_0],
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def self.select_for(formula, compilers = self.compilers)
|
def self.select_for(formula, compilers = self.compilers)
|
||||||
@ -150,9 +152,9 @@ class CompilerSelector
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compiler_version(name)
|
def compiler_version(name)
|
||||||
case name
|
case name.to_s
|
||||||
when GNU_GCC_REGEXP
|
when "gcc", GNU_GCC_REGEXP
|
||||||
versions.non_apple_gcc_version(name)
|
versions.non_apple_gcc_version(name.to_s)
|
||||||
else
|
else
|
||||||
versions.send("#{name}_build_version")
|
versions.send("#{name}_build_version")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -99,7 +99,7 @@ class DevelopmentTools
|
|||||||
path = HOMEBREW_PREFIX/"opt/gcc/bin"/cc
|
path = HOMEBREW_PREFIX/"opt/gcc/bin"/cc
|
||||||
path = locate(cc) unless path.exist?
|
path = locate(cc) unless path.exist?
|
||||||
version = if path &&
|
version = if path &&
|
||||||
build_version = `#{path} --version`[/gcc(?:-\d(?:\.\d)? \(.+\))? (\d\.\d\.\d)/, 1]
|
build_version = `#{path} --version`[/gcc(?:(?:-\d(?:\.\d)?)? \(.+\))? (\d\.\d\.\d)/, 1]
|
||||||
Version.new build_version
|
Version.new build_version
|
||||||
else
|
else
|
||||||
Version::NULL
|
Version::NULL
|
||||||
|
|||||||
@ -319,7 +319,11 @@ module SharedEnvExtension
|
|||||||
def compiler_with_cxx11_support?(cc)
|
def compiler_with_cxx11_support?(cc)
|
||||||
return if compiler_any_clang?(cc)
|
return if compiler_any_clang?(cc)
|
||||||
|
|
||||||
version = cc[/^gcc-(\d+(?:\.\d+)?)$/, 1]
|
version = if cc == :gcc
|
||||||
|
non_apple_gcc_version "gcc"
|
||||||
|
else
|
||||||
|
cc[/^gcc-(\d+(?:\.\d+)?)$/, 1]
|
||||||
|
end
|
||||||
version && Version.create(version) >= Version.create("4.8")
|
version && Version.create(version) >= Version.create("4.8")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1 +1,5 @@
|
|||||||
require "extend/os/mac/development_tools" if OS.mac?
|
if OS.mac?
|
||||||
|
require "extend/os/mac/development_tools"
|
||||||
|
elsif OS.linux?
|
||||||
|
require "extend/os/linux/development_tools"
|
||||||
|
end
|
||||||
|
|||||||
7
Library/Homebrew/extend/os/linux/development_tools.rb
Normal file
7
Library/Homebrew/extend/os/linux/development_tools.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class DevelopmentTools
|
||||||
|
class << self
|
||||||
|
def default_compiler
|
||||||
|
:gcc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -4,13 +4,13 @@ require "software_spec"
|
|||||||
describe CompilerSelector do
|
describe CompilerSelector do
|
||||||
subject { described_class.new(software_spec, versions, compilers) }
|
subject { described_class.new(software_spec, versions, compilers) }
|
||||||
|
|
||||||
let(:compilers) { [:clang, :gcc, :gnu] }
|
let(:compilers) { [:clang, :gcc_4_2, :gnu] }
|
||||||
let(:software_spec) { SoftwareSpec.new }
|
let(:software_spec) { SoftwareSpec.new }
|
||||||
let(:cc) { :clang }
|
let(:cc) { :clang }
|
||||||
let(:versions) do
|
let(:versions) do
|
||||||
double(
|
double(
|
||||||
gcc_4_0_build_version: Version::NULL,
|
gcc_4_0_build_version: Version::NULL,
|
||||||
gcc_build_version: Version.create("5666"),
|
gcc_4_2_build_version: Version.create("5666"),
|
||||||
llvm_build_version: Version::NULL,
|
llvm_build_version: Version::NULL,
|
||||||
clang_build_version: Version.create("425"),
|
clang_build_version: Version.create("425"),
|
||||||
)
|
)
|
||||||
@ -29,7 +29,7 @@ describe CompilerSelector do
|
|||||||
describe "#compiler" do
|
describe "#compiler" do
|
||||||
it "raises an error if no matching compiler can be found" do
|
it "raises an error if no matching compiler can be found" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(:gcc)
|
software_spec.fails_with(:gcc_4_2)
|
||||||
software_spec.fails_with(gcc: "4.8")
|
software_spec.fails_with(gcc: "4.8")
|
||||||
software_spec.fails_with(gcc: "4.7")
|
software_spec.fails_with(gcc: "4.7")
|
||||||
|
|
||||||
@ -42,11 +42,11 @@ describe CompilerSelector do
|
|||||||
|
|
||||||
it "returns gcc if it fails with clang" do
|
it "returns gcc if it fails with clang" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
expect(subject.compiler).to eq(:gcc)
|
expect(subject.compiler).to eq(:gcc_4_2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns clang if it fails with gcc" do
|
it "returns clang if it fails with gcc" do
|
||||||
software_spec.fails_with(:gcc)
|
software_spec.fails_with(:gcc_4_2)
|
||||||
expect(subject.compiler).to eq(:clang)
|
expect(subject.compiler).to eq(:clang)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -57,41 +57,41 @@ describe CompilerSelector do
|
|||||||
|
|
||||||
it "still returns gcc-4.8 if it fails with gcc without a specific version" do
|
it "still returns gcc-4.8 if it fails with gcc without a specific version" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(:gcc)
|
software_spec.fails_with(:gcc_4_2)
|
||||||
expect(subject.compiler).to eq("gcc-4.8")
|
expect(subject.compiler).to eq("gcc-4.8")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns gcc if it fails with clang and llvm" do
|
it "returns gcc if it fails with clang and llvm" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
expect(subject.compiler).to eq(:gcc)
|
expect(subject.compiler).to eq(:gcc_4_2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns clang if it fails with gcc and llvm" do
|
it "returns clang if it fails with gcc and llvm" do
|
||||||
software_spec.fails_with(:gcc)
|
software_spec.fails_with(:gcc_4_2)
|
||||||
expect(subject.compiler).to eq(:clang)
|
expect(subject.compiler).to eq(:clang)
|
||||||
end
|
end
|
||||||
|
|
||||||
example "returns gcc if it fails with a specific gcc version" do
|
example "returns gcc if it fails with a specific gcc version" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(gcc: "4.8")
|
software_spec.fails_with(gcc: "4.8")
|
||||||
expect(subject.compiler).to eq(:gcc)
|
expect(subject.compiler).to eq(:gcc_4_2)
|
||||||
end
|
end
|
||||||
|
|
||||||
example "returns a lower version of gcc if it fails with the highest version" do
|
example "returns a lower version of gcc if it fails with the highest version" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(:gcc)
|
software_spec.fails_with(:gcc_4_2)
|
||||||
software_spec.fails_with(gcc: "4.8")
|
software_spec.fails_with(gcc: "4.8")
|
||||||
expect(subject.compiler).to eq("gcc-4.7")
|
expect(subject.compiler).to eq("gcc-4.7")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prefers gcc" do
|
it "prefers gcc" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(:gcc)
|
software_spec.fails_with(:gcc_4_2)
|
||||||
expect(subject.compiler).to eq("gcc-4.8")
|
expect(subject.compiler).to eq("gcc-4.8")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error when gcc is missing" do
|
it "raises an error when gcc is missing" do
|
||||||
allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
|
allow(versions).to receive(:gcc_4_2_build_version).and_return(Version::NULL)
|
||||||
|
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(gcc: "4.8")
|
software_spec.fails_with(gcc: "4.8")
|
||||||
@ -101,7 +101,7 @@ describe CompilerSelector do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error when llvm and gcc are missing" do
|
it "raises an error when llvm and gcc are missing" do
|
||||||
allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
|
allow(versions).to receive(:gcc_4_2_build_version).and_return(Version::NULL)
|
||||||
|
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(gcc: "4.8")
|
software_spec.fails_with(gcc: "4.8")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user