Module: DeprecateDisable

Defined in:
deprecate_disable.rb

Overview

This module is part of an internal API. This module may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for handling disable! and deprecate!.

Constant Summary collapse

FORMULA_DEPRECATE_DISABLE_REASONS =

This constant is part of an internal API. This constant may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let({
  does_not_build:      "does not build",
  no_license:          "has no license",
  repo_archived:       "has an archived upstream repository",
  repo_removed:        "has a removed upstream repository",
  unmaintained:        "is not maintained upstream",
  unreachable:         "is no longer reliably reachable upstream",
  unsupported:         "is not supported upstream",
  deprecated_upstream: "is deprecated upstream",
  versioned_formula:   "is a versioned formula",
  checksum_mismatch:   "was built with an initially released source file that had " \
                       "a different checksum than the current one. " \
                       "Upstream's repository might have been compromised. " \
                       "We can re-package this once upstream has confirmed that they retagged their release",
}.freeze, T::Hash[Symbol, String])
CASK_DEPRECATE_DISABLE_REASONS =

This constant is part of an internal API. This constant may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let({
  discontinued:             "is discontinued upstream",
  moved_to_mas:             "is now exclusively distributed on the Mac App Store",
  no_longer_available:      "is no longer available upstream",
  no_longer_meets_criteria: "no longer meets the criteria for acceptable casks",
  unmaintained:             "is not maintained upstream",
  fails_gatekeeper_check:   "does not pass the macOS Gatekeeper check",
  unreachable:              "is no longer reliably reachable upstream",
}.freeze, T::Hash[Symbol, String])
REMOVE_DISABLED_TIME_WINDOW =

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.

One year when << or >> to Date.today. Keep in sync with RemoveDisabledPackages::REMOVE_DISABLED_MONTHS in Homebrew/actions/remove-disabled-packages/main.rb.

12
REMOVE_DISABLED_BEFORE =

This constant is part of an internal API. This constant may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let((Date.today << REMOVE_DISABLED_TIME_WINDOW).freeze, Date)

Class Method Summary collapse

Class Method Details

.disabled_on_all_platforms?(formula_or_cask) ⇒ 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.

Whether a formula or cask is disabled on every OS/architecture combination.

Parameters:

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
# File 'deprecate_disable.rb', line 43

def disabled_on_all_platforms?(formula_or_cask)
  return false unless formula_or_cask.disabled?
  return true unless formula_or_cask.on_system_blocks_exist?

  formula_or_cask.to_hash_with_variations.fetch("variations").each_value.all? do |variation|
    variation.fetch("disabled", true)
  end
end

.message(formula_or_cask) ⇒ 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:

Returns:



76
77
78
79
80
81
82
83
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
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 'deprecate_disable.rb', line 76

def message(formula_or_cask)
  return if type(formula_or_cask).blank?

  reason = if formula_or_cask.deprecated?
    formula_or_cask.deprecation_reason
  elsif formula_or_cask.disabled?
    formula_or_cask.disable_reason
  end

  reason = if formula_or_cask.is_a?(Formula) && FORMULA_DEPRECATE_DISABLE_REASONS.key?(reason)
    FORMULA_DEPRECATE_DISABLE_REASONS[reason]
  elsif formula_or_cask.is_a?(Cask::Cask) && CASK_DEPRECATE_DISABLE_REASONS.key?(reason)
    CASK_DEPRECATE_DISABLE_REASONS[reason]
  else
    reason
  end

  message = if reason.present?
    "#{type(formula_or_cask)} because it #{reason}!"
  else
    "#{type(formula_or_cask)}!"
  end

  disable_date = formula_or_cask.disable_date
  if !disable_date && formula_or_cask.deprecation_date
    disable_date = formula_or_cask.deprecation_date >> REMOVE_DISABLED_TIME_WINDOW
  end
  if disable_date
    message += if disable_date < Date.today
      " It was disabled on #{disable_date}."
    else
      " It will be disabled on #{disable_date}."
    end
  end

  replacement = if formula_or_cask.disabled?
    replacement_with_type(
      formula_or_cask.disable_replacement_formula,
      formula_or_cask.disable_replacement_cask,
    )
  elsif formula_or_cask.deprecated?
    replacement_with_type(
      formula_or_cask.deprecation_replacement_formula,
      formula_or_cask.deprecation_replacement_cask,
    )
  end

  if replacement.present?
    message << "\n"
    message << <<~EOS
      Replacement:
        brew install #{replacement}
    EOS
  end

  message
end

.replacement_with_type(formula, cask) ⇒ 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:

Returns:



65
66
67
68
69
70
71
72
73
# File 'deprecate_disable.rb', line 65

def replacement_with_type(formula, cask)
  if formula && formula == cask
    formula
  elsif formula
    "--formula #{formula}"
  elsif cask
    "--cask #{cask}"
  end
end

.to_reason_string_or_symbol(string, type:) ⇒ 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:

Returns:



135
136
137
138
139
140
141
142
143
144
# File 'deprecate_disable.rb', line 135

def to_reason_string_or_symbol(string, type:)
  return if string.nil?

  if (type == :formula && FORMULA_DEPRECATE_DISABLE_REASONS.key?(string.to_sym)) ||
     (type == :cask && CASK_DEPRECATE_DISABLE_REASONS.key?(string.to_sym))
    return string.to_sym
  end

  string
end

.type(formula_or_cask) ⇒ Symbol?

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:



53
54
55
56
57
# File 'deprecate_disable.rb', line 53

def type(formula_or_cask)
  return :deprecated if formula_or_cask.deprecated?

  :disabled if formula_or_cask.disabled?
end