2013-01-26 20:05:39 -06:00
|
|
|
require 'dependency'
|
|
|
|
require 'dependencies'
|
|
|
|
require 'requirement'
|
|
|
|
require 'requirements'
|
2013-04-16 03:31:29 -05:00
|
|
|
require 'set'
|
2013-01-26 20:05:39 -06:00
|
|
|
|
|
|
|
## 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.
|
2013-04-16 03:31:29 -05:00
|
|
|
LANGUAGE_MODULES = Set[
|
2013-01-26 20:05:39 -06:00
|
|
|
: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
|
|
|
|
|
2013-04-07 00:49:56 -05:00
|
|
|
private
|
2013-01-26 20:05:39 -06:00
|
|
|
|
|
|
|
def parse_spec spec, tag
|
|
|
|
case spec
|
|
|
|
when String
|
2013-05-06 16:08:49 -05:00
|
|
|
parse_string_spec(spec, tag)
|
2013-04-17 14:05:47 -05:00
|
|
|
when Symbol
|
|
|
|
parse_symbol_spec(spec, tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
when Dependency, Requirement
|
|
|
|
spec
|
|
|
|
when Class
|
2013-05-06 16:08:49 -05:00
|
|
|
parse_class_spec(spec, tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
else
|
|
|
|
raise "Unsupported type #{spec.class} for #{spec}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-06 16:08:49 -05:00
|
|
|
def parse_string_spec(spec, tag)
|
|
|
|
if tag && LANGUAGE_MODULES.include?(tag)
|
|
|
|
LanguageModuleDependency.new(tag, spec)
|
|
|
|
else
|
|
|
|
Dependency.new(spec, tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-26 20:05:39 -06:00
|
|
|
def parse_symbol_spec spec, tag
|
|
|
|
case spec
|
2013-02-10 19:26:18 -06:00
|
|
|
when :autoconf, :automake, :bsdmake, :libtool, :libltdl
|
2013-01-26 20:05:39 -06:00
|
|
|
# Xcode no longer provides autotools or some other build tools
|
2013-02-10 19:25:22 -06:00
|
|
|
autotools_dep(spec, tag)
|
2013-04-17 14:05:47 -05:00
|
|
|
when :x11 then X11Dependency.new(spec.to_s, tag)
|
2013-01-29 22:52:10 -06:00
|
|
|
when *X11Dependency::Proxy::PACKAGES
|
2013-02-10 19:25:22 -06:00
|
|
|
x11_dep(spec, tag)
|
2013-02-02 00:09:28 -06:00
|
|
|
when :cairo, :pixman
|
|
|
|
# We no longer use X11 psuedo-deps for cairo or pixman,
|
|
|
|
# so just return a standard formula dependency.
|
|
|
|
Dependency.new(spec.to_s, tag)
|
2013-01-29 22:52:10 -06:00
|
|
|
when :xcode then XcodeDependency.new(tag)
|
2013-02-12 16:24:30 -06:00
|
|
|
when :mysql then MysqlDependency.new(tag)
|
|
|
|
when :postgresql then PostgresqlDependency.new(tag)
|
|
|
|
when :tex then TeXDependency.new(tag)
|
2013-01-29 22:52:10 -06:00
|
|
|
when :clt then CLTDependency.new(tag)
|
2013-04-01 11:53:13 -05:00
|
|
|
when :arch then ArchRequirement.new(tag)
|
2013-04-17 10:01:38 -07:00
|
|
|
when :hg then MercurialDependency.new(tag)
|
2013-01-26 20:05:39 -06:00
|
|
|
else
|
|
|
|
raise "Unsupported special dependency #{spec}"
|
|
|
|
end
|
|
|
|
end
|
2013-02-10 19:25:22 -06:00
|
|
|
|
2013-05-06 16:08:49 -05:00
|
|
|
def parse_class_spec(spec, tag)
|
|
|
|
if spec < Requirement
|
|
|
|
spec.new(tag)
|
|
|
|
else
|
|
|
|
raise "#{spec} is not a Requirement subclass"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-10 19:25:22 -06:00
|
|
|
def x11_dep(spec, tag)
|
|
|
|
if MacOS.version >= :mountain_lion
|
|
|
|
Dependency.new(spec.to_s, tag)
|
|
|
|
else
|
|
|
|
X11Dependency::Proxy.for(spec.to_s, tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def autotools_dep(spec, tag)
|
2013-02-10 19:26:18 -06:00
|
|
|
case spec
|
|
|
|
when :libltdl then spec, tag = :libtool, Array(tag)
|
|
|
|
else tag = Array(tag) << :build
|
|
|
|
end
|
|
|
|
|
2013-02-10 19:25:22 -06:00
|
|
|
unless MacOS::Xcode.provides_autotools?
|
2013-02-10 19:26:18 -06:00
|
|
|
Dependency.new(spec.to_s, tag)
|
2013-02-10 19:25:22 -06:00
|
|
|
end
|
|
|
|
end
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|