Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompilerSelector: prefer the gcc version offered by the gcc formula #5958

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion Library/Homebrew/compilers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,19 @@ def compiler

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?
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/test/compiler_selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
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")
Expand Down