Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate_disable: support optional replacement parameter #18733

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,38 +363,40 @@

def to_h
{
"token" => token,
"full_token" => full_name,
"old_tokens" => old_tokens,
"tap" => tap&.name,
"name" => name,
"desc" => desc,
"homepage" => homepage,
"url" => url,
"url_specs" => url_specs,
"version" => version,
"installed" => installed_version,
"installed_time" => install_time&.to_i,
"bundle_version" => bundle_long_version,
"bundle_short_version" => bundle_short_version,
"outdated" => outdated?,
"sha256" => sha256,
"artifacts" => artifacts_list,
"caveats" => (caveats unless caveats.empty?),
"depends_on" => depends_on,
"conflicts_with" => conflicts_with,
"container" => container&.pairs,
"auto_updates" => auto_updates,
"deprecated" => deprecated?,
"deprecation_date" => deprecation_date,
"deprecation_reason" => deprecation_reason,
"disabled" => disabled?,
"disable_date" => disable_date,
"disable_reason" => disable_reason,
"tap_git_head" => tap_git_head,
"languages" => languages,
"ruby_source_path" => ruby_source_path,
"ruby_source_checksum" => ruby_source_checksum,
"token" => token,
"full_token" => full_name,
"old_tokens" => old_tokens,
"tap" => tap&.name,
"name" => name,
"desc" => desc,
"homepage" => homepage,
"url" => url,
"url_specs" => url_specs,
"version" => version,
"installed" => installed_version,
"installed_time" => install_time&.to_i,
"bundle_version" => bundle_long_version,
"bundle_short_version" => bundle_short_version,
"outdated" => outdated?,
"sha256" => sha256,
"artifacts" => artifacts_list,
"caveats" => (caveats unless caveats.empty?),
"depends_on" => depends_on,
"conflicts_with" => conflicts_with,
"container" => container&.pairs,
"auto_updates" => auto_updates,
"deprecated" => deprecated?,
"deprecation_date" => deprecation_date,
"deprecation_reason" => deprecation_reason,
"deprecation_replacement" => deprecation_replacement,
"disabled" => disabled?,
"disable_date" => disable_date,
"disable_reason" => disable_reason,
"disable_replacement" => disable_replacement,
"tap_git_head" => tap_git_head,
"languages" => languages,
"ruby_source_path" => ruby_source_path,
"ruby_source_checksum" => ruby_source_checksum,
}
end

Expand All @@ -415,11 +417,13 @@
if deprecation_date
api_hash["deprecation_date"] = deprecation_date
api_hash["deprecation_reason"] = deprecation_reason
api_hash["deprecation_replacement"] = deprecation_replacement

Check warning on line 420 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L420

Added line #L420 was not covered by tests
end

if disable_date
api_hash["disable_date"] = disable_date
api_hash["disable_reason"] = disable_reason
api_hash["disable_replacement"] = disable_replacement

Check warning on line 426 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L426

Added line #L426 was not covered by tests
end

if (url_specs_hash = url_specs).present?
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/cask/cask.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ module Cask

def deprecation_reason; end

def deprecation_replacement; end

def disabled?; end

def disable_date; end

def disable_reason; end

def disable_replacement; end

def homepage; end

def language; end
Expand Down
13 changes: 9 additions & 4 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@
:deprecated?,
:deprecation_date,
:deprecation_reason,
:deprecation_replacement,
:disable!,
:disabled?,
:disable_date,
:disable_reason,
:disable_replacement,
:discontinued?, # TODO: remove once discontinued? is removed (4.5.0)
:livecheck,
:livecheckable?,
Expand All @@ -105,8 +107,8 @@
extend Attrable
include OnSystem::MacOSOnly

attr_reader :cask, :token, :deprecation_date, :deprecation_reason, :disable_date, :disable_reason,
:on_system_block_min_os
attr_reader :cask, :token, :deprecation_date, :deprecation_reason, :deprecation_replacement, :disable_date,
:disable_reason, :disable_replacement, :on_system_block_min_os

attr_predicate :deprecated?, :disabled?, :livecheckable?, :on_system_blocks_exist?, :depends_on_set_in_block?

Expand Down Expand Up @@ -442,11 +444,12 @@
# NOTE: A warning will be shown when trying to install this cask.
#
# @api public
def deprecate!(date:, because:)
def deprecate!(date:, because:, replacement: nil)
@deprecation_date = Date.parse(date)
return if @deprecation_date > Date.today

@deprecation_reason = because
@deprecation_replacement = replacement
@deprecated = true
end

Expand All @@ -455,16 +458,18 @@
# NOTE: An error will be thrown when trying to install this cask.
#
# @api public
def disable!(date:, because:)
def disable!(date:, because:, replacement: nil)
@disable_date = Date.parse(date)

if @disable_date > Date.today
@deprecation_reason = because
@deprecation_replacement = replacement

Check warning on line 466 in Library/Homebrew/cask/dsl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/dsl.rb#L466

Added line #L466 was not covered by tests
@deprecated = true
return
end

@disable_reason = because
@disable_replacement = replacement
@disabled = true
end

Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/cask/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
output = "#{title_info(cask)}\n"
output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage
deprecate_disable = DeprecateDisable.message(cask)
output << "#{deprecate_disable.capitalize}\n" if deprecate_disable
if deprecate_disable.present?
deprecate_disable.tap { |message| message[0] = message[0].upcase }
output << "#{deprecate_disable}\n"

Check warning on line 17 in Library/Homebrew/cask/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/info.rb#L17

Added line #L17 was not covered by tests
end
output << "#{installation_info(cask)}\n"
repo = repo_info(cask)
output << "#{repo}\n" if repo
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/deprecate_disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ def message(formula_or_cask)
end
end

replacement = if formula_or_cask.deprecated?
formula_or_cask.deprecation_replacement
elsif formula_or_cask.disabled?
formula_or_cask.disable_replacement
end

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

message
end

Expand Down
47 changes: 45 additions & 2 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,13 @@
# @see .deprecate!
delegate deprecation_reason: :"self.class"

# The replacement for this deprecated {Formula}.
# Returns `nil` if no replacement is specified or the formula is not deprecated.
# @!method deprecation_replacement
# @return [String]
# @see .deprecate!
delegate deprecation_replacement: :"self.class"

# Whether this {Formula} is disabled (i.e. cannot be installed).
# Defaults to false.
# @!method disabled?
Expand All @@ -1563,6 +1570,13 @@
# @see .disable!
delegate disable_reason: :"self.class"

# The replacement for this disabled {Formula}.
# Returns `nil` if no replacement is specified or the formula is not disabled.
# @!method disable_replacement
# @return [String]
# @see .disable!
delegate disable_replacement: :"self.class"

sig { returns(T::Boolean) }
def skip_cxxstdlib_check?
false
Expand Down Expand Up @@ -2475,9 +2489,11 @@
"deprecated" => deprecated?,
"deprecation_date" => deprecation_date,
"deprecation_reason" => deprecation_reason,
"deprecation_replacement" => deprecation_replacement,
"disabled" => disabled?,
"disable_date" => disable_date,
"disable_reason" => disable_reason,
"disable_replacement" => disable_replacement,
"post_install_defined" => post_install_defined?,
"service" => (service.to_hash if service?),
"tap_git_head" => tap_git_head,
Expand Down Expand Up @@ -2568,11 +2584,13 @@
if deprecation_date
api_hash["deprecation_date"] = deprecation_date
api_hash["deprecation_reason"] = deprecation_reason
api_hash["deprecation_replacement"] = deprecation_replacement

Check warning on line 2587 in Library/Homebrew/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula.rb#L2587

Added line #L2587 was not covered by tests
end

if disable_date
api_hash["disable_date"] = disable_date
api_hash["disable_reason"] = disable_reason
api_hash["disable_replacement"] = disable_replacement

Check warning on line 2593 in Library/Homebrew/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula.rb#L2593

Added line #L2593 was not covered by tests
end

api_hash
Expand Down Expand Up @@ -4268,14 +4286,19 @@
# deprecate! date: "2020-08-27", because: "has been replaced by foo"
# ```
#
# ```ruby
# deprecate! date: "2020-08-27", because: "has been replaced by foo", replacement: "foo"
# ```
#
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae
# @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS
# @api public
def deprecate!(date:, because:)
def deprecate!(date:, because:, replacement: nil)
@deprecation_date = Date.parse(date)
return if @deprecation_date > Date.today

@deprecation_reason = because
@deprecation_replacement = replacement
@deprecated = true
end

Expand All @@ -4301,6 +4324,13 @@
# @see .deprecate!
attr_reader :deprecation_reason

# The replacement for a deprecated {Formula}.
#
# @return [nil] if no replacement was provided or the formula is not deprecated.
# @return [String]
# @see .deprecate!
attr_reader :deprecation_replacement

# Disables a {Formula} (on the given date) so it cannot be
# installed. If the date has not yet passed the formula
# will be deprecated instead of disabled.
Expand All @@ -4315,19 +4345,25 @@
# disable! date: "2020-08-27", because: "has been replaced by foo"
# ```
#
# ```ruby
# disable! date: "2020-08-27", because: "has been replaced by foo", replacement: "foo"
# ```
#
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae
# @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS
# @api public
def disable!(date:, because:)
def disable!(date:, because:, replacement: nil)
@disable_date = Date.parse(date)

if @disable_date > Date.today
@deprecation_reason = because
@deprecation_replacement = replacement

Check warning on line 4360 in Library/Homebrew/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula.rb#L4360

Added line #L4360 was not covered by tests
@deprecated = true
return
end

@disable_reason = because
@disable_replacement = replacement
@disabled = true
end

Expand All @@ -4354,6 +4390,13 @@
# @see .disable!
attr_reader :disable_reason

# The replacement for a disabled {Formula}.
# Returns `nil` if no reason was provided or the formula is not disabled.
#
# @return [String]
# @see .disable!
attr_reader :disable_replacement

# Permit overwriting certain files while linking.
#
# ### Examples
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/formula.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading