Skip to content
Snippets Groups Projects
Unverified Commit 066ef6b4 authored by Michka Popoff's avatar Michka Popoff Committed by GitHub
Browse files

Merge pull request #10512 from iMichka/gcc5

compilers: prefer gcc 5 on linux
parents c5e34371 221983db
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,7 @@ end
#
# @api private
class CompilerSelector
extend T::Sig
include CompilerConstants
Compiler = Struct.new(:name, :version)
......@@ -111,9 +112,14 @@ class CompilerSelector
private
sig { returns(String) }
def preferred_gcc
"gcc"
end
def gnu_gcc_versions
# 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
rescue FormulaUnavailableError
GNU_GCC_VERSIONS
......@@ -150,3 +156,5 @@ class CompilerSelector
end
end
end
require "extend/os/compilers"
# typed: strict
# frozen_string_literal: true
require "extend/os/linux/compilers" if OS.linux?
# 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
when "gcc-7" then Version.create("7.1")
when "gcc-6" then Version.create("6.1")
when "gcc-5" then Version.create("5.1")
else Version::NULL
end
end
......@@ -42,16 +43,31 @@ describe CompilerSelector do
expect(selector.compiler).to eq("gcc-7")
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)
allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0"))
expect(selector.compiler).to eq("gcc-6")
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
software_spec.fails_with(:clang)
software_spec.fails_with(gcc: "7")
software_spec.fails_with(gcc: "6")
software_spec.fails_with(gcc: "5")
expect { selector.compiler }.to raise_error(CompilerSelectionError)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment