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
|
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
|
|
|
|
tags.reject { |tag| RESERVED_TAGS.include? tag }.map { |tag| '--'+tag.to_s }
|
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
|
2012-10-24 18:17:43 -05:00
|
|
|
@tags = [tags].flatten.compact
|
|
|
|
end
|
|
|
|
|
|
|
|
def hash
|
|
|
|
@name.hash
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
@name
|
|
|
|
end
|
|
|
|
|
2012-10-24 18:17:43 -05:00
|
|
|
def ==(other)
|
|
|
|
@name == other.to_s
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
|
2012-10-24 18:17:43 -05:00
|
|
|
def <=>(other)
|
|
|
|
@name <=> other.to_s
|
2012-04-11 18:24:24 -05:00
|
|
|
end
|
|
|
|
|
2012-10-24 18:17:43 -05:00
|
|
|
def eql?(other)
|
|
|
|
other.is_a? self.class and hash == other.hash
|
2012-02-28 19:56:29 -08:00
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
|
attr_reader :tags
|
|
|
|
|
|
|
|
def initialize(*tags)
|
|
|
|
@tags = tags.flatten.compact
|
|
|
|
end
|
|
|
|
|
2012-08-09 20:32:57 -07:00
|
|
|
# Should return true if this requirement is met.
|
2012-02-28 19:56:29 -08:00
|
|
|
def satisfied?; false; end
|
2012-08-09 20:32:57 -07:00
|
|
|
# Should return true if not meeting this requirement should fail the build.
|
2012-12-23 19:44:15 -06:00
|
|
|
def fatal?
|
|
|
|
self.class.fatal || false
|
|
|
|
end
|
2012-08-09 20:32:57 -07:00
|
|
|
# The message to show when the requirement is not met.
|
2012-02-28 19:56:29 -08:00
|
|
|
def message; ""; end
|
2012-08-09 20:32:57 -07:00
|
|
|
|
|
|
|
# Requirements can modify the current build environment by overriding this.
|
|
|
|
# See X11Dependency
|
2012-07-09 11:33:43 -05:00
|
|
|
def modify_build_environment; nil 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)
|
|
|
|
other.is_a? self.class and hash == other.hash
|
|
|
|
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
|
|
|
|
|
|
|
class << self
|
|
|
|
def fatal(val=nil)
|
|
|
|
val.nil? ? @fatal : @fatal = val
|
|
|
|
end
|
2012-12-23 19:44:56 -06:00
|
|
|
|
|
|
|
def env(*settings)
|
|
|
|
@env ||= BuildEnvironment.new
|
|
|
|
settings.each { |s| @env << s }
|
|
|
|
@env
|
|
|
|
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'
|