diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 90f5e756c0..c30dfa7c22 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -94,7 +94,7 @@ module Cask version_os_hash = {} actual_version = MacOS.full_version.to_s - MacOS::Version::SYMBOLS.each do |os_name, os_version| + MacOSVersions::SYMBOLS.each do |os_name, os_version| MacOS.full_version = os_version cask = CaskLoader.load(token) version_os_hash[os_name] = cask.version if cask.version != version @@ -251,7 +251,7 @@ module Cask if @dsl.on_system_blocks_exist? [:arm, :intel].each do |arch| - MacOS::Version::SYMBOLS.each_key do |os_name| + MacOSVersions::SYMBOLS.each_key do |os_name| # Big Sur is the first version of macOS that supports arm next if arch == :arm && MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur) diff --git a/Library/Homebrew/cask/dsl/depends_on.rb b/Library/Homebrew/cask/dsl/depends_on.rb index d7ac942dfd..1d4e3a2448 100644 --- a/Library/Homebrew/cask/dsl/depends_on.rb +++ b/Library/Homebrew/cask/dsl/depends_on.rb @@ -55,7 +55,7 @@ module Cask begin @macos = if args.count > 1 MacOSRequirement.new([args], comparator: "==") - elsif MacOS::Version::SYMBOLS.key?(args.first) + elsif MacOSVersions::SYMBOLS.key?(args.first) MacOSRequirement.new([args.first], comparator: "==") elsif /^\s*(?<|>|[=<>]=)\s*:(?\S+)\s*$/ =~ args.first MacOSRequirement.new([version.to_sym], comparator: comparator) diff --git a/Library/Homebrew/extend/on_system.rb b/Library/Homebrew/extend/on_system.rb index 5490149e68..e008a6feca 100644 --- a/Library/Homebrew/extend/on_system.rb +++ b/Library/Homebrew/extend/on_system.rb @@ -23,7 +23,7 @@ module OnSystem def os_condition_met?(os_name, or_condition = nil) if Homebrew::EnvConfig.simulate_macos_on_linux? return false if os_name == :linux - return true if [:macos, *MacOS::Version::SYMBOLS.keys].include?(os_name) + return true if [:macos, *MacOSVersions::SYMBOLS.keys].include?(os_name) end if BASE_OS_OPTIONS.include?(os_name) @@ -35,7 +35,7 @@ module OnSystem return Homebrew::SimulateSystem.send("#{os_name}?") end - raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOS::Version::SYMBOLS.key?(os_name) + raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name) if or_condition.present? && [:or_newer, :or_older].exclude?(or_condition) raise ArgumentError, "Invalid OS `or_*` condition: #{or_condition.inspect}" @@ -87,7 +87,7 @@ module OnSystem end end - MacOS::Version::SYMBOLS.each_key do |os_name| + MacOSVersions::SYMBOLS.each_key do |os_name| onto.define_method("on_#{os_name}") do |or_condition = nil, &block| @on_system_blocks_exist = true diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 08a898c3aa..1a11464f69 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -72,6 +72,7 @@ HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/. require "env_config" require "compat/early" unless Homebrew::EnvConfig.no_compat? +require "macos_versions" require "os" require "messages" require "default_prefix" diff --git a/Library/Homebrew/macos_versions.rb b/Library/Homebrew/macos_versions.rb new file mode 100644 index 0000000000..16d4bd47e4 --- /dev/null +++ b/Library/Homebrew/macos_versions.rb @@ -0,0 +1,20 @@ +# typed: true +# frozen_string_literal: true + +# Helper functions for querying operating system information. +# +# @api private +module MacOSVersions + # TODO: when removing symbols here, ensure that they are added to + # DEPRECATED_MACOS_VERSIONS in MacOSRequirement. + SYMBOLS = { + ventura: "13", + monterey: "12", + big_sur: "11", + catalina: "10.15", + mojave: "10.14", + high_sierra: "10.13", + sierra: "10.12", + el_capitan: "10.11", + }.freeze +end diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index b2d6c64cad..3152c91389 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -50,25 +50,6 @@ module OS CI_GLIBC_VERSION = "2.23" CI_OS_VERSION = "Ubuntu 16.04" - module Mac - ::MacOS = OS::Mac - - class Version < ::Version - # TODO: when removing symbols here, ensure that they are added to - # DEPRECATED_MACOS_VERSIONS in MacOSRequirement. - SYMBOLS = { - ventura: "13", - monterey: "12", - big_sur: "11", - catalina: "10.15", - mojave: "10.14", - high_sierra: "10.13", - sierra: "10.12", - el_capitan: "10.11", - }.freeze - end - end - if OS.mac? require "os/mac" # Don't tell people to report issues on unsupported configurations. diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index 57598261ef..c8fcc00e52 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -8,6 +8,8 @@ module OS module_function + ::MacOS = OS::Mac + sig { returns(String) } def os_version if which("lsb_release") diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index b23e62dd8b..5f422450e9 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -13,6 +13,8 @@ module OS module_function + ::MacOS = OS::Mac + raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"] VERSION = ENV.fetch("HOMEBREW_MACOS_VERSION").chomp.freeze diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index a7d183eaef..a460141c50 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -30,7 +30,7 @@ module OS sig { params(version: Symbol).returns(T.attached_class) } def self.from_symbol(version) - str = SYMBOLS.fetch(version) { raise MacOSVersionError, version } + str = MacOSVersions::SYMBOLS.fetch(version) { raise MacOSVersionError, version } new(str) end @@ -48,10 +48,10 @@ module OS sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) @comparison_cache.fetch(other) do - if SYMBOLS.key?(other) && to_sym == other + if MacOSVersions::SYMBOLS.key?(other) && to_sym == other 0 else - v = SYMBOLS.fetch(other) { other.to_s } + v = MacOSVersions::SYMBOLS.fetch(other) { other.to_s } @comparison_cache[other] = super(::Version.new(v)) end end @@ -69,7 +69,7 @@ module OS sig { returns(Symbol) } def to_sym - @to_sym ||= SYMBOLS.invert.fetch(strip_patch.to_s, :dunno) + @to_sym ||= MacOSVersions::SYMBOLS.invert.fetch(strip_patch.to_s, :dunno) end sig { returns(String) } diff --git a/Library/Homebrew/simulate_system.rb b/Library/Homebrew/simulate_system.rb index 12d1e0e34d..d52a2af752 100644 --- a/Library/Homebrew/simulate_system.rb +++ b/Library/Homebrew/simulate_system.rb @@ -13,7 +13,7 @@ module Homebrew sig { params(new_os: Symbol).void } def os=(new_os) - os_options = [:macos, :linux, *MacOS::Version::SYMBOLS.keys] + os_options = [:macos, :linux, *MacOSVersions::SYMBOLS.keys] raise "Unknown OS: #{new_os}" unless os_options.include?(new_os) @os = new_os @@ -38,7 +38,7 @@ module Homebrew sig { returns(T::Boolean) } def macos? - [:macos, *MacOS::Version::SYMBOLS.keys].include?(@os) + [:macos, *MacOSVersions::SYMBOLS.keys].include?(@os) end sig { returns(T::Boolean) } diff --git a/Library/Homebrew/test/cask/cmd/list_spec.rb b/Library/Homebrew/test/cask/cmd/list_spec.rb index 6c0e3db2ff..77b6e7af89 100644 --- a/Library/Homebrew/test/cask/cmd/list_spec.rb +++ b/Library/Homebrew/test/cask/cmd/list_spec.rb @@ -256,7 +256,7 @@ describe Cask::Cmd::List, :cask do catalina: "10.15", mojave: "10.14", } - stub_const("MacOS::Version::SYMBOLS", symbols) + stub_const("MacOSVersions::SYMBOLS", symbols) # For consistency, always run on Monterey and ARM MacOS.full_version = "12"