
This makes it easier to test the automatic installation of the libc and compiler formulae without having to change the code. This is particularly useful now we don't have any official Docker images for this.
84 lines
3.0 KiB
Ruby
84 lines
3.0 KiB
Ruby
# typed: strict
|
|
# frozen_string_literal: true
|
|
|
|
module OS
|
|
module Linux
|
|
module DevelopmentTools
|
|
module ClassMethods
|
|
extend T::Helpers
|
|
|
|
requires_ancestor { ::DevelopmentTools }
|
|
|
|
sig { params(tool: T.any(String, Symbol)).returns(T.nilable(Pathname)) }
|
|
def locate(tool)
|
|
@locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), Pathname]))
|
|
@locate.fetch(tool) do |key|
|
|
@locate[key] = if ::DevelopmentTools.needs_build_formulae? &&
|
|
(binutils_path = HOMEBREW_PREFIX/"opt/binutils/bin/#{tool}").executable?
|
|
binutils_path
|
|
elsif ::DevelopmentTools.needs_build_formulae? &&
|
|
(glibc_path = HOMEBREW_PREFIX/"opt/glibc/bin/#{tool}").executable?
|
|
glibc_path
|
|
elsif (homebrew_path = HOMEBREW_PREFIX/"bin/#{tool}").executable?
|
|
homebrew_path
|
|
elsif File.executable?(system_path = "/usr/bin/#{tool}")
|
|
Pathname.new system_path
|
|
end
|
|
end
|
|
end
|
|
|
|
sig { returns(Symbol) }
|
|
def default_compiler = :gcc
|
|
|
|
sig { returns(T::Boolean) }
|
|
def needs_libc_formula?
|
|
return @needs_libc_formula unless @needs_libc_formula.nil?
|
|
|
|
@needs_libc_formula = T.let(nil, T.nilable(T::Boolean))
|
|
|
|
# Undocumented environment variable to make it easier to test libc
|
|
# formula automatic installation.
|
|
@needs_libc_formula = true if ENV["HOMEBREW_FORCE_LIBC_FORMULA"]
|
|
@needs_libc_formula ||= OS::Linux::Glibc.below_ci_version?
|
|
end
|
|
|
|
# Keep this method around for now to make it easier to add this functionality later.
|
|
# rubocop:disable Lint/UselessMethodDefinition
|
|
sig { returns(Pathname) }
|
|
def host_gcc_path
|
|
# TODO: override this if/when we to pick the GCC based on e.g. the Ubuntu version.
|
|
super
|
|
end
|
|
# rubocop:enable Lint/UselessMethodDefinition
|
|
|
|
sig { returns(T::Boolean) }
|
|
def needs_compiler_formula?
|
|
return @needs_compiler_formula unless @needs_compiler_formula.nil?
|
|
|
|
@needs_compiler_formula = T.let(nil, T.nilable(T::Boolean))
|
|
|
|
# Undocumented environment variable to make it easier to test compiler
|
|
# formula automatic installation.
|
|
@needs_compiler_formula = true if ENV["HOMEBREW_FORCE_COMPILER_FORMULA"]
|
|
|
|
@needs_compiler_formula ||= if host_gcc_path.exist?
|
|
::DevelopmentTools.gcc_version(host_gcc_path.to_s) < OS::LINUX_GCC_CI_VERSION
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
sig { returns(T::Hash[String, T.nilable(String)]) }
|
|
def build_system_info
|
|
super.merge({
|
|
"glibc_version" => OS::Linux::Glibc.version.to_s.presence,
|
|
"oldest_cpu_family" => ::Hardware.oldest_cpu.to_s,
|
|
})
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
DevelopmentTools.singleton_class.prepend(OS::Linux::DevelopmentTools::ClassMethods)
|