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.

TODO:

when Yosemite is removed here, keep these around as empty arrays so we

can keep the deprecation/disabling code the same.

[
  :yosemite,
].freeze
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.

[].freeze

Constants included from Dependable

Dependable::RESERVED_TAGS

Instance Attribute Summary collapse

Attributes inherited from Requirement

#cask, #download, #name

Attributes included from Dependable

#tags

Instance Method Summary collapse

Methods inherited from Requirement

cask, download, #env, env, #env_proc, expand, fatal, #fatal?, #mktemp, #modify_build_environment, #option_names, prune, prune?, #satisfied?, #satisfied_result_parent, satisfy

Methods included from BuildEnvironment::DSL

#env, #inherited

Methods included from Cachable

#cache, #clear_cache

Methods included from Attrable

#attr_predicate, #attr_rw

Methods included from Dependable

#build?, #implicit?, #option_tags, #optional?, #options, #prune_from_option?, #prune_if_build_and_not_dependent?, #recommended?, #required?, #test?

Constructor Details

#initialize(tags = [], 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.

Returns a new instance of MacOSRequirement.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'requirements/macos_requirement.rb', line 19

def initialize(tags = [], comparator: ">=")
  @version = 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

  @comparator = comparator
  super(tags.drop(1))
end

Instance Attribute Details

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



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

def comparator
  @comparator
end

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



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

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.

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
# File 'requirements/macos_requirement.rb', line 71

def allows?(other)
  return true unless version_specified?

  case @comparator
  when ">=" then other >= @version
  when "<=" then other <= @version
  else
    return @version.include?(other) if @version.respond_to?(:to_ary)

    @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:



125
126
127
128
129
130
131
132
133
134
135
# File 'requirements/macos_requirement.rb', line 125

def display_s
  if version_specified?
    if @version.respond_to?(:to_ary)
      "macOS #{@comparator} #{version.join(" / ")} (or Linux)"
    else
      "macOS #{@comparator} #{@version} (or Linux)"
    end
  else
    "macOS"
  end
end

#message(type: :formula) ⇒ Object

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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'requirements/macos_requirement.rb', line 84

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

  case @comparator
  when ">="
    "This software does not run on macOS versions older than #{@version.pretty_name}."
  when "<="
    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
      "This cask does not run on macOS versions newer than #{@version.pretty_name}."
    end
  else
    if @version.respond_to?(:to_ary)
      *versions, last = @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 #{@version.pretty_name}."
  end
end

#minimum_versionObject

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.



64
65
66
67
68
69
# File 'requirements/macos_requirement.rb', line 64

def minimum_version
  return MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) if @comparator == "<=" || !version_specified?
  return @version.min if @version.respond_to?(:to_ary)

  @version
end

#to_json(options) ⇒ Object

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.



137
138
139
140
141
142
# File 'requirements/macos_requirement.rb', line 137

def to_json(options)
  comp = @comparator.to_s
  return { comp => @version.map(&:to_s) }.to_json(options) if @version.is_a?(Array)

  { comp => [@version.to_s] }.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)


51
52
53
# File 'requirements/macos_requirement.rb', line 51

def version_specified?
  @version.present?
end