2013-01-26 20:05:39 -06:00
|
|
|
require 'dependency'
|
|
|
|
require 'dependencies'
|
|
|
|
require 'requirement'
|
|
|
|
require 'requirements'
|
2013-04-13 21:11:14 -05:00
|
|
|
require 'requirements/ld64_dependency'
|
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-06-17 09:06:38 +02:00
|
|
|
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
|
2013-01-26 20:05:39 -06:00
|
|
|
].freeze
|
|
|
|
|
2014-02-27 14:22:43 -06:00
|
|
|
CACHE = {}
|
|
|
|
|
2013-01-26 20:05:39 -06:00
|
|
|
attr_reader :deps, :requirements
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@deps = Dependencies.new
|
|
|
|
@requirements = ComparableSet.new
|
|
|
|
end
|
|
|
|
|
2013-01-27 16:53:42 -06:00
|
|
|
def add(spec)
|
2014-02-27 14:22:43 -06:00
|
|
|
case dep = fetch(spec)
|
2013-01-27 16:53:42 -06:00
|
|
|
when Dependency
|
|
|
|
@deps << dep
|
|
|
|
when Requirement
|
|
|
|
@requirements << dep
|
|
|
|
end
|
|
|
|
dep
|
|
|
|
end
|
|
|
|
|
2014-02-27 14:22:43 -06:00
|
|
|
def fetch(spec)
|
|
|
|
CACHE.fetch(cache_key(spec)) { |key| CACHE[key] = build(spec) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache_key(spec)
|
|
|
|
if Resource === spec && spec.download_strategy == CurlDownloadStrategy
|
|
|
|
File.extname(spec.url)
|
|
|
|
else
|
|
|
|
spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-27 16:53:42 -06:00
|
|
|
def build(spec)
|
2013-05-06 16:08:50 -05:00
|
|
|
spec, tags = case spec
|
2013-09-13 09:51:23 -05:00
|
|
|
when Hash then destructure_spec_hash(spec)
|
2013-05-06 16:08:50 -05:00
|
|
|
else spec
|
|
|
|
end
|
2013-01-27 16:53:42 -06:00
|
|
|
|
2013-05-06 16:08:50 -05:00
|
|
|
parse_spec(spec, Array(tags))
|
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
|
|
|
|
2013-09-13 09:51:23 -05:00
|
|
|
def destructure_spec_hash(spec)
|
|
|
|
spec.each { |o| return o }
|
|
|
|
end
|
|
|
|
|
2013-05-06 16:08:50 -05:00
|
|
|
def parse_spec(spec, tags)
|
2013-01-26 20:05:39 -06:00
|
|
|
case spec
|
|
|
|
when String
|
2013-05-06 16:08:50 -05:00
|
|
|
parse_string_spec(spec, tags)
|
2013-09-28 16:37:05 -05:00
|
|
|
when Resource
|
|
|
|
resource_dep(spec, tags)
|
2013-04-17 14:05:47 -05:00
|
|
|
when Symbol
|
2013-05-06 16:08:50 -05:00
|
|
|
parse_symbol_spec(spec, tags)
|
2013-05-06 16:08:49 -05:00
|
|
|
when Requirement, Dependency
|
2013-01-26 20:05:39 -06:00
|
|
|
spec
|
|
|
|
when Class
|
2013-05-06 16:08:50 -05:00
|
|
|
parse_class_spec(spec, tags)
|
2013-01-26 20:05:39 -06:00
|
|
|
else
|
2013-06-26 15:25:09 -05:00
|
|
|
raise TypeError, "Unsupported type #{spec.class} for #{spec.inspect}"
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-06 16:08:50 -05:00
|
|
|
def parse_string_spec(spec, tags)
|
|
|
|
if tags.empty?
|
|
|
|
Dependency.new(spec, tags)
|
|
|
|
elsif (tag = tags.first) && LANGUAGE_MODULES.include?(tag)
|
2013-05-06 16:08:49 -05:00
|
|
|
LanguageModuleDependency.new(tag, spec)
|
2014-02-28 11:16:55 -06:00
|
|
|
elsif HOMEBREW_TAP_FORMULA_REGEX === spec
|
|
|
|
TapDependency.new(spec, tags)
|
2013-05-06 16:08:49 -05:00
|
|
|
else
|
2013-05-06 16:08:50 -05:00
|
|
|
Dependency.new(spec, tags)
|
2013-05-06 16:08:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-06 16:08:50 -05:00
|
|
|
def parse_symbol_spec(spec, tags)
|
2013-01-26 20:05:39 -06:00
|
|
|
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-05-06 16:08:50 -05:00
|
|
|
autotools_dep(spec, tags)
|
|
|
|
when :x11 then X11Dependency.new(spec.to_s, tags)
|
2014-03-05 20:12:51 -06:00
|
|
|
when :cairo, :fontconfig, :freetype, :libpng, :pixman
|
|
|
|
# We no longer use X11 proxy deps, but we support the symbols
|
|
|
|
# for backwards compatibility.
|
2013-05-06 16:08:50 -05:00
|
|
|
Dependency.new(spec.to_s, tags)
|
|
|
|
when :xcode then XcodeDependency.new(tags)
|
2013-05-24 08:37:16 -07:00
|
|
|
when :macos then MinimumMacOSRequirement.new(tags)
|
2013-05-06 16:08:50 -05:00
|
|
|
when :mysql then MysqlDependency.new(tags)
|
|
|
|
when :postgresql then PostgresqlDependency.new(tags)
|
2013-06-25 21:08:59 -05:00
|
|
|
when :fortran then FortranDependency.new(tags)
|
2013-06-26 22:08:54 -05:00
|
|
|
when :mpi then MPIDependency.new(*tags)
|
2013-05-06 16:08:50 -05:00
|
|
|
when :tex then TeXDependency.new(tags)
|
|
|
|
when :clt then CLTDependency.new(tags)
|
|
|
|
when :arch then ArchRequirement.new(tags)
|
|
|
|
when :hg then MercurialDependency.new(tags)
|
2014-01-04 13:18:42 +00:00
|
|
|
# python2 is deprecated
|
|
|
|
when :python, :python2 then PythonDependency.new(tags)
|
|
|
|
when :python3 then Python3Dependency.new(tags)
|
2013-04-13 21:11:14 -05:00
|
|
|
# Tiger's ld is too old to properly link some software
|
|
|
|
when :ld64 then LD64Dependency.new if MacOS.version < :leopard
|
2013-10-28 14:44:20 -05:00
|
|
|
when :ant then ant_dep(spec, tags)
|
2013-01-26 20:05:39 -06:00
|
|
|
else
|
2013-06-26 15:25:09 -05:00
|
|
|
raise "Unsupported special dependency #{spec.inspect}"
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|
|
|
|
end
|
2013-02-10 19:25:22 -06:00
|
|
|
|
2013-05-06 16:08:50 -05:00
|
|
|
def parse_class_spec(spec, tags)
|
2013-05-06 16:08:49 -05:00
|
|
|
if spec < Requirement
|
2013-05-06 16:08:50 -05:00
|
|
|
spec.new(tags)
|
2013-05-06 16:08:49 -05:00
|
|
|
else
|
2013-06-26 15:25:09 -05:00
|
|
|
raise TypeError, "#{spec.inspect} is not a Requirement subclass"
|
2013-05-06 16:08:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-06 16:08:50 -05:00
|
|
|
def autotools_dep(spec, tags)
|
2013-11-04 12:00:06 -06:00
|
|
|
return if MacOS::Xcode.provides_autotools?
|
2013-05-06 16:08:50 -05:00
|
|
|
|
2013-11-04 12:00:06 -06:00
|
|
|
if spec == :libltdl
|
|
|
|
spec = :libtool
|
|
|
|
tags << :run
|
2013-02-10 19:25:22 -06:00
|
|
|
end
|
2013-11-04 12:00:06 -06:00
|
|
|
|
|
|
|
tags << :build unless tags.include? :run
|
|
|
|
Dependency.new(spec.to_s, tags)
|
2013-02-10 19:25:22 -06:00
|
|
|
end
|
2013-09-28 16:37:05 -05:00
|
|
|
|
2013-10-28 14:44:20 -05:00
|
|
|
def ant_dep(spec, tags)
|
|
|
|
if MacOS.version >= :mavericks
|
|
|
|
tags << :build
|
|
|
|
Dependency.new(spec.to_s, tags)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-28 16:37:05 -05:00
|
|
|
def resource_dep(spec, tags)
|
|
|
|
tags << :build
|
|
|
|
strategy = spec.download_strategy
|
|
|
|
|
|
|
|
case
|
|
|
|
when strategy <= CurlDownloadStrategy
|
|
|
|
parse_url_spec(spec.url, tags)
|
|
|
|
when strategy <= GitDownloadStrategy
|
|
|
|
GitDependency.new(tags)
|
|
|
|
when strategy <= MercurialDownloadStrategy
|
|
|
|
MercurialDependency.new(tags)
|
|
|
|
when strategy <= FossilDownloadStrategy
|
|
|
|
Dependency.new("fossil", tags)
|
|
|
|
when strategy <= BazaarDownloadStrategy
|
|
|
|
Dependency.new("bazaar", tags)
|
2013-11-18 15:58:41 -06:00
|
|
|
when strategy <= CVSDownloadStrategy
|
2013-12-04 01:10:11 -06:00
|
|
|
Dependency.new("cvs", tags) unless MacOS::Xcode.provides_cvs?
|
2013-09-28 16:37:05 -05:00
|
|
|
when strategy < AbstractDownloadStrategy
|
|
|
|
# allow unknown strategies to pass through
|
|
|
|
else
|
|
|
|
raise TypeError,
|
|
|
|
"#{strategy.inspect} is not an AbstractDownloadStrategy subclass"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_url_spec(url, tags)
|
|
|
|
case File.extname(url)
|
|
|
|
when '.xz' then Dependency.new('xz', tags)
|
2013-11-29 10:10:28 -08:00
|
|
|
when '.lz' then Dependency.new('lzip', tags)
|
2013-09-28 16:37:05 -05:00
|
|
|
when '.rar' then Dependency.new('unrar', tags)
|
|
|
|
when '.7z' then Dependency.new('p7zip', tags)
|
|
|
|
end
|
|
|
|
end
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|