Create MacOSVersions module
This commit is contained in:
parent
5ec19adf58
commit
ac067eedb2
@ -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)
|
||||
|
||||
|
||||
@ -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*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/ =~ args.first
|
||||
MacOSRequirement.new([version.to_sym], comparator: comparator)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
20
Library/Homebrew/macos_versions.rb
Normal file
20
Library/Homebrew/macos_versions.rb
Normal file
@ -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
|
||||
@ -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.
|
||||
|
||||
@ -8,6 +8,8 @@ module OS
|
||||
|
||||
module_function
|
||||
|
||||
::MacOS = OS::Mac
|
||||
|
||||
sig { returns(String) }
|
||||
def os_version
|
||||
if which("lsb_release")
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) }
|
||||
|
||||
@ -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) }
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user