CompilerSelector: prefer the gcc verion offered by the gcc formula
When GCC is used (default for Linux), we should prefer the gcc offered by the gcc formula. As such even if users install a gcc with higher version from `gcc@*` formula, it will not be picked up to build other formulae. This would also allow users to safely delete `gcc@*` formula. Closes #5953.
This commit is contained in:
parent
439283c3df
commit
363355ae47
@ -105,11 +105,19 @@ class CompilerSelector
|
||||
|
||||
private
|
||||
|
||||
def gnu_gcc_versions
|
||||
# prioritize gcc version provided by gcc formula.
|
||||
v = Formulary.factory("gcc").version.to_s.slice(/\d/)
|
||||
GNU_GCC_VERSIONS - [v] + [v] # move the version to the end of the list
|
||||
rescue FormulaUnavailableError
|
||||
GNU_GCC_VERSIONS
|
||||
end
|
||||
|
||||
def find_compiler
|
||||
compilers.each do |compiler|
|
||||
case compiler
|
||||
when :gnu
|
||||
GNU_GCC_VERSIONS.reverse_each do |v|
|
||||
gnu_gcc_versions.reverse_each do |v|
|
||||
name = "gcc-#{v}"
|
||||
version = compiler_version(name)
|
||||
yield Compiler.new(name, version) unless version.null?
|
||||
|
||||
@ -39,6 +39,12 @@ describe CompilerSelector do
|
||||
expect(subject.compiler).to eq("gcc-7")
|
||||
end
|
||||
|
||||
it "returns gcc-6 if gcc formula offers gcc-6" do
|
||||
software_spec.fails_with(:clang)
|
||||
allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0"))
|
||||
expect(subject.compiler).to eq("gcc-6")
|
||||
end
|
||||
|
||||
it "raises an error when gcc or llvm is missing" do
|
||||
software_spec.fails_with(:clang)
|
||||
software_spec.fails_with(gcc: "7")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user