Use new Requirements code in Homebrew

This commit is contained in:
Adam Vandenberg 2012-02-28 19:56:35 -08:00
parent fee00469f6
commit cef5429f93
4 changed files with 28 additions and 110 deletions

View File

@ -146,8 +146,8 @@ get '/formula/:name' do
s << <<-HTML s << <<-HTML
<dt>Depends on</td> <dt>Depends on</td>
HTML HTML
klass.deps.each do |name| klass.deps.each do |dep|
s << "<dd>#{link_to_formula(name)}</dd>" s << "<dd>#{link_to_formula(dep.name)}</dd>"
end end
end end

View File

@ -51,54 +51,12 @@ class FormulaInstallationAlreadyAttemptedError < Homebrew::InstallationError
end end
end end
class UnsatisfiedExternalDependencyError < Homebrew::InstallationError class UnsatisfiedRequirement < Homebrew::InstallationError
attr :type attr :dep
def initialize formula, type def initialize formula, dep
@type = type @dep = dep
super formula, get_message(formula) super formula, "An unsatisfied requirement failed this build."
end
def get_message formula
<<-EOS.undent
Unsatisfied external dependency: #{formula}
Homebrew does not provide #{type.to_s.capitalize} dependencies, #{tool} does:
#{command_line} #{formula}
EOS
end
private
def tool
case type
when :python then 'easy_install'
when :ruby, :jruby, :rbx then 'rubygems'
when :perl then 'cpan'
when :node then 'npm'
when :chicken then 'chicken-install'
when :lua then "luarocks"
end
end
def command_line
case type
when :python
"easy_install"
when :ruby
"gem install"
when :perl
"cpan -i"
when :jruby
"jruby -S gem install"
when :rbx
"rbx gem install"
when :node
"npm install"
when :chicken
"chicken-install"
when :lua
"luarocks install"
end
end end
end end

View File

@ -1,4 +1,5 @@
require 'download_strategy' require 'download_strategy'
require 'dependencies'
require 'formula_support' require 'formula_support'
require 'hardware' require 'hardware'
require 'bottles' require 'bottles'
@ -357,17 +358,10 @@ class Formula
HOMEBREW_REPOSITORY+"Library/Formula/#{name.downcase}.rb" HOMEBREW_REPOSITORY+"Library/Formula/#{name.downcase}.rb"
end end
def mirrors def mirrors; self.class.mirrors or []; end
self.class.mirrors or []
end
def deps def deps; self.class.dependencies.deps; end
self.class.deps or [] def external_deps; self.class.dependencies.external_deps; end
end
def external_deps
self.class.external_deps or {}
end
# deps are in an installable order # deps are in an installable order
# which means if a depends on b then b will be ordered before a in this list # which means if a depends on b then b will be ordered before a in this list
@ -377,8 +371,8 @@ class Formula
def self.expand_deps f def self.expand_deps f
f.deps.map do |dep| f.deps.map do |dep|
dep = Formula.factory dep f_dep = Formula.factory dep.to_s
expand_deps(dep) << dep expand_deps(f_dep) << f_dep
end end
end end
@ -603,7 +597,7 @@ private
end end
end end
attr_rw :version, :homepage, :mirrors, :specs, :deps, :external_deps attr_rw :version, :homepage, :mirrors, :specs
attr_rw :keg_only_reason, :fails_with_llvm_reason, :skip_clean_all attr_rw :keg_only_reason, :fails_with_llvm_reason, :skip_clean_all
attr_rw :bottle_url, :bottle_sha1 attr_rw :bottle_url, :bottle_sha1
attr_rw(*CHECKSUM_TYPES) attr_rw(*CHECKSUM_TYPES)
@ -659,29 +653,12 @@ private
@mirrors.uniq! @mirrors.uniq!
end end
def depends_on name def dependencies
@deps ||= [] @dependencies ||= DependencyCollector.new
@external_deps ||= {:python => [], :perl => [], :ruby => [], :jruby => [], :chicken => [], :rbx => [], :node => [], :lua => []} end
case name def depends_on dep
when String, Formula dependencies.add(dep)
@deps << name
when Hash
key, value = name.shift
case value
when :python, :perl, :ruby, :jruby, :chicken, :rbx, :node, :lua
@external_deps[value] << key
when :optional, :recommended, :build
@deps << key
else
raise "Unsupported dependency type #{value}"
end
when Symbol
opoo "#{self.name} -- #{name}: Using symbols for deps is deprecated; use a string instead"
@deps << name.to_s
else
raise "Unsupported type #{name.class}"
end
end end
def skip_clean paths def skip_clean paths

View File

@ -52,9 +52,16 @@ class FormulaInstaller
EOS EOS
end end
unless ignore_deps f.external_deps.each do |dep|
f.check_external_deps unless dep.satisfied?
puts dep.message
if dep.fatal? and not ignore_deps
raise UnsatisfiedRequirement.new(f, dep)
end
end
end
unless ignore_deps
needed_deps = f.recursive_deps.reject{ |d| d.installed? } needed_deps = f.recursive_deps.reject{ |d| d.installed? }
unless needed_deps.empty? unless needed_deps.empty?
needed_deps.each do |dep| needed_deps.each do |dep|
@ -369,20 +376,6 @@ class FormulaInstaller
end end
def external_dep_check dep, type
case type
when :python then %W{/usr/bin/env python -c import\ #{dep}}
when :jruby then %W{/usr/bin/env jruby -rubygems -e require\ '#{dep}'}
when :ruby then %W{/usr/bin/env ruby -rubygems -e require\ '#{dep}'}
when :rbx then %W{/usr/bin/env rbx -rubygems -e require\ '#{dep}'}
when :perl then %W{/usr/bin/env perl -e use\ #{dep}}
when :chicken then %W{/usr/bin/env csi -e (use #{dep})}
when :node then %W{/usr/bin/env node -e require('#{dep}');}
when :lua then %W{/usr/bin/env luarocks show #{dep}}
end
end
class Formula class Formula
def keg_only_text def keg_only_text
# Add indent into reason so undent won't truncate the beginnings of lines # Add indent into reason so undent won't truncate the beginnings of lines
@ -400,14 +393,4 @@ class Formula
CPPFLAGS -I#{include} CPPFLAGS -I#{include}
EOS EOS
end end
def check_external_deps
[:ruby, :python, :perl, :jruby, :rbx, :chicken, :node, :lua].each do |type|
self.external_deps[type].each do |dep|
unless quiet_system(*external_dep_check(dep, type))
raise UnsatisfiedExternalDependencyError.new(dep, type)
end
end if self.external_deps[type]
end
end
end end