From 719e6c8999928f45dfca2d640cd6f9a3e784e9a1 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 14 Nov 2010 03:52:59 +0000 Subject: [PATCH] Refactor the blacklists Also don't abort searches if the query matches a blacklist. Eg. `brew search vim` should return macvim and the information that vim itself is not packaged. --- Library/Homebrew/blacklist.rb | 49 +++++++++++++++++++++++++++++++++ Library/Homebrew/cmd/create.rb | 31 ++------------------- Library/Homebrew/cmd/install.rb | 43 +++-------------------------- Library/Homebrew/cmd/search.rb | 21 +++++++++----- 4 files changed, 69 insertions(+), 75 deletions(-) create mode 100644 Library/Homebrew/blacklist.rb diff --git a/Library/Homebrew/blacklist.rb b/Library/Homebrew/blacklist.rb new file mode 100644 index 0000000000..6789ba1e7a --- /dev/null +++ b/Library/Homebrew/blacklist.rb @@ -0,0 +1,49 @@ +def blacklisted? name + case name.downcase + when 'vim', 'screen', /^rubygems?$/ then <<-EOS.undent + Apple distributes #{name} with OS X, you can find it in /usr/bin. + EOS + when 'libxml', 'libarchive', 'libpcap' then <<-EOS.undent + Apple distributes #{name} with OS X, you can find it in /usr/lib. + EOS + when 'libxlst', 'freetype', 'libpng' then <<-EOS.undent + Apple distributes #{name} with OS X, you can find it in /usr/X11/lib. + However not all build scripts look here, so you may need to call ENV.x11 or + ENV.libxml2 in your formula's install function. + EOS + when 'wxwidgets' then <<-EOS.undent + An old version of wxWidgets can be found in /usr/X11/lib. However, Homebrew + does provide a newer version, 2.8.10: + + brew install wxmac + EOS + when 'tex', 'tex-live', 'texlive' 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 deps on Snow Leopard.) + + We recommend using a MacTeX distribution: http://www.tug.org/mactex/ + EOS + when 'mercurial', 'hg' then <<-EOS.undent + Install Mercurial with pip: + + brew install pip && pip install mercurial + + Or easy_install: + + easy_install mercurial + EOS + when 'setuptools' then <<-EOS.undent + When working with a Homebrew-built Python, distribute is preferred over + setuptools, and can be used as the prerequisite for pip: + + brew install distribute + EOS + when 'npm' then <<-EOS.undent + npm can be installed thusly by following the instructions at + http://npmjs.org/ + + To do it in one line, use this command: + curl http://npmjs.org/install.sh | sudo sh + EOS + end +end diff --git a/Library/Homebrew/cmd/create.rb b/Library/Homebrew/cmd/create.rb index e21c9a5244..8f39ce87b9 100644 --- a/Library/Homebrew/cmd/create.rb +++ b/Library/Homebrew/cmd/create.rb @@ -1,4 +1,5 @@ require 'formula' +require 'blacklist' module Homebrew extend self def create @@ -26,7 +27,7 @@ module Homebrew extend self unless ARGV.force? if msg = blacklisted?(fc.name) - raise "#{msg}\n\nIf you really want to make this formula use --force." + raise "#{fc.name} is blacklisted for creation.\n#{msg}\nIf you really want to create this formula use --force." end if Formula.aliases.include? fc.name @@ -49,34 +50,6 @@ module Homebrew extend self gots = $stdin.gets.chomp if gots.empty? then nil else gots end end - - def blacklisted? name - case name.downcase - when 'vim', 'screen' then <<-EOS.undent - #{name} is blacklisted for creation - Apple distributes this program with OS X. - EOS - when 'libarchive', 'libpcap' then <<-EOS.undent - #{name} is blacklisted for creation - Apple distributes this library with OS X, you can find it in /usr/lib. - EOS - when 'libxml', 'libxlst', 'freetype', 'libpng' then <<-EOS.undent - #{name} is blacklisted for creation - Apple distributes this library with OS X, you can find it in /usr/X11/lib. - However not all build scripts look here, so you may need to call ENV.x11 or - ENV.libxml2 in your formula's install function. - EOS - when /^rubygems?$/ - "Sorry RubyGems comes with OS X so we don't package it." - when 'wxwidgets' then <<-EOS.undent - #{name} is blacklisted for creation - An older version of wxWidgets is provided by Apple with OS X, but - a formula for wxWidgets 2.8.10 is provided: - - brew install wxmac - EOS - end - end end class FormulaCreator diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 2c48085da9..2102d2182b 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -1,10 +1,12 @@ require 'formula_installer' require 'hardware' +require 'blacklist' module Homebrew extend self def install - blacklisted? ARGV.named do |msg, name| - abort msg + ARGV.named.each do |name| + msg = blacklisted? name + raise "No available formula for #{name}\n#{msg}" if msg end unless ARGV.force? install_formulae ARGV.formulae @@ -62,41 +64,4 @@ module Homebrew extend self end end end - - def blacklisted? names - names.each do |name| - msg = blacklisted_reason name - yield msg.undent, name if msg - end - end - - def blacklisted_reason name - case name - when 'tex', 'tex-live', 'texlive' then <<-EOS - Installing TeX from source is weird and gross, requires a lot of patches, - and only builds 32-bit (and thus can't use Homebrew deps on Snow Leopard.) - - We recommend using a MacTeX distribution: - http://www.tug.org/mactex/ - EOS - when 'mercurial', 'hg' then <<-EOS - Mercurial can be install thusly: - brew install pip && pip install mercurial - EOS - when 'npm' then abort <<-EOS.undent - npm can be installed thusly by following the instructions at - http://npmjs.org/ - - To do it in one line, use this command: - curl http://npmjs.org/install.sh | sudo sh - EOS - when 'setuptools' then abort <<-EOS.undent - When working with a Homebrew-built Python, distribute is preferred - over setuptools, and can be used as the prerequisite for pip. - - Install distribute using: - brew install distribute - EOS - end - end end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index b6a0e971d3..ccbf784d41 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -1,4 +1,5 @@ require "formula" +require "blacklist" module Homebrew extend self def search @@ -6,14 +7,20 @@ module Homebrew extend self exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" elsif ARGV.include? '--fink' exec "open", "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}" + else + query = ARGV.first + search_results = search_brews query + puts_columns search_results + + if $stdout.tty? and msg = blacklisted?(query) + unless search_results.empty? + puts + puts "If you meant `#{query}' precisely:" + puts + end + puts msg + end end - - require 'cmd/install' # for blacklisted? function - blacklisted? ARGV.named do |msg, _| - abort msg - end unless ARGV.force? - - puts_columns search_brews(ARGV.first) end def search_brews text