blacklist: move to missing_formula class instead.

This will allow extending this class so it can be used by more than
just blacklisting.
This commit is contained in:
Mike McQuaid 2017-03-18 17:02:08 +02:00
parent 623c95b3f8
commit 80e95b684e
13 changed files with 269 additions and 239 deletions

View File

@ -1,92 +0,0 @@
def blacklisted?(name)
case name.downcase
when "gem", /^rubygems?$/ then <<-EOS.undent
Homebrew provides gem via: `brew install ruby`.
EOS
when "tex", "tex-live", "texlive", "latex" then <<-EOS.undent
Installing TeX from source is weird and gross, requires a lot of patches,
and only builds 32-bit (and thus can't use Homebrew dependencies)
We recommend using a MacTeX distribution: https://www.tug.org/mactex/
You can install it with Homebrew-Cask:
brew cask install mactex
EOS
when "pip" then <<-EOS.undent
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
#{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")}
EOS
when "pil" then <<-EOS.undent
Instead of PIL, consider `pip install pillow` or `brew install Homebrew/python/pillow`.
EOS
when "macruby" then <<-EOS.undent
MacRuby is not packaged and is on an indefinite development hiatus.
You can read more about it at:
#{Formatter.url("https://github.com/MacRuby/MacRuby")}
EOS
when /(lib)?lzma/
"lzma is now part of the xz formula."
when "gtest", "googletest", "google-test" then <<-EOS.undent
Installing gtest system-wide is not recommended; it should be vendored
in your projects that use it.
EOS
when "gmock", "googlemock", "google-mock" then <<-EOS.undent
Installing gmock system-wide is not recommended; it should be vendored
in your projects that use it.
EOS
when "sshpass" then <<-EOS.undent
We won't add sshpass because it makes it too easy for novice SSH users to
ruin SSH's security.
EOS
when "gsutil" then <<-EOS.undent
Install gsutil with `pip install gsutil`
EOS
when "clojure" then <<-EOS.undent
Clojure isn't really a program but a library managed as part of a
project and Leiningen is the user interface to that library.
To install Clojure you should install Leiningen:
brew install leiningen
and then follow the tutorial:
#{Formatter.url("https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md")}
EOS
when "osmium" then <<-EOS.undent
The creator of Osmium requests that it not be packaged and that people
use the GitHub master branch instead.
EOS
when "gfortran" then <<-EOS.undent
GNU Fortran is now provided as part of GCC, and can be installed with:
brew install gcc
EOS
when "play" then <<-EOS.undent
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")}
EOS
when "haskell-platform" then <<-EOS.undent
We no longer package haskell-platform. Consider installing ghc
and cabal-install instead:
brew install ghc cabal-install
You can install with Homebrew-Cask:
brew cask install haskell-platform
EOS
when "mysqldump-secure" then <<-EOS.undent
The creator of mysqldump-secure tried to game our popularity metrics.
EOS
when "ngrok" then <<-EOS.undent
Upstream sunsetted 1.x in March 2016 and 2.x is not open-source.
If you wish to use the 2.x release you can install with Homebrew-Cask:
brew cask install ngrok
EOS
end
end
alias generic_blacklisted? blacklisted?
require "extend/os/blacklist"

View File

@ -16,7 +16,7 @@
#: See the docs for examples of using the JSON output:
#: <http://docs.brew.sh/Querying-Brew.html>
require "blacklist"
require "missing_formula"
require "caveats"
require "options"
require "formula"
@ -56,9 +56,9 @@ module Homebrew
info_formula Formulary.find_with_priority(f)
end
rescue FormulaUnavailableError => e
# No formula with this name, try a blacklist lookup
if (blacklist = blacklisted?(f))
ofail "#{e.message}\n#{blacklist}"
# No formula with this name, try a missing formula lookup
if (missing_formula = Homebrew::MissingFormula.missing_formula(f))
ofail "#{e.message}\n#{missing_formula}"
else
ofail e.message

View File

@ -55,7 +55,7 @@
#: If `--git` is passed, Homebrew will create a Git repository, useful for
#: creating patches to the software.
require "blacklist"
require "missing_formula"
require "diagnostic"
require "cmd/search"
require "formula_installer"
@ -207,8 +207,8 @@ module Homebrew
# formula was found, but there's a problem with its implementation).
ofail e.message
rescue FormulaUnavailableError => e
if (blacklist = blacklisted?(e.name))
ofail "#{e.message}\n#{blacklist}"
if (missing_formula = Homebrew::MissingFormula.missing_formula(e.name))
ofail "#{e.message}\n#{missing_formula}"
elsif e.name == "updog"
ofail "What's updog?"
else

View File

@ -14,7 +14,7 @@
#: Search for <text> in the given package manager's list.
require "formula"
require "blacklist"
require "missing_formula"
require "utils"
require "thread"
require "official_taps"
@ -67,7 +67,7 @@ module Homebrew
if $stdout.tty?
count = local_results.length + tap_results.length
if msg = blacklisted?(query)
if msg = Homebrew::MissingFormula.missing_formula(query)
if count > 0
puts
puts "If you meant #{query.inspect} specifically:"

View File

@ -38,7 +38,7 @@ require "official_taps"
require "cmd/search"
require "cmd/style"
require "date"
require "blacklist"
require "missing_formula"
require "digest"
module Homebrew
@ -399,7 +399,7 @@ class FormulaAuditor
name = formula.name
full_name = formula.full_name
if blacklisted?(name)
if Homebrew::MissingFormula.blacklisted_reason(name)
problem "'#{name}' is blacklisted."
end

View File

@ -19,7 +19,7 @@
#: the specified tap.
require "formula"
require "blacklist"
require "missing_formula"
require "digest"
require "erb"
@ -73,8 +73,8 @@ module Homebrew
# Don't allow blacklisted formula, or names that shadow aliases,
# unless --force is specified.
unless ARGV.force?
if msg = blacklisted?(fc.name)
raise "#{fc.name} is blacklisted for creation.\n#{msg}\nIf you really want to create this formula use --force."
if reason = Homebrew::MissingFormula.blacklisted_reason(fc.name)
raise "#{fc.name} is blacklisted for creation.\n#{reason}\nIf you really want to create this formula use --force."
end
if Formula.aliases.include? fc.name

View File

@ -1,2 +0,0 @@
require "blacklist"
require "extend/os/mac/blacklist" if OS.mac?

View File

@ -1,16 +0,0 @@
def blacklisted?(name)
case name.downcase
when "xcode"
if MacOS.version >= :lion
<<-EOS.undent
Xcode can be installed from the App Store.
EOS
else
<<-EOS.undent
Xcode can be installed from https://developer.apple.com/xcode/downloads/
EOS
end
else
generic_blacklisted?(name)
end
end

View File

@ -0,0 +1,22 @@
module Homebrew
module MissingFormula
class << self
def blacklisted_reason(name)
case name.downcase
when "xcode"
if MacOS.version >= :lion
<<-EOS.undent
Xcode can be installed from the App Store.
EOS
else
<<-EOS.undent
Xcode can be installed from #{Formatter.url("https://developer.apple.com/xcode/downloads/")}.
EOS
end
else
generic_blacklisted_reason(name)
end
end
end
end
end

View File

@ -0,0 +1,2 @@
require "missing_formula"
require "extend/os/mac/missing_formula" if OS.mac?

View File

@ -0,0 +1,106 @@
require "formulary"
require "tap"
require "utils"
module Homebrew
module MissingFormula
class << self
def reason(name)
blacklisted_reason(name)
end
def blacklisted_reason(name)
case name.downcase
when "gem", /^rubygems?$/ then <<-EOS.undent
Homebrew provides gem via: `brew install ruby`.
EOS
when "tex", "tex-live", "texlive", "latex" then <<-EOS.undent
Installing TeX from source is weird and gross, requires a lot of patches,
and only builds 32-bit (and thus can't use Homebrew dependencies)
We recommend using a MacTeX distribution: https://www.tug.org/mactex/
You can install it with Homebrew-Cask:
brew cask install mactex
EOS
when "pip" then <<-EOS.undent
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
#{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")}
EOS
when "pil" then <<-EOS.undent
Instead of PIL, consider `pip install pillow` or `brew install Homebrew/python/pillow`.
EOS
when "macruby" then <<-EOS.undent
MacRuby is not packaged and is on an indefinite development hiatus.
You can read more about it at:
#{Formatter.url("https://github.com/MacRuby/MacRuby")}
EOS
when /(lib)?lzma/
"lzma is now part of the xz formula."
when "gtest", "googletest", "google-test" then <<-EOS.undent
Installing gtest system-wide is not recommended; it should be vendored
in your projects that use it.
EOS
when "gmock", "googlemock", "google-mock" then <<-EOS.undent
Installing gmock system-wide is not recommended; it should be vendored
in your projects that use it.
EOS
when "sshpass" then <<-EOS.undent
We won't add sshpass because it makes it too easy for novice SSH users to
ruin SSH's security.
EOS
when "gsutil" then <<-EOS.undent
Install gsutil with `pip install gsutil`
EOS
when "clojure" then <<-EOS.undent
Clojure isn't really a program but a library managed as part of a
project and Leiningen is the user interface to that library.
To install Clojure you should install Leiningen:
brew install leiningen
and then follow the tutorial:
#{Formatter.url("https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md")}
EOS
when "osmium" then <<-EOS.undent
The creator of Osmium requests that it not be packaged and that people
use the GitHub master branch instead.
EOS
when "gfortran" then <<-EOS.undent
GNU Fortran is now provided as part of GCC, and can be installed with:
brew install gcc
EOS
when "play" then <<-EOS.undent
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")}
EOS
when "haskell-platform" then <<-EOS.undent
We no longer package haskell-platform. Consider installing ghc
and cabal-install instead:
brew install ghc cabal-install
You can install with Homebrew-Cask:
brew cask install haskell-platform
EOS
when "mysqldump-secure" then <<-EOS.undent
The creator of mysqldump-secure tried to game our popularity metrics.
EOS
when "ngrok" then <<-EOS.undent
Upstream sunsetted 1.x in March 2016 and 2.x is not open-source.
If you wish to use the 2.x release you can install with Homebrew-Cask:
brew cask install ngrok
EOS
end
end
alias generic_blacklisted_reason blacklisted_reason
require "extend/os/missing_formula"
end
end
end

View File

@ -1,115 +0,0 @@
require "blacklist"
describe "Blacklist" do
matcher(:be_blacklisted) { match(&method(:blacklisted?)) }
context "rubygems" do
%w[gem rubygem rubygems].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "latex" do
%w[latex tex tex-live texlive TexLive].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "pip" do
subject { "pip" }
it { is_expected.to be_blacklisted }
end
context "pil" do
subject { "pil" }
it { is_expected.to be_blacklisted }
end
context "macruby" do
subject { "MacRuby" }
it { is_expected.to be_blacklisted }
end
context "lzma" do
%w[lzma liblzma].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "gtest" do
%w[gtest googletest google-test].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "gmock" do
%w[gmock googlemock google-mock].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "sshpass" do
subject { "sshpass" }
it { is_expected.to be_blacklisted }
end
context "gsutil" do
subject { "gsutil" }
it { is_expected.to be_blacklisted }
end
context "clojure" do
subject { "clojure" }
it { is_expected.to be_blacklisted }
end
context "osmium" do
%w[osmium Osmium].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "gfortran" do
subject { "gfortran" }
it { is_expected.to be_blacklisted }
end
context "play" do
subject { "play" }
it { is_expected.to be_blacklisted }
end
context "haskell-platform" do
subject { "haskell-platform" }
it { is_expected.to be_blacklisted }
end
context "xcode", :needs_macos do
%w[xcode Xcode].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
end

View File

@ -0,0 +1,125 @@
require "missing_formula"
describe Homebrew::MissingFormula do
context ".reason" do
subject { described_class.reason("gem") }
it { is_expected.to_not be_nil }
end
context ".blacklisted_reason" do
matcher(:be_blacklisted) do
match(&Homebrew::MissingFormula.method(:blacklisted_reason))
end
context "rubygems" do
%w[gem rubygem rubygems].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "latex" do
%w[latex tex tex-live texlive TexLive].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "pip" do
subject { "pip" }
it { is_expected.to be_blacklisted }
end
context "pil" do
subject { "pil" }
it { is_expected.to be_blacklisted }
end
context "macruby" do
subject { "MacRuby" }
it { is_expected.to be_blacklisted }
end
context "lzma" do
%w[lzma liblzma].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "gtest" do
%w[gtest googletest google-test].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "gmock" do
%w[gmock googlemock google-mock].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "sshpass" do
subject { "sshpass" }
it { is_expected.to be_blacklisted }
end
context "gsutil" do
subject { "gsutil" }
it { is_expected.to be_blacklisted }
end
context "clojure" do
subject { "clojure" }
it { is_expected.to be_blacklisted }
end
context "osmium" do
%w[osmium Osmium].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
context "gfortran" do
subject { "gfortran" }
it { is_expected.to be_blacklisted }
end
context "play" do
subject { "play" }
it { is_expected.to be_blacklisted }
end
context "haskell-platform" do
subject { "haskell-platform" }
it { is_expected.to be_blacklisted }
end
context "xcode", :needs_macos do
%w[xcode Xcode].each do |s|
subject { s }
it { is_expected.to be_blacklisted }
end
end
end
end