2015-08-03 13:09:07 +01:00
|
|
|
require "dependency"
|
|
|
|
require "dependencies"
|
|
|
|
require "ld64_dependency"
|
|
|
|
require "requirement"
|
|
|
|
require "requirements"
|
|
|
|
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[
|
2016-01-01 19:49:43 -04:00
|
|
|
:lua, :lua51, :perl, :python, :python3, :ruby
|
2013-01-26 20:05:39 -06:00
|
|
|
].freeze
|
|
|
|
|
2014-02-27 14:22:43 -06:00
|
|
|
CACHE = {}
|
|
|
|
|
2014-07-02 15:10:07 -05:00
|
|
|
def self.clear_cache
|
|
|
|
CACHE.clear
|
|
|
|
end
|
|
|
|
|
2013-01-26 20:05:39 -06:00
|
|
|
attr_reader :deps, :requirements
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@deps = Dependencies.new
|
2014-07-03 14:50:57 -05:00
|
|
|
@requirements = Requirements.new
|
2013-01-26 20:05:39 -06:00
|
|
|
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)
|
2016-09-20 22:03:08 +02:00
|
|
|
if spec.is_a?(Resource) && spec.download_strategy == CurlDownloadStrategy
|
2014-02-27 14:22:43 -06:00
|
|
|
File.extname(spec.url)
|
|
|
|
else
|
|
|
|
spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-27 16:53:42 -06:00
|
|
|
def build(spec)
|
2016-09-20 22:03:08 +02:00
|
|
|
spec, tags = spec.is_a?(Hash) ? spec.first : spec
|
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-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
|
2014-07-01 15:07:06 -05:00
|
|
|
raise TypeError, "Unsupported type #{spec.class.name} 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)
|
2016-09-20 22:03:08 +02:00
|
|
|
if spec =~ HOMEBREW_TAP_FORMULA_REGEX
|
2015-04-06 23:20:07 -07:00
|
|
|
TapDependency.new(spec, tags)
|
|
|
|
elsif tags.empty?
|
2013-05-06 16:08:50 -05:00
|
|
|
Dependency.new(spec, tags)
|
|
|
|
elsif (tag = tags.first) && LANGUAGE_MODULES.include?(tag)
|
2015-06-15 09:56:04 +01:00
|
|
|
LanguageModuleRequirement.new(tag, spec, tags[1])
|
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
|
2015-06-15 09:56:04 +01:00
|
|
|
when :x11 then X11Requirement.new(spec.to_s, tags)
|
|
|
|
when :xcode then XcodeRequirement.new(tags)
|
2013-05-24 08:37:16 -07:00
|
|
|
when :macos then MinimumMacOSRequirement.new(tags)
|
2015-06-15 09:56:04 +01:00
|
|
|
when :mysql then MysqlRequirement.new(tags)
|
|
|
|
when :postgresql then PostgresqlRequirement.new(tags)
|
2016-08-10 21:00:14 +01:00
|
|
|
when :gpg then GPG2Requirement.new(tags)
|
2015-06-15 09:56:04 +01:00
|
|
|
when :fortran then FortranRequirement.new(tags)
|
|
|
|
when :mpi then MPIRequirement.new(*tags)
|
|
|
|
when :tex then TeXRequirement.new(tags)
|
2013-05-06 16:08:50 -05:00
|
|
|
when :arch then ArchRequirement.new(tags)
|
2015-06-15 09:56:04 +01:00
|
|
|
when :hg then MercurialRequirement.new(tags)
|
|
|
|
when :python then PythonRequirement.new(tags)
|
|
|
|
when :python3 then Python3Requirement.new(tags)
|
|
|
|
when :java then JavaRequirement.new(tags)
|
2016-01-09 02:22:43 +00:00
|
|
|
when :rbenv then RbenvRequirement.new(tags)
|
2015-04-11 19:18:40 +01:00
|
|
|
when :ruby then RubyRequirement.new(tags)
|
2015-06-15 09:56:04 +01:00
|
|
|
when :osxfuse then OsxfuseRequirement.new(tags)
|
2016-05-02 19:39:56 +01:00
|
|
|
when :perl then PerlRequirement.new(tags)
|
2015-06-15 09:56:04 +01:00
|
|
|
when :tuntap then TuntapRequirement.new(tags)
|
2014-12-05 01:34:56 -05:00
|
|
|
when :ant then ant_dep(spec, tags)
|
2015-06-15 09:56:04 +01:00
|
|
|
when :apr then AprRequirement.new(tags)
|
2015-05-08 14:37:15 +08:00
|
|
|
when :emacs then EmacsRequirement.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-05-06 17:52:42 -05:00
|
|
|
# Tiger doesn't ship expat in /usr/lib
|
|
|
|
when :expat then Dependency.new("expat", tag) if MacOS.version < :leopard
|
2014-12-05 01:34:56 -05:00
|
|
|
when :python2
|
2015-06-15 09:56:04 +01:00
|
|
|
PythonRequirement.new(tags)
|
2013-01-26 20:05:39 -06:00
|
|
|
else
|
2014-03-22 10:31:00 +00:00
|
|
|
raise ArgumentError, "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
|
|
|
|
|
2016-09-22 17:47:50 -04:00
|
|
|
def ant_dep(spec, tags)
|
|
|
|
Dependency.new(spec.to_s, tags)
|
|
|
|
end
|
|
|
|
|
2013-09-28 16:37:05 -05:00
|
|
|
def resource_dep(spec, tags)
|
|
|
|
tags << :build
|
|
|
|
strategy = spec.download_strategy
|
|
|
|
|
2016-09-17 15:17:27 +01:00
|
|
|
if strategy <= CurlDownloadStrategy
|
2013-09-28 16:37:05 -05:00
|
|
|
parse_url_spec(spec.url, tags)
|
2016-09-17 15:17:27 +01:00
|
|
|
elsif strategy <= GitDownloadStrategy
|
2015-06-15 09:56:04 +01:00
|
|
|
GitRequirement.new(tags)
|
2016-09-17 15:17:27 +01:00
|
|
|
elsif strategy <= MercurialDownloadStrategy
|
2015-06-15 09:56:04 +01:00
|
|
|
MercurialRequirement.new(tags)
|
2016-09-17 15:17:27 +01:00
|
|
|
elsif strategy <= FossilDownloadStrategy
|
2013-09-28 16:37:05 -05:00
|
|
|
Dependency.new("fossil", tags)
|
2016-09-17 15:17:27 +01:00
|
|
|
elsif strategy <= BazaarDownloadStrategy
|
2013-09-28 16:37:05 -05:00
|
|
|
Dependency.new("bazaar", tags)
|
2016-09-17 15:17:27 +01:00
|
|
|
elsif strategy <= CVSDownloadStrategy
|
2014-04-02 19:58:15 -05:00
|
|
|
Dependency.new("cvs", tags) if MacOS.version >= :mavericks || !MacOS::Xcode.provides_cvs?
|
2016-09-17 15:17:27 +01:00
|
|
|
elsif strategy < AbstractDownloadStrategy
|
2013-09-28 16:37:05 -05:00
|
|
|
# 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)
|
2016-09-21 08:32:57 +02:00
|
|
|
when ".xz" then Dependency.new("xz", tags)
|
2015-12-31 19:48:07 -04:00
|
|
|
when ".lha", ".lzh" then Dependency.new("lha", tags)
|
2016-09-21 08:32:57 +02:00
|
|
|
when ".lz" then Dependency.new("lzip", tags)
|
|
|
|
when ".rar" then Dependency.new("unrar", tags)
|
|
|
|
when ".7z" then Dependency.new("p7zip", tags)
|
2013-09-28 16:37:05 -05:00
|
|
|
end
|
|
|
|
end
|
2013-01-26 20:05:39 -06:00
|
|
|
end
|
2016-09-18 16:23:36 -04:00
|
|
|
|
|
|
|
require "extend/os/dependency_collector"
|