compilers: prefer gcc 5 on linux
Fixes #10170 by preferring gcc@5 on linux This makes sure ENV.cc and ENV.cxx is correctly set: If a formula does not explicitely depend on a brewed gcc, ENV.cc is set to gcc-5 (system gcc-5 or brewed gcc-5) with this change, even if other gcc versions are installed on the system.
This commit is contained in:
parent
1d486249a3
commit
221983dbcf
@ -78,6 +78,7 @@ end
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
class CompilerSelector
|
class CompilerSelector
|
||||||
|
extend T::Sig
|
||||||
include CompilerConstants
|
include CompilerConstants
|
||||||
|
|
||||||
Compiler = Struct.new(:name, :version)
|
Compiler = Struct.new(:name, :version)
|
||||||
@ -111,9 +112,14 @@ class CompilerSelector
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def preferred_gcc
|
||||||
|
"gcc"
|
||||||
|
end
|
||||||
|
|
||||||
def gnu_gcc_versions
|
def gnu_gcc_versions
|
||||||
# prioritize gcc version provided by gcc formula.
|
# prioritize gcc version provided by gcc formula.
|
||||||
v = Formulary.factory("gcc").version.to_s.slice(/\d+/)
|
v = Formulary.factory(preferred_gcc).version.to_s.slice(/\d+/)
|
||||||
GNU_GCC_VERSIONS - [v] + [v] # move the version to the end of the list
|
GNU_GCC_VERSIONS - [v] + [v] # move the version to the end of the list
|
||||||
rescue FormulaUnavailableError
|
rescue FormulaUnavailableError
|
||||||
GNU_GCC_VERSIONS
|
GNU_GCC_VERSIONS
|
||||||
@ -150,3 +156,5 @@ class CompilerSelector
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "extend/os/compilers"
|
||||||
|
|||||||
4
Library/Homebrew/extend/os/compilers.rb
Normal file
4
Library/Homebrew/extend/os/compilers.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# typed: strict
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "extend/os/linux/compilers" if OS.linux?
|
||||||
11
Library/Homebrew/extend/os/linux/compilers.rb
Normal file
11
Library/Homebrew/extend/os/linux/compilers.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# typed: strict
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CompilerSelector
|
||||||
|
sig { returns(String) }
|
||||||
|
def preferred_gcc
|
||||||
|
# gcc-5 is the lowest gcc version we support on Linux.
|
||||||
|
# gcc-5 is the default gcc in Ubuntu 16.04 (used for our CI)
|
||||||
|
"gcc@5"
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -22,6 +22,7 @@ describe CompilerSelector do
|
|||||||
case name
|
case name
|
||||||
when "gcc-7" then Version.create("7.1")
|
when "gcc-7" then Version.create("7.1")
|
||||||
when "gcc-6" then Version.create("6.1")
|
when "gcc-6" then Version.create("6.1")
|
||||||
|
when "gcc-5" then Version.create("5.1")
|
||||||
else Version::NULL
|
else Version::NULL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -42,16 +43,31 @@ describe CompilerSelector do
|
|||||||
expect(selector.compiler).to eq("gcc-7")
|
expect(selector.compiler).to eq("gcc-7")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns gcc-6 if gcc formula offers gcc-6" do
|
it "returns gcc-6 if gcc formula offers gcc-6 on mac", :needs_macos do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0"))
|
allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0"))
|
||||||
expect(selector.compiler).to eq("gcc-6")
|
expect(selector.compiler).to eq("gcc-6")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns gcc-5 if gcc formula offers gcc-5 on linux", :needs_linux do
|
||||||
|
software_spec.fails_with(:clang)
|
||||||
|
allow(Formulary).to receive(:factory).with("gcc@5").and_return(double(version: "5.0"))
|
||||||
|
expect(selector.compiler).to eq("gcc-5")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns gcc-6 if gcc formula offers gcc-6 and fails with gcc-5 and gcc-7 on linux", :needs_linux do
|
||||||
|
software_spec.fails_with(:clang)
|
||||||
|
software_spec.fails_with(gcc: "5")
|
||||||
|
software_spec.fails_with(gcc: "7")
|
||||||
|
allow(Formulary).to receive(:factory).with("gcc@5").and_return(double(version: "5.0"))
|
||||||
|
expect(selector.compiler).to eq("gcc-6")
|
||||||
|
end
|
||||||
|
|
||||||
it "raises an error when gcc or llvm is missing" do
|
it "raises an error when gcc or llvm is missing" do
|
||||||
software_spec.fails_with(:clang)
|
software_spec.fails_with(:clang)
|
||||||
software_spec.fails_with(gcc: "7")
|
software_spec.fails_with(gcc: "7")
|
||||||
software_spec.fails_with(gcc: "6")
|
software_spec.fails_with(gcc: "6")
|
||||||
|
software_spec.fails_with(gcc: "5")
|
||||||
|
|
||||||
expect { selector.compiler }.to raise_error(CompilerSelectionError)
|
expect { selector.compiler }.to raise_error(CompilerSelectionError)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user