2013-01-26 20:05:39 -06:00
|
|
|
require 'dependency'
|
|
|
|
require 'dependencies'
|
|
|
|
require 'requirement'
|
|
|
|
require 'requirements'
|
|
|
|
|
|
|
|
## A dependency is a formula that another formula needs to install.
|
|
|
|
## A requirement is something other than a formula that another formula
|
|
|
|
## needs to be present. This includes external language modules,
|
|
|
|
## command-line tools in the path, or any arbitrary predicate.
|
|
|
|
##
|
|
|
|
## The `depends_on` method in the formula DSL is used to declare
|
|
|
|
## dependencies and requirements.
|
|
|
|
|
|
|
|
# This class is used by `depends_on` in the formula DSL to turn dependency
|
|
|
|
# specifications into the proper kinds of dependencies and requirements.
|
|
|
|
class DependencyCollector
|
|
|
|
# Define the languages that we can handle as external dependencies.
|
|
|
|
LANGUAGE_MODULES = [
|
|
|
|
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
attr_reader :deps, :requirements
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@deps = Dependencies.new
|
|
|
|
@requirements = ComparableSet.new
|
|
|
|
end
|
|
|
|
|
2013-01-27 16:53:42 -06:00
|
|
|
def add(spec)
|
|
|
|
case dep = build(spec)
|
|
|
|
when Dependency
|
|
|
|
@deps << dep
|
|
|
|
when Requirement
|
|
|
|
@requirements << dep
|
|
|
|
end
|
|
|
|
dep
|
|
|
|
end
|
|
|
|
|
|
|
|
def build(spec)
|
|
|
|
spec, tag = case spec
|
|
|
|
when Hash then spec.shift
|
|
|
|
else spec
|
|
|
|
end
|
|
|
|
|
|
|
|
parse_spec(spec, tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_spec spec, tag
|
|
|
|
case spec
|
|
|
|
when Symbol
|
|
|
|
parse_symbol_spec(spec, tag)
|
|
|
|
when String
|
|
|
|
if LANGUAGE_MODULES.include? tag
|
|
|
|
LanguageModuleDependency.new(tag, spec)
|
|
|
|
else
|
|
|
|
Dependency.new(spec, tag)
|
|
|
|
end
|
|
|
|
when Formula
|
|
|
|
Dependency.new(spec.name, tag)
|
|
|
|
when Dependency, Requirement
|
|
|
|
spec
|
|
|
|
when Class
|
|
|
|
if spec < Requirement
|
2013-01-30 14:18:11 -06:00
|
|
|
spec.new(tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
else
|
|
|
|
raise "#{spec} is not a Requirement subclass"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise "Unsupported type #{spec.class} for #{spec}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_symbol_spec spec, tag
|
|
|
|
case spec
|
|
|
|
when :autoconf, :automake, :bsdmake, :libtool
|
|
|
|
# Xcode no longer provides autotools or some other build tools
|
|
|
|
Dependency.new(spec.to_s, tag) unless MacOS::Xcode.provides_autotools?
|
|
|
|
when :libpng, :freetype, :pixman, :fontconfig, :cairo
|
|
|
|
if MacOS.version >= :mountain_lion
|
|
|
|
Dependency.new(spec.to_s, tag)
|
|
|
|
else
|
2013-01-27 15:41:45 -06:00
|
|
|
X11Dependency.new(spec.to_s, tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|
|
|
|
when :x11
|
2013-01-27 15:41:45 -06:00
|
|
|
X11Dependency.new(spec.to_s, tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
when :xcode
|
|
|
|
XcodeDependency.new(tag)
|
|
|
|
when :mysql
|
|
|
|
MysqlInstalled.new(tag)
|
|
|
|
when :postgresql
|
|
|
|
PostgresqlInstalled.new(tag)
|
|
|
|
when :tex
|
|
|
|
TeXInstalled.new(tag)
|
|
|
|
when :clt
|
|
|
|
CLTDependency.new(tag)
|
|
|
|
else
|
|
|
|
raise "Unsupported special dependency #{spec}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|