Class: MacOSRequirement Private
- Inherits:
-
Requirement
- Object
- Requirement
- MacOSRequirement
- Extended by:
- Utils::Output::Mixin
- Defined in:
- requirements/macos_requirement.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
A requirement on macOS.
Constant Summary collapse
- Cache =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
type_template { { fixed: T::Hash[String, T.untyped] } }
- DISABLED_MACOS_VERSIONS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Keep these around as empty arrays so we can keep the deprecation/disabling code the same. Treat these like odeprecated/odisabled in terms of deprecation/disabling.
T.let([ :mojave, :high_sierra, :sierra, :el_capitan, ].freeze, T::Array[Symbol])
- DEPRECATED_MACOS_VERSIONS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let([].freeze, T::Array[Symbol])
Constants included from Dependable
Dependable::KEEP_BUT_PRUNE_RECURSIVE_DEPS, Dependable::PRUNE, Dependable::RESERVED_TAGS, Dependable::SKIP
Instance Attribute Summary collapse
- #comparator ⇒ String readonly private
- #version ⇒ MacOSVersion, ... readonly private
Attributes inherited from Requirement
#cask, #download, #name, #tags
Class Method Summary collapse
Instance Method Summary collapse
- #allows?(other) ⇒ Boolean private
- #display_s ⇒ String private
- #initialize(tags = [], comparator: ">=") ⇒ void constructor private
- #maximum_version ⇒ MacOSVersion? private
- #message(type: :formula) ⇒ String private
- #minimum_version ⇒ MacOSVersion? private
- #to_h ⇒ Hash{String => Array<String>} private
- #to_json(options) ⇒ String private
- #version_specified? ⇒ Boolean private
Methods included from Utils::Output::Mixin
issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_uninstalled, pretty_upgradable
Methods inherited from Requirement
cask, download, #env, env, #env_proc, expand, fatal, #fatal?, inherited, #mktemp, #modify_build_environment, #option_names, prune?, #satisfied?, #satisfied_result_parent, satisfy, #tap, #which
Methods included from BuildEnvironment::DSL
Methods included from Cachable
Methods included from Dependable
#build?, #implicit?, #no_linkage?, #option_names, #option_tags, #optional?, #options, #prune_from_option?, #prune_if_build_and_not_dependent?, #recommended?, #required?, #tags, #test?
Constructor Details
#initialize(tags = [], comparator: ">=") ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'requirements/macos_requirement.rb', line 63 def initialize( = [], comparator: ">=") @version = T.let(begin if comparator == "==" && .first.respond_to?(:map) .first.map { |s| MacOSVersion.from_symbol(s) } else MacOSVersion.from_symbol(.first) unless .empty? end rescue MacOSVersion::Error => e if DISABLED_MACOS_VERSIONS.include?(e.version) # This odisabled should stick around indefinitely. odisabled "`depends_on macos: :#{e.version}`" elsif DEPRECATED_MACOS_VERSIONS.include?(e.version) # This odeprecated should stick around indefinitely. odeprecated "`depends_on macos: :#{e.version}`" else raise end # Array of versions: remove the bad ones and try again. if .first.respond_to?(:reject) = [.first.reject { |s| s == e.version }, [1..]] retry end # Otherwise fallback to the oldest allowed if comparator is >=. MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) if comparator == ">=" end, T.nilable(T.any(MacOSVersion, T::Array[MacOSVersion]))) @comparator = T.let(comparator, String) super(.drop(1)) end |
Instance Attribute Details
#comparator ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
19 20 21 |
# File 'requirements/macos_requirement.rb', line 19 def comparator @comparator end |
#version ⇒ MacOSVersion, ... (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
22 23 24 |
# File 'requirements/macos_requirement.rb', line 22 def version @version end |
Class Method Details
.parse(args, comparator:) ⇒ MacOSRequirement
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'requirements/macos_requirement.rb', line 35 def self.parse(args, comparator:) first_arg = args.first first_arg_s = first_arg&.to_s if first_arg == :any new elsif args.count > 1 new([args], comparator: "==") elsif first_arg.is_a?(Symbol) && MacOSVersion::SYMBOLS.key?(first_arg) new([first_arg], comparator:) elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/.match(first_arg_s)) replacement = if md[:comparator] == "<=" "`depends_on maximum_macos: :#{md[:version]}`" elsif md[:comparator] == ">=" "`depends_on macos: :#{md[:version]}`" end odeprecated "string comparison format for `depends_on macos:`", replacement new([T.must(md[:version]).to_sym], comparator: T.must(md[:comparator])) elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*(?<version>\S+)\s*$/.match(first_arg_s)) odeprecated "string comparison format for `depends_on macos:`" new([md[:version]], comparator: T.must(md[:comparator])) else odeprecated "strict symbol format for `depends_on macos:`" new([first_arg], comparator: "==") end end |
Instance Method Details
#allows?(other) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'requirements/macos_requirement.rb', line 126 def allows?(other) return true unless version_specified? version = @version case @comparator when ">=" then other >= T.cast(version, MacOSVersion) when "<=" then other <= T.cast(version, MacOSVersion) else return T.unsafe(version).include?(other) if version.respond_to?(:to_ary) || version.is_a?(Array) version == other end end |
#display_s ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
189 190 191 192 193 194 195 196 197 198 199 |
# File 'requirements/macos_requirement.rb', line 189 def display_s if version_specified? if @version.respond_to?(:to_ary) || @version.is_a?(Array) "macOS #{@comparator} #{T.unsafe(@version).join(" / ")} (or Linux)" else "macOS #{@comparator} #{@version} (or Linux)" end else "macOS" end end |
#maximum_version ⇒ MacOSVersion?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
118 119 120 121 122 123 |
# File 'requirements/macos_requirement.rb', line 118 def maximum_version return MacOSVersion.new(HOMEBREW_MACOS_NEWEST_UNSUPPORTED) if @comparator == ">=" || !version_specified? return T.unsafe(@version).max if @version.respond_to?(:to_ary) || @version.is_a?(Array) @version end |
#message(type: :formula) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'requirements/macos_requirement.rb', line 141 def (type: :formula) subject = (type == :cask) ? "This cask" : "This formula" return "#{subject} requires macOS." unless version_specified? version = @version case @comparator when ">=" "#{subject} does not run on macOS versions older than #{T.cast(version, MacOSVersion).pretty_name}." when "<=" case type when :formula <<~EOS #{subject} either does not compile or function as expected on macOS versions newer than #{T.cast(version, MacOSVersion).pretty_name} due to an upstream incompatibility. EOS when :cask "#{subject} does not run on macOS versions newer than #{T.cast(version, MacOSVersion).pretty_name}." else "" end else if version.respond_to?(:to_ary) || version.is_a?(Array) *versions, last = T.unsafe(version).map(&:pretty_name) return "#{subject} does not run on macOS versions other than #{versions.join(", ")} and #{last}." end "#{subject} does not run on macOS versions other than #{T.cast(version, MacOSVersion).pretty_name}." end end |
#minimum_version ⇒ MacOSVersion?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
110 111 112 113 114 115 |
# File 'requirements/macos_requirement.rb', line 110 def minimum_version return MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) if @comparator == "<=" || !version_specified? return T.unsafe(@version).min if @version.respond_to?(:to_ary) || @version.is_a?(Array) @version end |
#to_h ⇒ Hash{String => Array<String>}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
202 203 204 205 206 207 208 209 |
# File 'requirements/macos_requirement.rb', line 202 def to_h return {} unless version_specified? comp = @comparator.to_s return { comp => @version.map(&:to_s) } if @version.is_a?(Array) { comp => [@version.to_s] } end |
#to_json(options) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
212 213 214 |
# File 'requirements/macos_requirement.rb', line 212 def to_json() to_h.to_json() end |
#version_specified? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
96 97 98 |
# File 'requirements/macos_requirement.rb', line 96 def version_specified? @version.present? end |