Skip to content

Commit

Permalink
Replace undef with prepended modules
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Sep 11, 2024
1 parent 44a34af commit c07f515
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 76 deletions.
3 changes: 0 additions & 3 deletions Library/Homebrew/cli/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class Args < OpenStruct
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"
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/extend/os/linux/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -21,3 +23,5 @@ def use_system_ruby?
end
end
end

Homebrew::Cleanup.prepend(Homebrew::CleanupLinux)
12 changes: 6 additions & 6 deletions Library/Homebrew/extend/os/linux/formula.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -50,3 +48,5 @@ def valid_platform?
requirements.none?(MacOSRequirement)
end
end

Formula.prepend(FormulaLinux)
13 changes: 9 additions & 4 deletions Library/Homebrew/extend/os/linux/parser.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -22,3 +25,5 @@ def validate_options
end
end
end

Homebrew::CLI::Parser.prepend(Homebrew::CLI::ParserLinux)
6 changes: 3 additions & 3 deletions Library/Homebrew/extend/os/mac/cleaner.rb
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions Library/Homebrew/extend/os/mac/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -13,3 +11,5 @@ def use_system_ruby?
end
end
end

Homebrew::Cleanup.prepend(Homebrew::CleanupMac)
8 changes: 3 additions & 5 deletions Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,12 +13,12 @@ def tar_args
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"
end
end
end
end

Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac)
9 changes: 6 additions & 3 deletions Library/Homebrew/extend/os/mac/formula.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -31,3 +32,5 @@ def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework
args
end
end

Formula.prepend(FormulaMac)
8 changes: 6 additions & 2 deletions Library/Homebrew/extend/os/mac/formula_installer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# 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)
!Homebrew::EnvConfig.developer? && !OS::Mac.version.outdated_release? &&
(!installed_as_dependency? || !formula.any_version_installed?)
end
end

FormulaInstaller.prepend(FormulaInstallerMac)
6 changes: 3 additions & 3 deletions Library/Homebrew/extend/os/mac/linkage_checker.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand All @@ -12,3 +10,5 @@ def system_libraries_exist_in_cache?
MacOS.version >= :big_sur
end
end

LinkageChecker.prepend(LinkageCheckerMac)
61 changes: 32 additions & 29 deletions Library/Homebrew/extend/os/mac/readall.rb
Original file line number Diff line number Diff line change
@@ -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

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
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
success

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)
23 changes: 10 additions & 13 deletions Library/Homebrew/extend/os/mac/simulate_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
# frozen_string_literal: true

module Homebrew
class SimulateSystem
class << self
undef simulating_or_running_on_macos?
undef current_os

sig { returns(T::Boolean) }
def simulating_or_running_on_macos?
os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os)
end
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(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)

0 comments on commit c07f515

Please sign in to comment.