2012-12-23 19:44:56 -06:00
|
|
|
require 'build_environment'
|
|
|
|
|
2012-02-28 19:56:29 -08:00
|
|
|
## This file defines dependencies and 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 = [
|
2012-11-28 01:21:03 -05:00
|
|
|
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
|
2012-02-28 19:56:29 -08:00
|
|
|
].freeze
|
|
|
|
|
2012-07-23 17:06:38 -07:00
|
|
|
attr_reader :deps, :requirements
|
2012-02-28 19:56:29 -08:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@deps = Dependencies.new
|
2012-10-02 13:21:00 -05:00
|
|
|
@requirements = ComparableSet.new
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def add spec
|
2012-06-07 22:29:44 +02:00
|
|
|
tag = nil
|
|
|
|
spec, tag = spec.shift if spec.is_a? Hash
|
|
|
|
|
2012-07-03 07:49:30 -07:00
|
|
|
dep = parse_spec(spec, tag)
|
|
|
|
# Some symbol specs are conditional, and resolve to nil if there is no
|
|
|
|
# dependency needed for the current platform.
|
|
|
|
return if dep.nil?
|
|
|
|
# Add dep to the correct bucket
|
2012-07-23 17:06:38 -07:00
|
|
|
(dep.is_a?(Requirement) ? @requirements : @deps) << dep
|
2012-07-03 07:49:30 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_spec spec, tag
|
|
|
|
case spec
|
2012-06-08 04:31:51 +02:00
|
|
|
when Symbol
|
2012-07-03 07:49:30 -07:00
|
|
|
parse_symbol_spec(spec, tag)
|
2012-06-07 22:29:44 +02:00
|
|
|
when String
|
|
|
|
if LANGUAGE_MODULES.include? tag
|
|
|
|
LanguageModuleDependency.new(tag, spec)
|
2012-02-28 19:56:29 -08:00
|
|
|
else
|
2012-06-07 22:29:44 +02:00
|
|
|
Dependency.new(spec, tag)
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
2012-06-07 22:29:44 +02:00
|
|
|
when Formula
|
|
|
|
Dependency.new(spec.name, tag)
|
|
|
|
when Dependency, Requirement
|
|
|
|
spec
|
2013-01-26 14:33:03 +00:00
|
|
|
when Class
|
|
|
|
if spec < Requirement
|
|
|
|
spec.new
|
|
|
|
else
|
|
|
|
raise "#{spec} is not a Requirement subclass"
|
|
|
|
end
|
2012-02-28 19:56:29 -08:00
|
|
|
else
|
|
|
|
raise "Unsupported type #{spec.class} for #{spec}"
|
|
|
|
end
|
2012-07-03 07:49:30 -07:00
|
|
|
end
|
2012-06-07 22:29:44 +02:00
|
|
|
|
2012-07-03 07:49:30 -07:00
|
|
|
def parse_symbol_spec spec, tag
|
|
|
|
case spec
|
2012-07-10 09:53:03 -07:00
|
|
|
when :autoconf, :automake, :bsdmake, :libtool
|
|
|
|
# Xcode no longer provides autotools or some other build tools
|
2012-10-24 18:17:43 -05:00
|
|
|
Dependency.new(spec.to_s, tag) unless MacOS::Xcode.provides_autotools?
|
2012-07-30 21:34:44 +01:00
|
|
|
when :libpng, :freetype, :pixman, :fontconfig, :cairo
|
2012-08-22 13:34:26 -07:00
|
|
|
if MacOS.version >= :mountain_lion
|
2012-10-24 18:17:43 -05:00
|
|
|
Dependency.new(spec.to_s, tag)
|
2012-07-30 21:34:44 +01:00
|
|
|
else
|
|
|
|
X11Dependency.new(tag)
|
|
|
|
end
|
|
|
|
when :x11
|
2012-07-03 07:49:30 -07:00
|
|
|
X11Dependency.new(tag)
|
2012-07-12 07:08:23 -07:00
|
|
|
when :xcode
|
2012-10-24 18:17:43 -05:00
|
|
|
XcodeDependency.new(tag)
|
2012-11-05 20:03:26 -06:00
|
|
|
when :mysql
|
|
|
|
MysqlInstalled.new(tag)
|
|
|
|
when :postgresql
|
|
|
|
PostgresqlInstalled.new(tag)
|
2012-12-13 22:23:06 -08:00
|
|
|
when :tex
|
|
|
|
TeXInstalled.new(tag)
|
2012-07-03 07:49:30 -07:00
|
|
|
else
|
|
|
|
raise "Unsupported special dependency #{spec}"
|
|
|
|
end
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
2012-06-07 18:34:40 +02:00
|
|
|
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
2013-01-07 14:06:34 -06:00
|
|
|
class Dependencies
|
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
@deps = Array.new(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def each(*args, &block)
|
|
|
|
@deps.each(*args, &block)
|
|
|
|
end
|
2012-02-28 19:56:29 -08:00
|
|
|
|
2012-10-24 18:17:43 -05:00
|
|
|
def <<(o)
|
2013-01-07 14:06:34 -06:00
|
|
|
@deps << o unless @deps.include? o
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty?
|
|
|
|
@deps.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def *(arg)
|
|
|
|
@deps * arg
|
2012-10-24 18:17:43 -05:00
|
|
|
end
|
2013-01-07 18:16:11 -06:00
|
|
|
|
|
|
|
def to_ary
|
|
|
|
@deps
|
|
|
|
end
|
2012-10-24 18:17:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module Dependable
|
|
|
|
RESERVED_TAGS = [:build, :optional, :recommended]
|
|
|
|
|
|
|
|
def build?
|
|
|
|
tags.include? :build
|
|
|
|
end
|
|
|
|
|
|
|
|
def optional?
|
|
|
|
tags.include? :optional
|
|
|
|
end
|
|
|
|
|
|
|
|
def recommended?
|
|
|
|
tags.include? :recommended
|
|
|
|
end
|
|
|
|
|
|
|
|
def options
|
2013-01-23 00:26:28 -06:00
|
|
|
Options.coerce(tags - RESERVED_TAGS)
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# A dependency on another Homebrew formula.
|
|
|
|
class Dependency
|
2012-10-24 18:17:43 -05:00
|
|
|
include Dependable
|
|
|
|
|
2012-02-28 19:56:29 -08:00
|
|
|
attr_reader :name, :tags
|
|
|
|
|
2012-10-24 18:17:43 -05:00
|
|
|
def initialize(name, *tags)
|
2012-02-28 19:56:29 -08:00
|
|
|
@name = name
|
2013-01-13 19:51:19 -06:00
|
|
|
@tags = tags.flatten.compact
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2013-01-13 19:51:19 -06:00
|
|
|
name
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
2012-10-24 18:17:43 -05:00
|
|
|
def ==(other)
|
2013-01-13 19:51:19 -06:00
|
|
|
name == other.name
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
2013-01-13 19:51:19 -06:00
|
|
|
def eql?(other)
|
|
|
|
other.is_a?(self.class) && hash == other.hash
|
2012-04-11 18:24:24 -05:00
|
|
|
end
|
|
|
|
|
2013-01-13 19:51:19 -06:00
|
|
|
def hash
|
|
|
|
name.hash
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
2013-01-23 00:26:24 -06:00
|
|
|
|
|
|
|
def to_formula
|
2013-01-23 00:26:28 -06:00
|
|
|
f = Formula.factory(name)
|
|
|
|
# Add this dependency's options to the formula's build args
|
|
|
|
f.build.args = f.build.args.concat(options)
|
|
|
|
f
|
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
|
|
|
to_formula.installed?
|
2013-01-23 00:26:24 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def requested?
|
|
|
|
ARGV.formulae.include?(to_formula) rescue false
|
|
|
|
end
|
2013-01-23 00:26:26 -06:00
|
|
|
|
2013-01-23 00:26:28 -06:00
|
|
|
def universal!
|
|
|
|
tags << 'universal' if to_formula.build.has_option? 'universal'
|
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:26 -06:00
|
|
|
# Expand the dependencies of f recursively, optionally yielding
|
|
|
|
# [f, dep] to allow callers to apply arbitrary filters to the list.
|
|
|
|
# The default filter, which is used when a block is not supplied,
|
|
|
|
# omits optionals and recommendeds based on what the dependent has
|
|
|
|
# asked for.
|
|
|
|
def self.expand(dependent, &block)
|
|
|
|
dependent.deps.map do |dep|
|
|
|
|
prune = catch(:prune) do
|
|
|
|
if block_given?
|
|
|
|
yield dependent, dep
|
|
|
|
elsif dep.optional? || dep.recommended?
|
|
|
|
Dependency.prune unless dependent.build.with?(dep.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
next if prune
|
|
|
|
|
|
|
|
expand(dep.to_formula, &block) << dep
|
|
|
|
end.flatten.compact.uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
# Used to prune dependencies when calling expand_dependencies with a block.
|
|
|
|
def self.prune
|
|
|
|
throw(:prune, true)
|
|
|
|
end
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
# A base class for non-formula requirements needed by formulae.
|
|
|
|
# A "fatal" requirement is one that will fail the build if it is not present.
|
|
|
|
# By default, Requirements are non-fatal.
|
|
|
|
class Requirement
|
2012-10-24 18:17:43 -05:00
|
|
|
include Dependable
|
2013-01-19 20:45:57 -06:00
|
|
|
extend BuildEnvironmentDSL
|
2012-10-24 18:17:43 -05:00
|
|
|
|
|
|
|
attr_reader :tags
|
|
|
|
|
|
|
|
def initialize(*tags)
|
|
|
|
@tags = tags.flatten.compact
|
|
|
|
end
|
|
|
|
|
2013-01-19 20:45:58 -06:00
|
|
|
# The message to show when the requirement is not met.
|
|
|
|
def message; "" end
|
|
|
|
|
|
|
|
# Overriding #satisfied? is deprepcated.
|
|
|
|
# Pass a block or boolean to the satisfied DSL method instead.
|
|
|
|
def satisfied?
|
2013-01-22 14:33:33 -06:00
|
|
|
result = self.class.satisfy.yielder do |proc|
|
2013-01-19 20:45:58 -06:00
|
|
|
instance_eval(&proc)
|
|
|
|
end
|
2013-01-22 14:33:33 -06:00
|
|
|
|
|
|
|
infer_env_modification(result)
|
|
|
|
!!result
|
2013-01-19 20:45:58 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
# Overriding #fatal? is deprecated.
|
|
|
|
# Pass a boolean to the fatal DSL method instead.
|
2012-12-23 19:44:15 -06:00
|
|
|
def fatal?
|
|
|
|
self.class.fatal || false
|
|
|
|
end
|
2012-08-09 20:32:57 -07:00
|
|
|
|
2013-01-19 20:45:58 -06:00
|
|
|
# Overriding #modify_build_environment is deprecated.
|
|
|
|
# Pass a block to the the env DSL method instead.
|
2013-01-19 20:45:57 -06:00
|
|
|
def modify_build_environment
|
2013-01-19 20:45:58 -06:00
|
|
|
satisfied? and env.modify_build_environment(self)
|
2013-01-19 20:45:57 -06:00
|
|
|
end
|
2012-07-27 02:50:29 -05:00
|
|
|
|
2012-12-23 19:44:56 -06:00
|
|
|
def env
|
|
|
|
@env ||= self.class.env
|
|
|
|
end
|
|
|
|
|
2012-07-27 02:50:29 -05:00
|
|
|
def eql?(other)
|
2013-01-13 19:51:19 -06:00
|
|
|
other.is_a?(self.class) && hash == other.hash
|
2012-07-27 02:50:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def hash
|
2012-08-14 23:13:18 -05:00
|
|
|
message.hash
|
2012-07-27 02:50:29 -05:00
|
|
|
end
|
2012-12-23 19:44:15 -06:00
|
|
|
|
2013-01-22 14:33:33 -06:00
|
|
|
private
|
|
|
|
|
|
|
|
def infer_env_modification(o)
|
|
|
|
case o
|
|
|
|
when Pathname
|
|
|
|
self.class.env do
|
|
|
|
unless ENV["PATH"].split(":").include?(o.parent.to_s)
|
|
|
|
append("PATH", o.parent, ":")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 19:44:15 -06:00
|
|
|
class << self
|
|
|
|
def fatal(val=nil)
|
|
|
|
val.nil? ? @fatal : @fatal = val
|
|
|
|
end
|
2013-01-19 20:45:58 -06:00
|
|
|
|
|
|
|
def satisfy(options={}, &block)
|
2013-01-22 14:33:33 -06:00
|
|
|
@satisfied ||= Requirement::Satisfier.new(options, &block)
|
2013-01-19 20:45:58 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Satisfier
|
|
|
|
def initialize(options={}, &block)
|
2013-01-22 14:33:33 -06:00
|
|
|
case options
|
|
|
|
when Hash
|
|
|
|
@options = { :build_env => true }
|
|
|
|
@options.merge!(options)
|
|
|
|
else
|
|
|
|
@satisfied = options
|
|
|
|
end
|
2013-01-19 20:45:58 -06:00
|
|
|
@proc = block
|
|
|
|
end
|
|
|
|
|
|
|
|
def yielder
|
2013-01-22 14:33:33 -06:00
|
|
|
if instance_variable_defined?(:@satisfied)
|
|
|
|
@satisfied
|
|
|
|
elsif @options[:build_env]
|
2013-01-19 20:45:58 -06:00
|
|
|
require 'superenv'
|
|
|
|
ENV.with_build_environment do
|
2013-01-22 14:11:21 -06:00
|
|
|
ENV.userpaths!
|
2013-01-19 20:45:58 -06:00
|
|
|
yield @proc
|
|
|
|
end
|
|
|
|
else
|
|
|
|
yield @proc
|
|
|
|
end
|
|
|
|
end
|
2012-12-23 19:44:15 -06:00
|
|
|
end
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
2012-10-24 18:06:00 -05:00
|
|
|
require 'requirements'
|