Remove alias generic_* definitions in favour of using super

This is the pattern we've been adopting for a while and it's a bit
cleaner. Let's remove all of the existing usage of the existing pattern
to avoid confusion when adopting the new one.
This commit is contained in:
Mike McQuaid 2025-06-13 16:59:10 +01:00 committed by GitHub
parent b6167f6024
commit 9ac306e464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 1121 additions and 1032 deletions

View File

@ -10,7 +10,6 @@ module Homebrew
def analytics_api_path
"analytics"
end
alias generic_analytics_api_path analytics_api_path
sig { params(category: String, days: T.any(Integer, String)).returns(T::Hash[String, T.untyped]) }
def fetch(category, days)

View File

@ -142,6 +142,7 @@ module Homebrew
private
sig { returns(String) }
def git_tags
tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname")
if tags.blank?

View File

@ -350,7 +350,6 @@ module Homebrew
sudo chmod +t #{HOMEBREW_TEMP}
EOS
end
alias generic_check_tmpdir_sticky_bit check_tmpdir_sticky_bit
def check_exist_directories
return if HOMEBREW_PREFIX.writable?

View File

@ -54,8 +54,6 @@ module SharedEnvExtension
@debug_symbols = debug_symbols
reset
end
alias generic_shared_setup_build_environment setup_build_environment
private :generic_shared_setup_build_environment
sig { void }
def reset

View File

@ -68,7 +68,6 @@ module Stdenv
gcc_formula = gcc_version_formula(cc)
append_path "PATH", gcc_formula.opt_bin.to_s
end
alias generic_setup_build_environment setup_build_environment
sig { returns(T.nilable(PATH)) }
def determine_pkg_config_libdir

View File

@ -125,7 +125,6 @@ module Superenv
# These flags will also be present:
# a - apply fix for apr-1-config path
end
alias generic_setup_build_environment setup_build_environment
private
@ -152,7 +151,6 @@ module Superenv
.reverse
.map { |d| d.opt_libexec/"bin" }
end
alias generic_homebrew_extra_paths homebrew_extra_paths
sig { returns(T.nilable(PATH)) }
def determine_path
@ -372,8 +370,8 @@ module Superenv
append_to_cccfg "O"
end
# This is an exception where we want to use this method name format.
# rubocop: disable Naming/MethodName
# Fixes style error `Naming/MethodName: Use snake_case for method names.`
sig { params(block: T.nilable(T.proc.void)).void }
def O0(&block)
if block

View File

@ -1,19 +1,19 @@
# typed: strict
# frozen_string_literal: true
module Homebrew
module OS
module Linux
module DevCmd
class UpdateTest < AbstractCommand
alias generic_git_tags git_tags
module UpdateTest
private
sig { returns(String) }
def git_tags
tags = generic_git_tags
tags = Utils.popen_read("git tag --list | sort -rV") if tags.blank?
tags
super.presence || Utils.popen_read("git tag --list | sort -rV")
end
end
end
end
end
Homebrew::DevCmd::UpdateTest.prepend(OS::Linux::DevCmd::UpdateTest)

View File

@ -62,7 +62,7 @@ module OS
def build_system_info
super.merge({
"glibc_version" => OS::Linux::Glibc.version.to_s.presence,
"oldest_cpu_family" => Hardware.oldest_cpu.to_s,
"oldest_cpu_family" => ::Hardware.oldest_cpu.to_s,
})
end
end

View File

@ -32,7 +32,7 @@ module OS
end
def check_tmpdir_sticky_bit
message = generic_check_tmpdir_sticky_bit
message = super
return if message.nil?
message + <<~EOS
@ -74,11 +74,11 @@ module OS
end
def check_supported_architecture
return if Hardware::CPU.intel?
return if Homebrew::EnvConfig.developer? && ENV["HOMEBREW_ARM64_TESTING"].present? && Hardware::CPU.arm?
return if ::Hardware::CPU.intel?
return if Homebrew::EnvConfig.developer? && ENV["HOMEBREW_ARM64_TESTING"].present? && ::Hardware::CPU.arm?
<<~EOS
Your CPU architecture (#{Hardware::CPU.arch}) is not supported. We only support
Your CPU architecture (#{::Hardware::CPU.arch}) is not supported. We only support
x86_64 CPU architectures. You will be unable to use binary packages (bottles).
#{support_tier_message(tier: 2)}

View File

@ -1,16 +1,22 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
module SharedEnvExtension
module OS
module Linux
module SharedEnvExtension
def effective_arch
if @build_bottle && @bottle_arch
@bottle_arch.to_sym
elsif @build_bottle
Hardware.oldest_cpu
elsif Hardware::CPU.intel? || Hardware::CPU.arm?
::Hardware.oldest_cpu
elsif ::Hardware::CPU.intel? || ::Hardware::CPU.arm?
:native
else
:dunno
end
end
end
end
end
SharedEnvExtension.prepend(OS::Linux::SharedEnvExtension)

View File

@ -1,10 +1,16 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
module Stdenv
module OS
module Linux
module Stdenv
extend T::Helpers
requires_ancestor { ::SharedEnvExtension }
sig {
params(
formula: T.nilable(Formula),
formula: T.nilable(::Formula),
cc: T.nilable(String),
build_bottle: T.nilable(T::Boolean),
bottle_arch: T.nilable(String),
@ -12,10 +18,9 @@ module Stdenv
debug_symbols: T.nilable(T::Boolean),
).void
}
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:,
testing_formula:, debug_symbols:)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
super
prepend_path "CPATH", HOMEBREW_PREFIX/"include"
prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"
@ -29,8 +34,12 @@ module Stdenv
end
def libxml2
append "CPPFLAGS", "-I#{Formula["libxml2"].include/"libxml2"}"
append "CPPFLAGS", "-I#{::Formula["libxml2"].include/"libxml2"}"
rescue FormulaUnavailableError
nil
end
end
end
end
Stdenv.prepend(OS::Linux::Stdenv)

View File

@ -1,16 +1,25 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
module Superenv
module OS
module Linux
module Superenv
extend T::Helpers
requires_ancestor { SharedEnvExtension }
requires_ancestor { ::Superenv }
module ClassMethods
sig { returns(Pathname) }
def self.shims_path
def shims_path
HOMEBREW_SHIMS_PATH/"linux/super"
end
sig { returns(T.nilable(Pathname)) }
def self.bin
def bin
shims_path.realpath
end
end
sig {
params(
@ -22,10 +31,10 @@ module Superenv
debug_symbols: T.nilable(T::Boolean),
).void
}
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:,
testing_formula:, debug_symbols:)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
super
self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2"
self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path
self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula)
@ -35,11 +44,11 @@ module Superenv
# Pointer authentication and BTI are hardening techniques most distros
# use by default on their packages. arm64 Linux we're packaging
# everything from scratch so the entire dependency tree can have it.
append_to_cccfg "b" if Hardware::CPU.arch == :arm64 && DevelopmentTools.gcc_version("gcc") >= 9
append_to_cccfg "b" if ::Hardware::CPU.arch == :arm64 && ::DevelopmentTools.gcc_version("gcc") >= 9
end
def homebrew_extra_paths
paths = generic_homebrew_extra_paths
paths = super
paths += %w[binutils make].filter_map do |f|
bin = Formulary.factory(f).opt_bin
bin if bin.directory?
@ -76,4 +85,9 @@ module Superenv
path
end
end
end
end
Superenv.singleton_class.prepend(OS::Linux::Superenv::ClassMethods)
Superenv.prepend(OS::Linux::Superenv)

View File

@ -1,9 +1,15 @@
# typed: strict
# frozen_string_literal: true
module FormulaCellarChecks
module OS
module Linux
module FormulaCellarChecks
sig { params(filename: Pathname).returns(T::Boolean) }
def valid_library_extension?(filename)
generic_valid_library_extension?(filename) || filename.basename.to_s.include?(".so.")
super || filename.basename.to_s.include?(".so.")
end
end
end
end
FormulaCellarChecks.prepend(OS::Linux::FormulaCellarChecks)

View File

@ -1,12 +1,18 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
module Hardware
class CPU
class << self
module OS
module Linux
module Hardware
module CPU
module ClassMethods
extend T::Helpers
requires_ancestor { T.class_of(::Hardware::CPU) }
def optimization_flags
@optimization_flags ||= begin
flags = generic_optimization_flags.dup
flags = super.dup
flags[:native] = arch_flag(Homebrew::EnvConfig.arch)
flags
end
@ -138,7 +144,7 @@ module Hardware
%w[aes altivec avx avx2 lm ssse3 sse4_2].each do |flag|
define_method(:"#{flag}?") do
T.bind(self, T.class_of(Hardware::CPU))
T.bind(self, OS::Linux::Hardware::CPU::ClassMethods)
flags.include? flag
end
end
@ -158,4 +164,8 @@ module Hardware
end
end
end
end
end
end
Hardware::CPU.singleton_class.prepend(OS::Linux::Hardware::CPU::ClassMethods)

View File

@ -1,8 +1,10 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
module Homebrew
module OS
module Linux
module Install
module ClassMethods
# This is a list of known paths to the host dynamic linker on Linux if
# the host glibc is new enough. The symlink_ld_so method will fail if
# the host linker cannot be found in this list.
@ -16,7 +18,6 @@ module Homebrew
/system/bin/linker64
/system/bin/linker
].freeze
private_constant :DYNAMIC_LINKERS
# We link GCC runtime libraries that are not specifically used for Fortran,
# which are linked by the GCC formula. We only use the versioned shared libraries
@ -28,44 +29,41 @@ module Homebrew
libgomp.so.1
libstdc++.so.6
].freeze
private_constant :GCC_RUNTIME_LIBS
def self.perform_preinstall_checks(all_fatal: false)
generic_perform_preinstall_checks(all_fatal:)
symlink_ld_so
setup_preferred_gcc_libs
end
private_class_method :perform_preinstall_checks
def self.global_post_install
generic_global_post_install
def perform_preinstall_checks(all_fatal: false)
super
symlink_ld_so
setup_preferred_gcc_libs
end
def self.check_cpu
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
return if Hardware::CPU.arm?
def global_post_install
super
symlink_ld_so
setup_preferred_gcc_libs
end
def check_cpu
return if ::Hardware::CPU.intel? && ::Hardware::CPU.is_64_bit?
return if ::Hardware::CPU.arm?
message = "Sorry, Homebrew does not support your computer's CPU architecture!"
if Hardware::CPU.ppc64le?
if ::Hardware::CPU.ppc64le?
message += <<~EOS
For OpenPOWER Linux (PPC64LE) support, see:
#{Formatter.url("https://github.com/homebrew-ppc64le/brew")}
EOS
end
abort message
::Kernel.abort message
end
private_class_method :check_cpu
def self.symlink_ld_so
def symlink_ld_so
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
ld_so = HOMEBREW_PREFIX/"opt/glibc/bin/ld.so"
unless ld_so.readable?
ld_so = DYNAMIC_LINKERS.find { |s| File.executable? s }
if ld_so.blank?
raise "Unable to locate the system's dynamic linker" unless brew_ld_so.readable?
::Kernel.raise "Unable to locate the system's dynamic linker" unless brew_ld_so.readable?
return
end
@ -76,9 +74,8 @@ module Homebrew
FileUtils.mkdir_p HOMEBREW_PREFIX/"lib"
FileUtils.ln_sf ld_so, brew_ld_so
end
private_class_method :symlink_ld_so
def self.setup_preferred_gcc_libs
def setup_preferred_gcc_libs
gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}"
glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?
@ -103,10 +100,10 @@ module Homebrew
FileUtils.chmod "u=rw,go-wx", ld_gcc_conf
FileUtils.rm_f HOMEBREW_PREFIX/"etc/ld.so.cache"
system HOMEBREW_PREFIX/"opt/glibc/sbin/ldconfig"
::Kernel.system HOMEBREW_PREFIX/"opt/glibc/sbin/ldconfig"
end
else
odie "#{HOMEBREW_PREFIX}/lib does not exist!" unless (HOMEBREW_PREFIX/"lib").readable?
::Kernel.odie "#{HOMEBREW_PREFIX}/lib does not exist!" unless (HOMEBREW_PREFIX/"lib").readable?
end
GCC_RUNTIME_LIBS.each do |library|
@ -127,6 +124,9 @@ module Homebrew
end
end
end
private_class_method :setup_preferred_gcc_libs
end
end
end
end
Homebrew::Install.singleton_class.prepend(OS::Linux::Install::ClassMethods)

View File

@ -3,7 +3,9 @@
require "compilers"
class LinkageChecker
module OS
module Linux
module LinkageChecker
# Libraries provided by glibc and gcc.
SYSTEM_LIBRARY_ALLOWLIST = %w[
ld-linux-x86-64.so.2
@ -29,7 +31,7 @@ class LinkageChecker
private
def check_dylibs(rebuild_cache:)
generic_check_dylibs(rebuild_cache:)
super
# glibc and gcc are implicit dependencies.
# No other linkage to system libraries is expected or desired.
@ -39,7 +41,8 @@ class LinkageChecker
# We build all formulae with an RPATH that includes the gcc formula's runtime lib directory.
# See: https://github.com/Homebrew/brew/blob/e689cc07/Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L53
# This results in formulae showing linkage with gcc whenever it is installed, even if no dependency is declared.
# This results in formulae showing linkage with gcc whenever it is installed, even if no dependency is
# declared.
# See discussions at:
# https://github.com/Homebrew/brew/pull/13659
# https://github.com/Homebrew/brew/pull/13796
@ -47,4 +50,8 @@ class LinkageChecker
@undeclared_deps.delete("gcc")
@indirect_deps.delete("gcc")
end
end
end
end
LinkageChecker.prepend(OS::Linux::LinkageChecker)

View File

@ -5,12 +5,14 @@ require "compilers"
require "os/linux/glibc"
require "system_command"
module SystemConfig
module OS
module Linux
module SystemConfig
module ClassMethods
include SystemCommand::Mixin
HOST_RUBY_PATH = "/usr/bin/ruby"
class << self
def host_glibc_version
version = OS::Linux::Glibc.system_version
return "N/A" if version.null?
@ -19,10 +21,10 @@ module SystemConfig
end
def host_gcc_version
gcc = DevelopmentTools.host_gcc_path
gcc = ::DevelopmentTools.host_gcc_path
return "N/A" unless gcc.executable?
`#{gcc} --version 2>/dev/null`[/ (\d+\.\d+\.\d+)/, 1]
Utils.popen_read(gcc, "--version")[/ (\d+\.\d+\.\d+)/, 1]
end
def formula_linked_version(formula)
@ -42,16 +44,20 @@ module SystemConfig
def dump_verbose_config(out = $stdout)
kernel = Utils.safe_popen_read("uname", "-mors").chomp
dump_generic_verbose_config(out)
super
out.puts "Kernel: #{kernel}"
out.puts "OS: #{OS::Linux.os_version}"
out.puts "WSL: #{OS::Linux.wsl_version}" if OS::Linux.wsl?
out.puts "Host glibc: #{host_glibc_version}"
out.puts "#{DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH
["glibc", CompilerSelector.preferred_gcc, OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA, "xorg"].each do |f|
out.puts "#{f}: #{formula_linked_version(f)}"
end
end
end
end
end
end
SystemConfig.singleton_class.prepend(OS::Linux::SystemConfig::ClassMethods)

View File

@ -1,10 +1,16 @@
# typed: strict
# frozen_string_literal: true
module SharedEnvExtension
module OS
module Mac
module SharedEnvExtension
extend T::Helpers
requires_ancestor { ::SharedEnvExtension }
sig {
params(
formula: T.nilable(Formula),
formula: T.nilable(::Formula),
cc: T.nilable(String),
build_bottle: T.nilable(T::Boolean),
bottle_arch: T.nilable(String),
@ -12,11 +18,9 @@ module SharedEnvExtension
debug_symbols: T.nilable(T::Boolean),
).void
}
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
generic_shared_setup_build_environment(formula:, cc:, build_bottle:,
bottle_arch:, testing_formula:,
debug_symbols:)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
super
# Normalise the system Perl version used, where multiple may be available
self["VERSIONER_PERL_VERSION"] = MacOS.preferred_perl_version
@ -39,4 +43,8 @@ module SharedEnvExtension
# https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2
OS::Mac::DevelopmentTools.ld64_version >= 711
end
end
end
end
SharedEnvExtension.prepend(OS::Mac::SharedEnvExtension)

View File

@ -1,8 +1,13 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
module Stdenv
undef homebrew_extra_pkg_config_paths
module OS
module Mac
module Stdenv
extend T::Helpers
requires_ancestor { SharedEnvExtension }
requires_ancestor { ::Stdenv }
sig { returns(T::Array[Pathname]) }
def homebrew_extra_pkg_config_paths
@ -20,10 +25,9 @@ module Stdenv
debug_symbols: T.nilable(T::Boolean),
).void
}
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:,
testing_formula:, debug_symbols:)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
super
append "LDFLAGS", "-Wl,-headerpad_max_install_names"
@ -114,4 +118,8 @@ module Stdenv
def no_fixup_chains
append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support?
end
end
end
end
Stdenv.prepend(OS::Mac::Stdenv)

View File

@ -1,34 +1,32 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
module Superenv
class << self
# The location of Homebrew's shims on macOS.
module OS
module Mac
module Superenv
extend T::Helpers
requires_ancestor { SharedEnvExtension }
requires_ancestor { ::Superenv }
module ClassMethods
sig { returns(Pathname) }
def shims_path
HOMEBREW_SHIMS_PATH/"mac/super"
end
undef bin
sig { returns(T.nilable(Pathname)) }
def bin
return unless DevelopmentTools.installed?
return unless ::DevelopmentTools.installed?
shims_path.realpath
end
end
undef homebrew_extra_pkg_config_paths,
homebrew_extra_isystem_paths, homebrew_extra_library_paths,
homebrew_extra_cmake_include_paths,
homebrew_extra_cmake_library_paths,
homebrew_extra_cmake_frameworks_paths,
determine_cccfg
sig { returns(T::Array[Pathname]) }
def homebrew_extra_pkg_config_paths
[Pathname("/usr/lib/pkgconfig"), Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")]
end
private :homebrew_extra_pkg_config_paths
sig { returns(T::Boolean) }
def libxml2_include_needed?
@ -37,7 +35,6 @@ module Superenv
true
end
private :libxml2_include_needed?
def homebrew_extra_isystem_paths
paths = []
@ -51,7 +48,7 @@ module Superenv
paths = []
if compiler == :llvm_clang
paths << "#{self["HOMEBREW_SDKROOT"]}/usr/lib"
paths << Formula["llvm"].opt_lib.to_s
paths << ::Formula["llvm"].opt_lib.to_s
end
paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths
@ -66,7 +63,8 @@ module Superenv
end
def homebrew_extra_cmake_library_paths
[Pathname("#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries")]
brew_sdkroot = self["HOMEBREW_SDKROOT"]
[Pathname("#{brew_sdkroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries")]
end
def homebrew_extra_cmake_frameworks_paths
@ -83,8 +81,8 @@ module Superenv
end
# @private
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk
is_xcode_sdk = sdk&.source == :xcode
@ -105,12 +103,11 @@ module Superenv
if deps.none? { |d| d.name == "m4" } &&
MacOS.active_developer_dir == MacOS::CLT::PKG_PATH &&
!File.exist?("#{MacOS::CLT::PKG_PATH}/usr/bin/m4") &&
(gm4 = DevelopmentTools.locate("gm4").to_s).present?
(gm4 = ::DevelopmentTools.locate("gm4").to_s).present?
self["M4"] = gm4
end
generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:,
testing_formula:, debug_symbols:)
super
# Filter out symbols known not to be defined since GNU Autotools can't
# reliably figure this out with Xcode 8 and above.
@ -168,4 +165,9 @@ module Superenv
def no_fixup_chains
append_to_cccfg "f" if no_fixup_chains_support?
end
end
end
end
Superenv.singleton_class.prepend(OS::Mac::Superenv::ClassMethods)
Superenv.prepend(OS::Mac::Superenv)

View File

@ -4,7 +4,14 @@
require "cache_store"
require "linkage_checker"
module FormulaCellarChecks
module OS
module Mac
module FormulaCellarChecks
extend T::Helpers
requires_ancestor { Homebrew::FormulaAuditor }
requires_ancestor { ::FormulaCellarChecks }
sig { returns(T.nilable(String)) }
def check_shadowed_headers
return if ["libtool", "subversion", "berkeley-db"].any? do |formula_name|
@ -31,7 +38,7 @@ module FormulaCellarChecks
def check_openssl_links
return unless formula.prefix.directory?
keg = Keg.new(formula.prefix)
keg = ::Keg.new(formula.prefix)
system_openssl = keg.mach_o_files.select do |obj|
dlls = obj.dynamically_linked_libraries
dlls.any? { |dll| %r{/usr/lib/lib(crypto|ssl|tls)\..*dylib}.match? dll }
@ -69,10 +76,10 @@ module FormulaCellarChecks
def check_linkage
return unless formula.prefix.directory?
keg = Keg.new(formula.prefix)
keg = ::Keg.new(formula.prefix)
CacheStoreDatabase.use(:linkage) do |db|
checker = LinkageChecker.new(keg, formula, cache_db: db)
checker = ::LinkageChecker.new(keg, formula, cache_db: db)
next unless checker.broken_library_linkage?
output = <<~EOS
@ -85,14 +92,14 @@ module FormulaCellarChecks
output += <<~EOS
Rebuild this from source with:
brew reinstall --build-from-source #{formula}
If that's successful, file an issue#{formula.tap ? " here:\n #{T.must(formula.tap).issues_url}" : "."}
If that's successful, file an issue#{formula.tap ? " here:\n #{formula.tap.issues_url}" : "."}
EOS
end
problem_if_output output
end
end
sig { params(formula: Formula).returns(T.nilable(String)) }
sig { params(formula: ::Formula).returns(T.nilable(String)) }
def check_flat_namespace(formula)
return unless formula.prefix.directory?
return if formula.tap&.audit_exception(:flat_namespace_allowlist, formula.name)
@ -120,7 +127,7 @@ module FormulaCellarChecks
sig { void }
def audit_installed
generic_audit_installed
super
problem_if_output(check_shadowed_headers)
problem_if_output(check_openssl_links)
problem_if_output(check_python_framework_links(formula.lib))
@ -128,9 +135,14 @@ module FormulaCellarChecks
problem_if_output(check_flat_namespace(formula))
end
MACOS_LIB_EXTENSIONS = %w[.dylib .framework].freeze
sig { params(filename: Pathname).returns(T::Boolean) }
def valid_library_extension?(filename)
macos_lib_extensions = %w[.dylib .framework]
generic_valid_library_extension?(filename) || macos_lib_extensions.include?(filename.extname)
super || MACOS_LIB_EXTENSIONS.include?(filename.extname)
end
end
end
end
FormulaCellarChecks.prepend(OS::Mac::FormulaCellarChecks)

View File

@ -1,15 +1,18 @@
# typed: strict
# frozen_string_literal: true
module Hardware
sig { params(version: T.nilable(Version)).returns(Symbol) }
def self.oldest_cpu(version = nil)
module OS
module Mac
module Hardware
module ClassMethods
sig { params(version: T.nilable(MacOSVersion)).returns(Symbol) }
def oldest_cpu(version = nil)
version = if version
MacOSVersion.new(version.to_s)
else
MacOS.version
end
if CPU.arch == :arm64
if ::Hardware::CPU.arch == :arm64
:arm_vortex_tempest
# This cannot use a newer CPU e.g. haswell because Rosetta 2 does not
# support AVX instructions in bottles:
@ -19,7 +22,12 @@ module Hardware
elsif version >= :mojave
:nehalem
else
generic_oldest_cpu
super
end
end
end
end
end
end
Hardware.singleton_class.prepend(OS::Mac::Hardware::ClassMethods)

View File

@ -95,7 +95,7 @@ module OS
end
end
generic_fix_dynamic_linkage
super
end
def loader_name_for(file, target)
@ -199,7 +199,7 @@ module OS
end
def prepare_relocation_to_locations
relocation = generic_prepare_relocation_to_locations
relocation = super
brewed_perl = runtime_dependencies&.any? { |dep| dep["full_name"] == "perl" && dep["declared_directly"] }
perl_path = if brewed_perl || name == "perl"

View File

@ -5,9 +5,10 @@ require "cask/info"
require "cask/cask_loader"
require "cask/caskroom"
module Homebrew
module OS
module Mac
module MissingFormula
class << self
module ClassMethods
sig { params(name: String).returns(T.nilable(String)) }
def disallowed_reason(name)
case name.downcase
@ -16,7 +17,7 @@ module Homebrew
Xcode can be installed from the App Store.
EOS
else
generic_disallowed_reason(name)
super
end
end
@ -36,24 +37,27 @@ module Homebrew
EOS
case command
when "install"
Cask::CaskLoader.load(name)
::Cask::CaskLoader.load(name)
when "uninstall"
cask = Cask::Caskroom.casks.find { |installed_cask| installed_cask.to_s == name }
raise Cask::CaskUnavailableError, name if cask.nil?
cask = ::Cask::Caskroom.casks.find { |installed_cask| installed_cask.to_s == name }
Kernel.raise ::Cask::CaskUnavailableError, name if cask.nil?
when "info"
cask = Cask::CaskLoader.load(name)
cask = ::Cask::CaskLoader.load(name)
suggestion = <<~EOS
Found a cask named "#{name}" instead.
#{Cask::Info.get_info(cask)}
#{::Cask::Info.get_info(cask)}
EOS
else
return
end
suggestion
rescue Cask::CaskUnavailableError
rescue ::Cask::CaskUnavailableError
nil
end
end
end
end
end
Homebrew::MissingFormula.singleton_class.prepend(OS::Mac::MissingFormula::ClassMethods)

View File

@ -6,6 +6,11 @@ require "system_command"
module OS
module Mac
module SystemConfig
module ClassMethods
extend T::Helpers
requires_ancestor { T.class_of(::SystemConfig) }
sig { returns(String) }
def describe_clang
return "N/A" if ::SystemConfig.clang.null?
@ -13,15 +18,6 @@ module OS
clang_build_info = ::SystemConfig.clang_build.null? ? "(parse error)" : ::SystemConfig.clang_build
"#{::SystemConfig.clang} build #{clang_build_info}"
end
end
end
end
SystemConfig.prepend(OS::Mac::SystemConfig)
module SystemConfig
class << self
include SystemCommand::Mixin
def xcode
@xcode ||= if MacOS::Xcode.installed?
@ -41,11 +37,14 @@ module SystemConfig
end
def dump_verbose_config(out = $stdout)
dump_generic_verbose_config(out)
super
out.puts "macOS: #{MacOS.full_version}-#{kernel}"
out.puts "CLT: #{clt || "N/A"}"
out.puts "Xcode: #{xcode || "N/A"}"
out.puts "Rosetta 2: #{Hardware::CPU.in_rosetta2?}" if Hardware::CPU.physical_cpu_arm64?
out.puts "Rosetta 2: #{::Hardware::CPU.in_rosetta2?}" if ::Hardware::CPU.physical_cpu_arm64?
end
end
end
end
end
SystemConfig.singleton_class.prepend(OS::Mac::SystemConfig::ClassMethods)

View File

@ -1,37 +1,40 @@
# typed: strict
# frozen_string_literal: true
module Utils
module OS
module Mac
module Bottles
class << self
module MacOSOverride
sig { params(tag: T.nilable(T.any(Symbol, Tag))).returns(Tag) }
module ClassMethods
sig { params(tag: T.nilable(T.any(Symbol, Utils::Bottles::Tag))).returns(Utils::Bottles::Tag) }
def tag(tag = nil)
return Tag.new(system: MacOS.version.to_sym, arch: Hardware::CPU.arch) if tag.nil?
if tag.nil?
Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: ::Hardware::CPU.arch)
else
super
end
end
prepend MacOSOverride
end
class Collector
module Collector
extend T::Helpers
requires_ancestor { Utils::Bottles::Collector }
private
alias generic_find_matching_tag find_matching_tag
sig { params(tag: Utils::Bottles::Tag, no_older_versions: T::Boolean).returns(T.nilable(Utils::Bottles::Tag)) }
sig {
params(tag: Utils::Bottles::Tag,
no_older_versions: T::Boolean).returns(T.nilable(Utils::Bottles::Tag))
}
def find_matching_tag(tag, no_older_versions: false)
# Used primarily by developers testing beta macOS releases.
if no_older_versions ||
(OS::Mac.version.prerelease? &&
Homebrew::EnvConfig.developer? &&
Homebrew::EnvConfig.skip_or_later_bottles?)
generic_find_matching_tag(tag)
super(tag)
else
generic_find_matching_tag(tag) ||
find_older_compatible_tag(tag)
super(tag) || find_older_compatible_tag(tag)
end
end
@ -56,4 +59,8 @@ module Utils
end
end
end
end
end
Utils::Bottles.singleton_class.prepend(OS::Mac::Bottles::ClassMethods)
Utils::Bottles::Collector.prepend(OS::Mac::Bottles::Collector)

View File

@ -84,7 +84,6 @@ module FormulaCellarChecks
def valid_library_extension?(filename)
VALID_LIBRARY_EXTENSIONS.include? filename.extname
end
alias generic_valid_library_extension? valid_library_extension?
sig { returns(T.nilable(String)) }
def check_non_libraries
@ -437,7 +436,6 @@ module FormulaCellarChecks
problem_if_output(check_cpuid_instruction(formula))
problem_if_output(check_binary_arches(formula))
end
alias generic_audit_installed audit_installed
private

View File

@ -42,7 +42,6 @@ module Hardware
ppc64le: "-mcpu=powerpc64le",
}.freeze, T.nilable(T::Hash[Symbol, String]))
end
alias generic_optimization_flags optimization_flags
sig { returns(Symbol) }
def arch_32_bit
@ -219,6 +218,7 @@ module Hardware
end
end
sig { params(_version: T.nilable(MacOSVersion)).returns(Symbol) }
def oldest_cpu(_version = nil)
if Hardware::CPU.intel?
if Hardware::CPU.is_64_bit?
@ -242,7 +242,6 @@ module Hardware
Hardware::CPU.family
end
end
alias generic_oldest_cpu oldest_cpu
# Returns a Rust flag to set the target CPU if necessary.
# Defaults to nil.

View File

@ -37,7 +37,6 @@ module Homebrew
end
def global_post_install; end
alias generic_global_post_install global_post_install
def check_prefix
if (Hardware::CPU.intel? || Hardware::CPU.in_rosetta2?) &&
@ -366,7 +365,6 @@ module Homebrew
Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
Diagnostic.checks(:fatal_preinstall_checks)
end
alias generic_perform_preinstall_checks perform_preinstall_checks
def attempt_directory_creation
Keg.must_exist_directories.each do |dir|

View File

@ -77,7 +77,6 @@ class Keg
FileUtils.ln_s(new_src, file)
end
end
alias generic_fix_dynamic_linkage fix_dynamic_linkage
def relocate_dynamic_linkage(_relocation)
[]
@ -102,7 +101,6 @@ class Keg
relocation
end
alias generic_prepare_relocation_to_placeholders prepare_relocation_to_placeholders
def replace_locations_with_placeholders
relocation = prepare_relocation_to_placeholders.freeze
@ -123,7 +121,6 @@ class Keg
relocation
end
alias generic_prepare_relocation_to_locations prepare_relocation_to_locations
def replace_placeholders_with_locations(files, skip_linkage: false)
relocation = prepare_relocation_to_locations.freeze
@ -221,7 +218,6 @@ class Keg
[grep_bin, grep_args]
end
alias generic_egrep_args egrep_args
def each_unique_file_matching(string)
Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io|

View File

@ -188,12 +188,10 @@ class LinkageChecker
store&.update!(keg_files_dylibs:)
end
alias generic_check_dylibs check_dylibs
def system_libraries_exist_in_cache?
false
end
alias generic_system_libraries_exist_in_cache? system_libraries_exist_in_cache?
def dylib_found_in_shared_cache?(dylib)
@dyld_shared_cache_contains_path ||= begin

View File

@ -93,7 +93,6 @@ module Homebrew
EOS
end
end
alias generic_disallowed_reason disallowed_reason
sig { params(name: String).returns(T.nilable(String)) }
def tap_migration_reason(name)
@ -195,8 +194,10 @@ module Homebrew
end
end
sig { params(name: String, silent: T::Boolean, show_info: T::Boolean).returns(T.nilable(String)) }
def cask_reason(name, silent: false, show_info: false); end
sig { params(name: String, command: String).returns(T.nilable(String)) }
def suggest_command(name, command); end
require "extend/os/missing_formula"

View File

@ -195,7 +195,6 @@ module SystemConfig
out.puts hardware if hardware
host_software_config(out)
end
alias dump_generic_verbose_config dump_verbose_config
end
end