2024-09-21 12:24:21 -07:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
module OS
|
|
|
|
module Linux
|
|
|
|
module DevelopmentTools
|
|
|
|
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
|
2018-10-01 15:34:47 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
sig { returns(Symbol) }
|
|
|
|
def default_compiler = :gcc
|
2021-03-31 17:01:36 -07:00
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
sig { returns(T::Boolean) }
|
|
|
|
def needs_libc_formula?
|
|
|
|
return @needs_libc_formula unless @needs_libc_formula.nil?
|
2022-08-25 11:04:37 +01:00
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
@needs_libc_formula = T.let(OS::Linux::Glibc.below_ci_version?, T.nilable(T::Boolean))
|
|
|
|
@needs_libc_formula = !!@needs_libc_formula
|
|
|
|
end
|
2022-08-25 11:04:37 +01:00
|
|
|
|
2025-04-03 12:47:21 +01:00
|
|
|
# Keep this method around for now to make it easier to add this functionality later.
|
|
|
|
# rubocop:disable Style/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 Style/UselessMethodDefinition
|
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
sig { returns(T::Boolean) }
|
|
|
|
def needs_compiler_formula?
|
|
|
|
return @needs_compiler_formula unless @needs_compiler_formula.nil?
|
2022-09-20 13:06:31 +01:00
|
|
|
|
2025-04-03 12:47:21 +01:00
|
|
|
@needs_compiler_formula = T.let(nil, T.nilable(T::Boolean))
|
|
|
|
@needs_compiler_formula = if host_gcc_path.exist?
|
|
|
|
::DevelopmentTools.gcc_version(host_gcc_path.to_s) < OS::LINUX_GCC_CI_VERSION
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
2022-11-09 14:45:43 +00:00
|
|
|
end
|
2022-08-25 11:04:37 +01:00
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
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
|
2021-03-31 17:01:36 -07:00
|
|
|
end
|
2018-09-27 18:26:03 -07:00
|
|
|
end
|
|
|
|
end
|
2024-09-21 12:24:21 -07:00
|
|
|
|
|
|
|
DevelopmentTools.singleton_class.prepend(OS::Linux::DevelopmentTools)
|