diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 709a84e77f..648cd3aa71 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -19,9 +19,6 @@ module Homebrew sig { returns(T::Array[String]) } attr_reader :options_only, :flags_only - # undefine tap to allow --tap argument - undef tap - sig { void } def initialize require "cli/named_args" diff --git a/Library/Homebrew/extend/os/linux/cleanup.rb b/Library/Homebrew/extend/os/linux/cleanup.rb index b6cd428fe8..deb231b318 100644 --- a/Library/Homebrew/extend/os/linux/cleanup.rb +++ b/Library/Homebrew/extend/os/linux/cleanup.rb @@ -2,8 +2,10 @@ # frozen_string_literal: true module Homebrew - class Cleanup - undef use_system_ruby? + module CleanupLinux + extend T::Helpers + + requires_ancestor { Cleanup } sig { returns(T::Boolean) } def use_system_ruby? @@ -21,3 +23,5 @@ module Homebrew end end end + +Homebrew::Cleanup.prepend(Homebrew::CleanupLinux) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index a6914a1f02..2d6250f816 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -1,12 +1,10 @@ # typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true -class Formula - undef shared_library - undef loader_path - undef deuniversalize_machos - undef add_global_deps_to_spec - undef valid_platform? +module FormulaLinux + extend T::Helpers + + requires_ancestor { Formula } sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } def shared_library(name, version = nil) @@ -50,3 +48,5 @@ class Formula requirements.none?(MacOSRequirement) end end + +Formula.prepend(FormulaLinux) diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index 7d81e2dddc..37f8481e18 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -1,16 +1,19 @@ -# typed: strict +# typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true module Homebrew module CLI - class Parser - undef set_default_options - undef validate_options + module ParserLinux + extend T::Helpers + requires_ancestor { Homebrew::CLI::Parser } + + sig { void } def set_default_options @args["formula?"] = true if @args.respond_to?(:formula?) end + sig { void } def validate_options return unless @args.respond_to?(:cask?) return unless @args.cask? @@ -22,3 +25,5 @@ module Homebrew end end end + +Homebrew::CLI::Parser.prepend(Homebrew::CLI::ParserLinux) diff --git a/Library/Homebrew/extend/os/mac/cleaner.rb b/Library/Homebrew/extend/os/mac/cleaner.rb index 460169c996..23cdfbf947 100644 --- a/Library/Homebrew/extend/os/mac/cleaner.rb +++ b/Library/Homebrew/extend/os/mac/cleaner.rb @@ -1,13 +1,13 @@ # typed: strict # frozen_string_literal: true -class Cleaner +module CleanerMac private - undef executable_path? - sig { params(path: Pathname).returns(T::Boolean) } def executable_path?(path) path.mach_o_executable? || path.text_executable? end end + +Cleaner.prepend(CleanerMac) diff --git a/Library/Homebrew/extend/os/mac/cleanup.rb b/Library/Homebrew/extend/os/mac/cleanup.rb index 3565e162b4..8c07923e09 100644 --- a/Library/Homebrew/extend/os/mac/cleanup.rb +++ b/Library/Homebrew/extend/os/mac/cleanup.rb @@ -2,9 +2,7 @@ # frozen_string_literal: true module Homebrew - class Cleanup - undef use_system_ruby? - + module CleanupMac sig { returns(T::Boolean) } def use_system_ruby? return false if Homebrew::EnvConfig.force_vendor_ruby? @@ -13,3 +11,5 @@ module Homebrew end end end + +Homebrew::Cleanup.prepend(Homebrew::CleanupMac) diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb index 26d96cc1ce..1c3ad6a7f9 100644 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -3,9 +3,7 @@ module Homebrew module DevCmd - class Bottle < AbstractCommand - undef tar_args - + module BottleMac sig { returns(T::Array[String]) } def tar_args if MacOS.version >= :catalina @@ -15,8 +13,6 @@ module Homebrew end end - undef gnu_tar - sig { params(gnu_tar_formula: Formula).returns(String) } def gnu_tar(gnu_tar_formula) "#{gnu_tar_formula.opt_bin}/gtar" @@ -24,3 +20,5 @@ module Homebrew end end end + +Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac) diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index c32a41d9e3..0aedbc9cab 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -1,9 +1,10 @@ # typed: strict # frozen_string_literal: true -class Formula - undef valid_platform? - undef std_cmake_args +module FormulaMac + extend T::Helpers + + requires_ancestor { Formula } sig { returns(T::Boolean) } def valid_platform? @@ -31,3 +32,5 @@ class Formula args end end + +Formula.prepend(FormulaMac) diff --git a/Library/Homebrew/extend/os/mac/formula_installer.rb b/Library/Homebrew/extend/os/mac/formula_installer.rb index 89115c871d..fe825f7221 100644 --- a/Library/Homebrew/extend/os/mac/formula_installer.rb +++ b/Library/Homebrew/extend/os/mac/formula_installer.rb @@ -1,8 +1,10 @@ # typed: strict # frozen_string_literal: true -class FormulaInstaller - undef fresh_install? +module FormulaInstallerMac + extend T::Helpers + + requires_ancestor { FormulaInstaller } sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } def fresh_install?(formula) @@ -10,3 +12,5 @@ class FormulaInstaller (!installed_as_dependency? || !formula.any_version_installed?) end end + +FormulaInstaller.prepend(FormulaInstallerMac) diff --git a/Library/Homebrew/extend/os/mac/linkage_checker.rb b/Library/Homebrew/extend/os/mac/linkage_checker.rb index b48d2b90d3..1171257479 100644 --- a/Library/Homebrew/extend/os/mac/linkage_checker.rb +++ b/Library/Homebrew/extend/os/mac/linkage_checker.rb @@ -1,9 +1,7 @@ # typed: strict # frozen_string_literal: true -class LinkageChecker - undef system_libraries_exist_in_cache? - +module LinkageCheckerMac private sig { returns(T::Boolean) } @@ -12,3 +10,5 @@ class LinkageChecker MacOS.version >= :big_sur end end + +LinkageChecker.prepend(LinkageCheckerMac) diff --git a/Library/Homebrew/extend/os/mac/readall.rb b/Library/Homebrew/extend/os/mac/readall.rb index 6957c2b086..15a78a78fe 100644 --- a/Library/Homebrew/extend/os/mac/readall.rb +++ b/Library/Homebrew/extend/os/mac/readall.rb @@ -1,39 +1,42 @@ # typed: strict # frozen_string_literal: true -module Readall - class << self - undef valid_casks? +module ReadallMac + extend T::Helpers - def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) - return true if os_name == :linux + requires_ancestor { Kernel } - current_macos_version = if os_name.is_a?(Symbol) - MacOSVersion.from_symbol(os_name) - else - MacOS.version - end + sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } + def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) + return true if os_name == :linux - 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 + current_macos_version = if os_name.is_a?(Symbol) + MacOSVersion.from_symbol(os_name) + else + MacOS.version 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 + +Readall.singleton_class.prepend(ReadallMac) diff --git a/Library/Homebrew/extend/os/mac/simulate_system.rb b/Library/Homebrew/extend/os/mac/simulate_system.rb index 95bc2ef9ae..aacc269202 100644 --- a/Library/Homebrew/extend/os/mac/simulate_system.rb +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -2,20 +2,17 @@ # frozen_string_literal: true module Homebrew - class SimulateSystem - class << self - undef simulating_or_running_on_macos? - undef current_os + module SimulateSystemMac + sig { returns(T::Boolean) } + def simulating_or_running_on_macos? + SimulateSystem.os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(SimulateSystem.os) + end - sig { returns(T::Boolean) } - def simulating_or_running_on_macos? - os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os) - end - - sig { returns(Symbol) } - def current_os - os || MacOS.version.to_sym - end + sig { returns(Symbol) } + def current_os + SimulateSystem.os || MacOS.version.to_sym end end end + +Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::SimulateSystemMac)