From 0a292c7041d4497d51259882fc7e44892e875133 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Mon, 8 Feb 2021 20:06:09 +0100 Subject: [PATCH] linux: use preferred_gcc instead of gcc --- Library/Homebrew/compilers.rb | 8 ++++---- Library/Homebrew/extend/os/linux/compilers.rb | 2 +- Library/Homebrew/extend/os/linux/keg_relocate.rb | 4 +++- Library/Homebrew/extend/os/linux/linkage_checker.rb | 4 +++- Library/Homebrew/extend/os/linux/system_config.rb | 3 ++- Library/Homebrew/test/formula_installer_bottle_spec.rb | 1 + Library/Homebrew/test/formulary_spec.rb | 1 + 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index 4802530d73..47baccc603 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -110,16 +110,16 @@ class CompilerSelector raise CompilerSelectionError, formula end - private - sig { returns(String) } - def preferred_gcc + def self.preferred_gcc "gcc" end + private + def gnu_gcc_versions # prioritize gcc version provided by gcc formula. - v = Formulary.factory(preferred_gcc).version.to_s.slice(/\d+/) + v = Formulary.factory(CompilerSelector.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 diff --git a/Library/Homebrew/extend/os/linux/compilers.rb b/Library/Homebrew/extend/os/linux/compilers.rb index 93698765de..21ac0954d5 100644 --- a/Library/Homebrew/extend/os/linux/compilers.rb +++ b/Library/Homebrew/extend/os/linux/compilers.rb @@ -3,7 +3,7 @@ class CompilerSelector sig { returns(String) } - def preferred_gcc + def self.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" diff --git a/Library/Homebrew/extend/os/linux/keg_relocate.rb b/Library/Homebrew/extend/os/linux/keg_relocate.rb index b4307b71d9..8a3d713abd 100644 --- a/Library/Homebrew/extend/os/linux/keg_relocate.rb +++ b/Library/Homebrew/extend/os/linux/keg_relocate.rb @@ -1,6 +1,8 @@ # typed: true # frozen_string_literal: true +require "compilers" + class Keg def relocate_dynamic_linkage(relocation) # Patching the dynamic linker of glibc breaks it. @@ -84,7 +86,7 @@ class Keg def self.bottle_dependencies @bottle_dependencies ||= begin formulae = relocation_formulae - gcc = Formula["gcc"] + gcc = Formulary.factory(CompilerSelector.preferred_gcc) if !Homebrew::EnvConfig.force_homebrew_on_linux? && DevelopmentTools.non_apple_gcc_version("gcc") < gcc.version.to_i formulae += gcc.recursive_dependencies.map(&:name) diff --git a/Library/Homebrew/extend/os/linux/linkage_checker.rb b/Library/Homebrew/extend/os/linux/linkage_checker.rb index 6b7d0ea53e..d3d431c1b1 100644 --- a/Library/Homebrew/extend/os/linux/linkage_checker.rb +++ b/Library/Homebrew/extend/os/linux/linkage_checker.rb @@ -1,6 +1,8 @@ # typed: true # frozen_string_literal: true +require "compilers" + class LinkageChecker # Libraries provided by glibc and gcc. SYSTEM_LIBRARY_ALLOWLIST = %w[ @@ -30,6 +32,6 @@ class LinkageChecker @unwanted_system_dylibs = @system_dylibs.reject do |s| SYSTEM_LIBRARY_ALLOWLIST.include? File.basename(s) end - @undeclared_deps -= ["gcc", "glibc"] + @undeclared_deps -= [CompilerSelector.preferred_gcc, "glibc"] end end diff --git a/Library/Homebrew/extend/os/linux/system_config.rb b/Library/Homebrew/extend/os/linux/system_config.rb index 2f07c89b18..fee1f439d6 100644 --- a/Library/Homebrew/extend/os/linux/system_config.rb +++ b/Library/Homebrew/extend/os/linux/system_config.rb @@ -1,6 +1,7 @@ # typed: true # frozen_string_literal: true +require "compilers" require "os/linux/glibc" require "system_command" @@ -46,7 +47,7 @@ module SystemConfig out.puts "Host glibc: #{host_glibc_version}" out.puts "/usr/bin/gcc: #{host_gcc_version}" out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH - ["glibc", "gcc", "xorg"].each do |f| + ["glibc", CompilerSelector.preferred_gcc, "xorg"].each do |f| out.puts "#{f}: #{formula_linked_version(f)}" end end diff --git a/Library/Homebrew/test/formula_installer_bottle_spec.rb b/Library/Homebrew/test/formula_installer_bottle_spec.rb index c399404410..5bd845b559 100644 --- a/Library/Homebrew/test/formula_installer_bottle_spec.rb +++ b/Library/Homebrew/test/formula_installer_bottle_spec.rb @@ -24,6 +24,7 @@ describe FormulaInstaller do stub_formula_loader formula stub_formula_loader formula("gcc") { url "gcc-1.0" } + stub_formula_loader formula("gcc@5") { url "gcc-5.0" } stub_formula_loader formula("patchelf") { url "patchelf-1.0" } allow(Formula["patchelf"]).to receive(:latest_version_installed?).and_return(true) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index b8ca07410d..7da52e0771 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -142,6 +142,7 @@ describe Formulary do before do allow(described_class).to receive(:loader_for).and_call_original stub_formula_loader formula("gcc") { url "gcc-1.0" } + stub_formula_loader formula("gcc@5") { url "gcc-5.0" } stub_formula_loader formula("patchelf") { url "patchelf-1.0" } allow(Formula["patchelf"]).to receive(:latest_version_installed?).and_return(true) end