brew/Library/Homebrew/missing_formula.rb

194 lines
6.3 KiB
Ruby
Raw Normal View History

2021-09-11 01:00:23 +01:00
# typed: true
# frozen_string_literal: true
require "formulary"
module Homebrew
2020-08-17 19:55:09 +02:00
# Helper module for checking if there is a reason a formula is missing.
#
# @api private
module MissingFormula
class << self
def reason(name, silent: false, show_info: false)
cask_reason(name, silent: silent, show_info: show_info) || disallowed_reason(name) ||
tap_migration_reason(name) || deleted_reason(name, silent: silent)
end
def disallowed_reason(name)
case name.downcase
2017-10-15 02:28:32 +02:00
when "gem", /^rubygems?$/ then <<~EOS
macOS provides gem as part of Ruby. To install a newer version:
brew install ruby
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "pip" then <<~EOS
pip is part of the python formula:
2019-02-05 14:05:57 +00:00
brew install python
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "pil" then <<~EOS
Instead of PIL, consider pillow:
pip2 install pillow
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "macruby" then <<~EOS
2019-02-18 16:20:59 -05:00
MacRuby has been discontinued. Consider RubyMotion:
2020-11-18 08:10:21 +01:00
brew install --cask rubymotion
2018-06-06 23:34:19 -04:00
EOS
when /(lib)?lzma/ then <<~EOS
lzma is now part of the xz formula:
2019-02-05 14:05:57 +00:00
brew install xz
EOS
2017-10-15 02:28:32 +02:00
when "sshpass" then <<~EOS
We won't add sshpass because it makes it too easy for novice SSH users to
ruin SSH's security.
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "gsutil" then <<~EOS
gsutil is available through pip:
pip2 install gsutil
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "gfortran" then <<~EOS
GNU Fortran is part of the GCC formula:
brew install gcc
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "play" then <<~EOS
Play 2.3 replaces the play command with activator:
brew install typesafe-activator
You can read more about this change at:
#{Formatter.url("https://www.playframework.com/documentation/2.3.x/Migration23")}
#{Formatter.url("https://www.playframework.com/documentation/2.3.x/Highlights23")}
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "haskell-platform" then <<~EOS
The components of the Haskell Platform are available separately.
Glasgow Haskell Compiler:
brew install ghc
Cabal build system:
brew install cabal-install
Haskell Stack tool:
brew install haskell-stack
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "mysqldump-secure" then <<~EOS
The creator of mysqldump-secure tried to game our popularity metrics.
2018-06-06 23:34:19 -04:00
EOS
2017-10-15 02:28:32 +02:00
when "ngrok" then <<~EOS
Upstream sunsetted 1.x in March 2016 and 2.x is not open-source.
2020-11-18 08:10:21 +01:00
If you wish to use the 2.x release you can install it with:
brew install --cask ngrok
2018-06-06 23:34:19 -04:00
EOS
when "cargo" then <<~EOS
cargo is part of the rust formula:
2019-02-05 14:05:57 +00:00
brew install rust
EOS
when "cargo-completion" then <<~EOS
cargo-completion is part of the rust formula:
brew install rust
EOS
when "uconv" then <<~EOS
uconv is part of the icu4c formula:
brew install icu4c
EOS
when "postgresql", "postgres" then <<~EOS
postgresql breaks existing databases on upgrade without human intervention.
See a more specific version to install with:
brew formulae | grep postgresql@
EOS
end
end
alias generic_disallowed_reason disallowed_reason
def tap_migration_reason(name)
2020-11-23 18:15:48 +01:00
message = T.let(nil, T.nilable(String))
Tap.each do |old_tap|
new_tap = old_tap.tap_migrations[name]
next unless new_tap
new_tap_user, new_tap_repo, new_tap_new_name = new_tap.split("/")
new_tap_name = "#{new_tap_user}/#{new_tap_repo}"
2017-10-15 02:28:32 +02:00
message = <<~EOS
It was migrated from #{old_tap} to #{new_tap}.
EOS
break if new_tap_name == CoreTap.instance.name
2018-05-25 18:03:16 +02:00
install_cmd = if new_tap_name.start_with?("homebrew/cask")
"install --cask"
else
"install"
end
new_tap_new_name ||= name
2017-10-15 02:28:32 +02:00
message += <<~EOS
You can access it again by running:
brew tap #{new_tap_name}
And then you can install it by running:
brew #{install_cmd} #{new_tap_new_name}
EOS
break
end
message
end
def deleted_reason(name, silent: false)
path = Formulary.path name
return if File.exist? path
2018-09-17 02:45:00 +02:00
tap = Tap.from_path(path)
return if tap.nil? || !File.exist?(tap.path)
2018-09-17 02:45:00 +02:00
relative_path = path.relative_path_from tap.path
tap.path.cd do
unless silent
ohai "Searching for a previously deleted formula (in the last month)..."
if (tap.path/".git/shallow").exist?
2017-10-15 02:28:32 +02:00
opoo <<~EOS
2021-01-26 15:21:24 -05:00
#{tap} is shallow clone. To get its complete history, run:
git -C "$(brew --repo #{tap})" fetch --unshallow
EOS
end
end
log_command = "git log --since='1 month ago' --diff-filter=D " \
"--name-only --max-count=1 " \
"--format=%H\\\\n%h\\\\n%B -- #{relative_path}"
hash, short_hash, *commit_message, relative_path =
Utils.popen_read(log_command).gsub("\\n", "\n").lines.map(&:chomp)
if hash.blank? || short_hash.blank? || relative_path.blank?
ofail "No previously deleted formula found." unless silent
return
end
commit_message = commit_message.reject(&:empty?).join("\n ")
commit_message.sub!(/ \(#(\d+)\)$/, " (#{tap.issues_url}/\\1)")
commit_message.gsub!(/(Closes|Fixes) #(\d+)/, "\\1 #{tap.issues_url}/\\2")
2017-10-15 02:28:32 +02:00
<<~EOS
#{name} was deleted from #{tap.name} in commit #{short_hash}:
#{commit_message}
2021-01-26 15:21:24 -05:00
To show the formula before removal, run:
git -C "$(brew --repo #{tap})" show #{short_hash}^:#{relative_path}
2021-01-26 15:21:24 -05:00
If you still use this formula, consider creating your own tap:
2019-04-05 12:24:10 -04:00
#{Formatter.url("https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap")}
EOS
end
end
def cask_reason(name, silent: false, show_info: false); end
def suggest_command(name, command); end
require "extend/os/missing_formula"
end
end
end