Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge HeadVersion and NullVersion into Version. #15336

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/ast_constants.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: true
# frozen_string_literal: true

require "macos_versions"
require "macos_version"

FORMULA_COMPONENT_PRECEDENCE_LIST = [
[{ name: :include, type: :method_call }],
Expand Down Expand Up @@ -29,7 +29,7 @@
[{ name: :depends_on, type: :method_call }],
[{ name: :uses_from_macos, type: :method_call }],
[{ name: :on_macos, type: :block_call }],
*MacOSVersions::SYMBOLS.keys.map do |os_name|
*MacOSVersion::SYMBOLS.keys.map do |os_name|
[{ name: :"on_#{os_name}", type: :block_call }]
end,
[{ name: :on_system, type: :block_call }],
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ esac
# TODO: bump version when new macOS is released or announced
# and also update references in docs/Installation.md,
# https://github.com/Homebrew/install/blob/HEAD/install.sh and
# MacOSVersions::SYMBOLS
# MacOSVersion::SYMBOLS
HOMEBREW_MACOS_NEWEST_UNSUPPORTED="14"
# TODO: bump version when new macOS is released and also update
# references in docs/Installation.md and
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ def audit_livecheck_min_os
return if min_os.blank?

begin
min_os_string = OS::Mac::Version.new(min_os).strip_patch
rescue MacOSVersionError
min_os_string = MacOSVersion.new(min_os).strip_patch
rescue MacOSVersion::Error
return
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def to_hash_with_variations
begin
if @dsl.on_system_blocks_exist?
[:arm, :intel].each do |arch|
MacOSVersions::SYMBOLS.each_key do |os_name|
MacOSVersion::SYMBOLS.each_key do |os_name|
bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch)
next unless bottle_tag.valid_combination?

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ def load(config:)
dep_type = dep_value.keys.first
if dep_type == :==
version_symbols = dep_value[dep_type].map do |version|
MacOSVersions::SYMBOLS.key(version) || version
MacOSVersion::SYMBOLS.key(version) || version
end
next [dep_key, version_symbols]
end

version_symbol = dep_value[dep_type].first
version_symbol = MacOSVersions::SYMBOLS.key(version_symbol) || version_symbol
version_symbol = MacOSVersion::SYMBOLS.key(version_symbol) || version_symbol
[dep_key, "#{dep_type} :#{version_symbol}"]
end.compact
depends_on(**dep_hash)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def checksum
@checksum ||= cask.sha256 if cask.sha256 != :no_check
end

sig { override.returns(T.nilable(::Version)) }
sig { override.returns(T.nilable(Version)) }
def version
@version ||= ::Version.create(cask.version)
@version ||= Version.create(cask.version)
end

sig {
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/dsl/depends_on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def macos=(*args)
begin
@macos = if args.count > 1
MacOSRequirement.new([args], comparator: "==")
elsif MacOSVersions::SYMBOLS.key?(args.first)
elsif MacOSVersion::SYMBOLS.key?(args.first)
MacOSRequirement.new([args.first], comparator: "==")
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/.match(first_arg))
MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: md[:comparator])
Expand All @@ -68,7 +68,7 @@ def macos=(*args)
else # rubocop:disable Lint/DuplicateBranch
MacOSRequirement.new([args.first], comparator: "==")
end
rescue MacOSVersionError => e
rescue MacOSVersion::Error, TypeError => e
raise "invalid 'depends_on macos' value: #{e}"
end
end
Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/cask/macos.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: true
# frozen_string_literal: true

require "os/mac/version"

module OS
module Mac
module_function
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/dispatch-build-bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def dispatch_build_bottle
os, arch = element.then do |s|
tag = Utils::Bottles::Tag.from_symbol(s.to_sym)
[tag.to_macos_version, tag.arch]
rescue ArgumentError, MacOSVersionError
rescue ArgumentError, MacOSVersion::Error
os, arch = s.split("-", 2)
[MacOS::Version.new(os), arch&.to_sym]
[MacOSVersion.new(os), arch&.to_sym]
end

if arch.present? && arch != :x86_64
Expand Down
10 changes: 0 additions & 10 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,6 @@ def initialize(inner)
end
end

# Raised when a macOS version is unsupported.
class MacOSVersionError < RuntimeError
attr_reader :version

def initialize(version)
@version = version
super "unknown or unsupported macOS version: #{version.inspect}"
end
end

# Raised when `detected_perl_shebang` etc cannot detect the shebang.
class ShebangDetectionError < RuntimeError
def initialize(type, reason)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/extend/on_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ def self.arch_condition_met?(arch)
def self.os_condition_met?(os_name, or_condition = nil)
return Homebrew::SimulateSystem.send("simulating_or_running_on_#{os_name}?") if BASE_OS_OPTIONS.include?(os_name)

raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name)
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersion::SYMBOLS.key?(os_name)

if or_condition.present? && [:or_newer, :or_older].exclude?(or_condition)
raise ArgumentError, "Invalid OS `or_*` condition: #{or_condition.inspect}"
end

return false if Homebrew::SimulateSystem.simulating_or_running_on_linux?

base_os = OS::Mac::Version.from_symbol(os_name)
base_os = MacOSVersion.from_symbol(os_name)
current_os = if Homebrew::SimulateSystem.current_os == :macos
# Assume the oldest macOS version when simulating a generic macOS version
# Version::NULL is always treated as less than any other version.
Version::NULL
else
OS::Mac::Version.from_symbol(Homebrew::SimulateSystem.current_os)
MacOSVersion.from_symbol(Homebrew::SimulateSystem.current_os)
end

return current_os >= base_os if or_condition == :or_newer
Expand Down Expand Up @@ -115,7 +115,7 @@ def self.setup_base_os_methods(base)

sig { params(base: Class).void }
def self.setup_macos_methods(base)
MacOSVersions::SYMBOLS.each_key do |os_name|
MacOSVersion::SYMBOLS.each_key do |os_name|
base.define_method("on_#{os_name}") do |or_condition = nil, &block|
@on_system_blocks_exist = true

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def check_broken_sdks
path_version = sdk.path.basename.to_s[MacOS::SDK::VERSIONED_SDK_REGEX, 1]
next true if path_version.blank?

sdk.version == MacOS::Version.new(path_version).strip_patch
sdk.version == MacOSVersion.new(path_version).strip_patch
end

if locator.source == :clt
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Hardware
sig { params(version: T.nilable(Version)).returns(Symbol) }
def self.oldest_cpu(version = nil)
version = if version
MacOS::Version.new(version.to_s)
MacOSVersion.new(version.to_s)
else
MacOS.version
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def valid_casks?(casks, os_name: nil, arch: Hardware::CPU.type)
return true if os_name == :linux

current_macos_version = if os_name.is_a?(Symbol)
MacOS::Version.from_symbol(os_name)
MacOSVersion.from_symbol(os_name)
else
MacOS.version
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/simulate_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class << self

sig { returns(T::Boolean) }
def simulating_or_running_on_macos?
os.blank? || [:macos, *MacOSVersions::SYMBOLS.keys].include?(os)
os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os)
end

sig { returns(Symbol) }
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/extend/os/mac/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def find_matching_tag(tag, no_older_versions: false)
def find_older_compatible_tag(tag)
tag_version = begin
tag.to_macos_version
rescue MacOSVersionError
rescue MacOSVersion::Error
nil
end

Expand All @@ -45,7 +45,7 @@ def find_older_compatible_tag(tag)
next if candidate.arch != tag.arch

candidate.to_macos_version <= tag_version
rescue MacOSVersionError
rescue MacOSVersion::Error
false
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ def to_hash_with_variations

variations = {}

os_versions = [*MacOSVersions::SYMBOLS.keys, :linux]
os_versions = [*MacOSVersion::SYMBOLS.keys, :linux]

begin
if path.exist? && self.class.on_system_blocks_exist?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def audit_revision_and_version_scheme
newest_committed_revision ||= previous_revision
newest_committed_url ||= stable.url
end
rescue MacOSVersionError
rescue MacOSVersion::Error
break
end

Expand Down Expand Up @@ -893,7 +893,7 @@ def linux_only_gcc_dep?(formula)
# The formula has no variations, so all OS-version-arch triples depend on GCC.
return false if variations.blank?

MacOSVersions::SYMBOLS.each_key do |macos_version|
MacOSVersion::SYMBOLS.each_key do |macos_version|
[:arm, :intel].each do |arch|
bottle_tag = Utils::Bottles::Tag.new(system: macos_version, arch: arch)
next unless bottle_tag.valid_combination?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def self.load_formula(name, path, contents, namespace, flags:, ignore_errors:)
# access them from within the formula's class scope.
mod.const_set(:BUILD_FLAGS, flags)
mod.module_eval(contents, path)
rescue NameError, ArgumentError, ScriptError, MethodDeprecatedError, MacOSVersionError => e
rescue NameError, ArgumentError, ScriptError, MethodDeprecatedError, MacOSVersion::Error => e
if e.is_a?(Ignorable::ExceptionMixin)
e.ignore
else
Expand Down Expand Up @@ -223,7 +223,7 @@ def self.load_formula_from_api(name, flags:)
when :arch
req["version"]&.to_sym
when :macos, :maximum_macos
MacOSVersions::SYMBOLS.key(req["version"])
MacOSVersion::SYMBOLS.key(req["version"])
else
req["version"]
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/github_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GitHubRunner < T::Struct
const :platform, Symbol
const :arch, Symbol
const :spec, T.any(LinuxRunnerSpec, MacOSRunnerSpec)
const :macos_version, T.nilable(OS::Mac::Version)
const :macos_version, T.nilable(MacOSVersion)
prop :active, T::Boolean, default: false

sig { returns(T::Boolean) }
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def linux_runner_spec
platform: Symbol,
arch: Symbol,
spec: RunnerSpec,
macos_version: T.nilable(OS::Mac::Version),
macos_version: T.nilable(MacOSVersion),
).returns(GitHubRunner)
}
def create_runner(platform, arch, spec, macos_version = nil)
Expand Down Expand Up @@ -120,8 +120,8 @@ def generate_runners!
ephemeral_suffix << "-deps" if @dependent_matrix
ephemeral_suffix.freeze

MacOSVersions::SYMBOLS.each_value do |version|
macos_version = OS::Mac::Version.new(version)
MacOSVersion::SYMBOLS.each_value do |version|
macos_version = MacOSVersion.new(version)
next if macos_version.unsupported_release?

# Intel Big Sur is a bit slower than the other runners,
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

require "extend/module"
require "env_config"
require "macos_versions"
require "macos_version"
require "os"
require "messages"
require "default_prefix"
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module Language
# @api public
module Python
def self.major_minor_version(python)
version = /\d\.\d+/.match `#{python} --version 2>&1`
version = `#{python} --version 2>&1`.chomp[/(\d\.\d+)/, 1]
return unless version

Version.create(version.to_s)
Version.new(version)
end

def self.homebrew_site_packages(python = "python3.7")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ def resource_version(
end
end

res_current = resource.version
res_current = T.must(resource.version)
res_latest = Version.new(match_version_map.values.max_by { |v| LivecheckVersion.create(resource, v) })

return status_hash(resource, "error", ["Unable to get versions"], verbose: verbose) if res_latest.blank?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/livecheck/strategy/sparkle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def self.items_from_content(content)

if (minimum_system_version = item.elements["minimumSystemVersion"]&.text&.gsub(/\A\D+|\D+\z/, ""))
macos_minimum_system_version = begin
OS::Mac::Version.new(minimum_system_version).strip_patch
rescue MacOSVersionError
MacOSVersion.new(minimum_system_version).strip_patch
rescue MacOSVersion::Error
nil
end

Expand Down
Loading