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.

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

#env, env, #env_proc, expand, #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 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.



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
50
51
# File 'requirements/macos_requirement.rb', line 21

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.



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

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.



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

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

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.



92
93
94
# File 'requirements/macos_requirement.rb', line 92

def ==(other)
  super(other) && comparator == other.comparator && version == other.version
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:



107
108
109
110
111
112
113
114
115
116
117
# File 'requirements/macos_requirement.rb', line 107

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

#hashObject

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.



97
98
99
# File 'requirements/macos_requirement.rb', line 97

def hash
  [super, comparator, version].hash
end

#inspectString

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:



102
103
104
# File 'requirements/macos_requirement.rb', line 102

def inspect
  "#<#{self.class.name}: version#{@comparator}#{@version.to_s.inspect} #{tags.inspect}>"
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.



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
# File 'requirements/macos_requirement.rb', line 66

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

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



119
120
121
122
123
124
# File 'requirements/macos_requirement.rb', line 119

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)


53
54
55
# File 'requirements/macos_requirement.rb', line 53

def version_specified?
  @version.present?
end