Class: MacOSRequirement Private

Inherits:
Requirement show all
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

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

Attributes inherited from Requirement

#cask, #download, #name, #tags

Instance Method Summary collapse

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

#env, #inherited

Methods included from Cachable

#cache, #clear_cache

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

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.

Parameters:

  • tags (T.untyped) (defaults to: [])
  • comparator (String) (defaults to: ">=")


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'requirements/macos_requirement.rb', line 27

def initialize(tags = [], comparator: ">=")
  @version = T.let(begin
    if comparator == "==" && tags.first.respond_to?(:map)
      tags.first.map { |s| MacOSVersion.from_symbol(s) }
    else
      MacOSVersion.from_symbol(tags.first) unless tags.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 tags.first.respond_to?(:reject)
      tags = [tags.first.reject { |s| s == e.version }, tags[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(tags.drop(1))
end

Instance Attribute Details

#comparatorString (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.

Returns:



11
12
13
# File 'requirements/macos_requirement.rb', line 11

def comparator
  @comparator
end

#versionMacOSVersion, ... (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.

Returns:



14
15
16
# File 'requirements/macos_requirement.rb', line 14

def version
  @version
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.

Parameters:

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'requirements/macos_requirement.rb', line 90

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_sString

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.

Returns:



151
152
153
154
155
156
157
158
159
160
161
# File 'requirements/macos_requirement.rb', line 151

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_versionMacOSVersion?

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.

Returns:



82
83
84
85
86
87
# File 'requirements/macos_requirement.rb', line 82

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.

Parameters:

  • type (Symbol) (defaults to: :formula)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'requirements/macos_requirement.rb', line 105

def message(type: :formula)
  return "macOS is required for this software." unless version_specified?

  version = @version
  case @comparator
  when ">="
    "This software does not run on macOS versions older than #{T.cast(version, MacOSVersion).pretty_name}."
  when "<="
    case type
    when :formula
      <<~EOS
        This formula 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
      "This cask 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 "This software does not run on macOS versions other than #{versions.join(", ")} and #{last}."
    end

    "This software does not run on macOS versions other than #{T.cast(version, MacOSVersion).pretty_name}."
  end
end

#minimum_versionMacOSVersion?

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.

Returns:



74
75
76
77
78
79
# File 'requirements/macos_requirement.rb', line 74

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_hHash{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.

Returns:



164
165
166
167
168
169
# File 'requirements/macos_requirement.rb', line 164

def to_h
  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.

Parameters:

  • options (T.untyped)

Returns:



172
173
174
# File 'requirements/macos_requirement.rb', line 172

def to_json(options)
  to_h.to_json(options)
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.

Returns:

  • (Boolean)


60
61
62
# File 'requirements/macos_requirement.rb', line 60

def version_specified?
  @version.present?
end