Replace undef with prepended modules

This commit is contained in:
Douglas Eichelberger 2024-09-05 19:56:32 -07:00
parent 07da4aa7a6
commit 27e951c408
12 changed files with 88 additions and 77 deletions

View File

@ -19,9 +19,6 @@ module Homebrew
sig { returns(T::Array[String]) } sig { returns(T::Array[String]) }
attr_reader :options_only, :flags_only attr_reader :options_only, :flags_only
# undefine tap to allow --tap argument
undef tap
sig { void } sig { void }
def initialize def initialize
require "cli/named_args" require "cli/named_args"

View File

@ -2,8 +2,10 @@
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
class Cleanup module CleanupLinux
undef use_system_ruby? extend T::Helpers
requires_ancestor { Cleanup }
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def use_system_ruby? def use_system_ruby?
@ -21,3 +23,5 @@ module Homebrew
end end
end end
end end
Homebrew::Cleanup.prepend(Homebrew::CleanupLinux)

View File

@ -1,12 +1,10 @@
# typed: true # rubocop:disable Sorbet/StrictSigil # typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true # frozen_string_literal: true
class Formula module FormulaLinux
undef shared_library extend T::Helpers
undef loader_path
undef deuniversalize_machos requires_ancestor { Formula }
undef add_global_deps_to_spec
undef valid_platform?
sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
def shared_library(name, version = nil) def shared_library(name, version = nil)
@ -50,3 +48,5 @@ class Formula
requirements.none?(MacOSRequirement) requirements.none?(MacOSRequirement)
end end
end end
Formula.prepend(FormulaLinux)

View File

@ -1,16 +1,19 @@
# typed: strict # typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
module CLI module CLI
class Parser module ParserLinux
undef set_default_options extend T::Helpers
undef validate_options
requires_ancestor { Homebrew::CLI::Parser }
sig { void }
def set_default_options def set_default_options
@args["formula?"] = true if @args.respond_to?(:formula?) @args["formula?"] = true if @args.respond_to?(:formula?)
end end
sig { void }
def validate_options def validate_options
return unless @args.respond_to?(:cask?) return unless @args.respond_to?(:cask?)
return unless @args.cask? return unless @args.cask?
@ -22,3 +25,5 @@ module Homebrew
end end
end end
end end
Homebrew::CLI::Parser.prepend(Homebrew::CLI::ParserLinux)

View File

@ -1,13 +1,13 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
class Cleaner module CleanerMac
private private
undef executable_path?
sig { params(path: Pathname).returns(T::Boolean) } sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path) def executable_path?(path)
path.mach_o_executable? || path.text_executable? path.mach_o_executable? || path.text_executable?
end end
end end
Cleaner.prepend(CleanerMac)

View File

@ -2,9 +2,7 @@
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
class Cleanup module CleanupMac
undef use_system_ruby?
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def use_system_ruby? def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby? return false if Homebrew::EnvConfig.force_vendor_ruby?
@ -13,3 +11,5 @@ module Homebrew
end end
end end
end end
Homebrew::Cleanup.prepend(Homebrew::CleanupMac)

View File

@ -3,9 +3,7 @@
module Homebrew module Homebrew
module DevCmd module DevCmd
class Bottle < AbstractCommand module BottleMac
undef tar_args
sig { returns(T::Array[String]) } sig { returns(T::Array[String]) }
def tar_args def tar_args
if MacOS.version >= :catalina if MacOS.version >= :catalina
@ -15,8 +13,6 @@ module Homebrew
end end
end end
undef gnu_tar
sig { params(gnu_tar_formula: Formula).returns(String) } sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula) def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar" "#{gnu_tar_formula.opt_bin}/gtar"
@ -24,3 +20,5 @@ module Homebrew
end end
end end
end end
Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac)

View File

@ -1,9 +1,10 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
class Formula module FormulaMac
undef valid_platform? extend T::Helpers
undef std_cmake_args
requires_ancestor { Formula }
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def valid_platform? def valid_platform?
@ -31,3 +32,5 @@ class Formula
args args
end end
end end
Formula.prepend(FormulaMac)

View File

@ -1,8 +1,10 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
class FormulaInstaller module FormulaInstallerMac
undef fresh_install? extend T::Helpers
requires_ancestor { FormulaInstaller }
sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } sig { params(formula: Formula).returns(T.nilable(T::Boolean)) }
def fresh_install?(formula) def fresh_install?(formula)
@ -10,3 +12,5 @@ class FormulaInstaller
(!installed_as_dependency? || !formula.any_version_installed?) (!installed_as_dependency? || !formula.any_version_installed?)
end end
end end
FormulaInstaller.prepend(FormulaInstallerMac)

View File

@ -1,9 +1,7 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
class LinkageChecker module LinkageCheckerMac
undef system_libraries_exist_in_cache?
private private
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
@ -12,3 +10,5 @@ class LinkageChecker
MacOS.version >= :big_sur MacOS.version >= :big_sur
end end
end end
LinkageChecker.prepend(LinkageCheckerMac)

View File

@ -1,39 +1,42 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Readall module ReadallMac
class << self extend T::Helpers
undef valid_casks?
def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) requires_ancestor { Kernel }
return true if os_name == :linux
current_macos_version = if os_name.is_a?(Symbol) sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) }
MacOSVersion.from_symbol(os_name) def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type)
else return true if os_name == :linux
MacOS.version
end
success = T.let(true, T::Boolean) current_macos_version = if os_name.is_a?(Symbol)
tap.cask_files.each do |file| MacOSVersion.from_symbol(os_name)
cask = Cask::CaskLoader.load(file) else
MacOS.version
# Fine to have missing URLs for unsupported macOS
macos_req = cask.depends_on.macos
next if macos_req&.version && Array(macos_req.version).none? do |macos_version|
current_macos_version.compare(macos_req.comparator, macos_version)
end
raise "Missing URL" if cask.url.nil?
rescue Interrupt
raise
rescue Exception => e # rubocop:disable Lint/RescueException
os_and_arch = "macOS #{current_macos_version} on #{arch}"
onoe "Invalid cask (#{os_and_arch}): #{file}"
$stderr.puts e
success = false
end
success
end end
success = T.let(true, T::Boolean)
tap.cask_files.each do |file|
cask = Cask::CaskLoader.load(file)
# Fine to have missing URLs for unsupported macOS
macos_req = cask.depends_on.macos
next if macos_req&.version && Array(macos_req.version).none? do |macos_version|
current_macos_version.compare(macos_req.comparator, macos_version)
end
raise "Missing URL" if cask.url.nil?
rescue Interrupt
raise
rescue Exception => e # rubocop:disable Lint/RescueException
os_and_arch = "macOS #{current_macos_version} on #{arch}"
onoe "Invalid cask (#{os_and_arch}): #{file}"
$stderr.puts e
success = false
end
success
end end
end end
Readall.singleton_class.prepend(ReadallMac)

View File

@ -2,20 +2,17 @@
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
class SimulateSystem module SimulateSystemMac
class << self sig { returns(T::Boolean) }
undef simulating_or_running_on_macos? def simulating_or_running_on_macos?
undef current_os SimulateSystem.os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(SimulateSystem.os)
end
sig { returns(T::Boolean) } sig { returns(Symbol) }
def simulating_or_running_on_macos? def current_os
os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os) SimulateSystem.os || MacOS.version.to_sym
end
sig { returns(Symbol) }
def current_os
os || MacOS.version.to_sym
end
end end
end end
end end
Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::SimulateSystemMac)