brew/Library/Homebrew/requirements/macos_requirement.rb

90 lines
2.2 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
require "requirement"
2020-08-19 06:51:15 +02:00
# A requirement on macOS.
#
# @api private
class MacOSRequirement < Requirement
2020-10-20 12:03:48 +02:00
extend T::Sig
fatal true
attr_reader :comparator, :version
def initialize(tags = [], comparator: ">=")
@version = if comparator == "==" && tags.first.respond_to?(:map)
tags.shift.map { |s| MacOS::Version.from_symbol(s) }
else
MacOS::Version.from_symbol(tags.shift) unless tags.empty?
2019-08-15 10:14:10 +02:00
end
@comparator = comparator
super(tags)
end
def version_specified?
2017-02-25 10:17:25 -08:00
OS.mac? && @version
end
satisfy(build_env: false) do
2020-07-13 22:48:53 +10:00
next Array(@version).any? { |v| MacOS.version.public_send(@comparator, v) } if version_specified?
2017-02-25 10:17:25 -08:00
next true if OS.mac?
next true if @version
2018-09-17 02:45:00 +02:00
2017-02-25 10:17:25 -08:00
false
end
2019-08-15 10:14:10 +02:00
def message(type: :formula)
return "macOS is required for this software." unless version_specified?
case @comparator
when ">="
"macOS #{@version.pretty_name} or newer is required for this software."
when "<="
2019-08-15 10:14:10 +02:00
case type
when :formula
<<~EOS
This formula either does not compile or function as expected on macOS
versions newer than #{@version.pretty_name} due to an upstream incompatibility.
EOS
when :cask
2019-08-30 14:11:13 -04:00
"This cask does not run on macOS versions newer than #{@version.pretty_name}."
2019-08-15 10:14:10 +02:00
end
else
2019-08-15 10:14:10 +02:00
if @version.respond_to?(:to_ary)
2019-08-30 14:11:13 -04:00
*versions, last = @version.map(&:pretty_name)
return "macOS #{versions.join(", ")} or #{last} is required for this software."
2019-08-15 10:14:10 +02:00
end
"macOS #{@version.pretty_name} is required for this software."
end
end
2020-10-20 12:03:48 +02:00
sig { returns(String) }
def inspect
"#<#{self.class.name}: version#{@comparator}#{@version.to_s.inspect} #{tags.inspect}>"
end
2020-10-20 12:03:48 +02:00
sig { returns(String) }
def display_s
if version_specified?
if @version.respond_to?(:to_ary)
"macOS #{@comparator} #{version.join(" / ")}"
else
"macOS #{@comparator} #{@version}"
end
else
"macOS"
end
end
2019-08-30 14:11:13 -04:00
def to_json(*args)
comp = @comparator.to_s
return { comp => @version.map(&:to_s) }.to_json(*args) if @version.is_a?(Array)
{ comp => [@version.to_s] }.to_json(*args)
end
end