Files
brew/Library/Homebrew/extend/os/mac/utils/bottles.rb
T
Mike McQuaid 204ea7e964 Make tests use public APIs and enable their cops
- Make every statically-poked method public and call it directly,
  keeping `public_send` only for dynamically-named public methods.
- Read and write state through public `attr_*` accessors instead of
  instance variable reflection.
- Enable `Homebrew/NoSendInTests` and
  `Homebrew/NoInstanceVariableAccessInTests` now the test suite is
  clean, so neither pattern creeps back in.
- Keep rare justified disables, e.g. `Module#remove_const` is
  private core Ruby and raw memoisation state has no accessor.
2026-07-27 08:11:46 +01:00

67 lines
1.9 KiB
Ruby

# typed: strict
# frozen_string_literal: true
module OS
module Mac
module Bottles
module ClassMethods
sig { params(tag: T.nilable(T.any(Symbol, Utils::Bottles::Tag))).returns(Utils::Bottles::Tag) }
def tag(tag = nil)
if tag.nil?
Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: ::Hardware::CPU.arch)
else
super
end
end
end
module Collector
extend T::Helpers
requires_ancestor { Utils::Bottles::Collector }
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?)
super(tag)
else
super(tag) || find_older_compatible_tag(tag)
end
end
private
# Find a bottle built for a previous version of macOS.
sig { params(tag: Utils::Bottles::Tag).returns(T.nilable(Utils::Bottles::Tag)) }
def find_older_compatible_tag(tag)
tag_version = begin
tag.to_macos_version
rescue MacOSVersion::Error
nil
end
return if tag_version.blank?
tags.find do |candidate|
next if candidate.standardized_arch != tag.standardized_arch
candidate.to_macos_version <= tag_version
rescue MacOSVersion::Error
false
end
end
end
end
end
end
Utils::Bottles.singleton_class.prepend(OS::Mac::Bottles::ClassMethods)
Utils::Bottles::Collector.prepend(OS::Mac::Bottles::Collector)