blob: 5eb14354dcb4f8d2bc86b885230e2bb70fa4181b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  | 
require 'requirement'
require 'extend/set'
class X11Dependency < Requirement
  include Comparable
  attr_reader :min_version
  fatal true
  env { ENV.x11 }
  def initialize(name="x11", tags=[])
    @name = name
    @min_version = tags.shift if /(\d\.)+\d/ === tags.first
    super(tags)
  end
  satisfy :build_env => false do
    MacOS::XQuartz.installed? && (@min_version.nil? || @min_version <= MacOS::XQuartz.version)
  end
  def message; <<-EOS.undent
    Unsatisfied dependency: XQuartz #{@min_version}
    Homebrew does not package XQuartz. Installers may be found at:
      https://xquartz.macosforge.org
    EOS
  end
  def <=> other
    unless other.is_a? X11Dependency
      raise TypeError, "expected X11Dependency"
    end
    if min_version.nil? && other.min_version.nil?
      0
    elsif other.min_version.nil?
      1
    elsif @min_version.nil?
      -1
    else
      @min_version <=> other.min_version
    end
  end
  # When X11Dependency is subclassed, the new class should
  # also inherit the information specified in the DSL above.
  def self.inherited(mod)
    instance_variables.each do |ivar|
      mod.instance_variable_set(ivar, instance_variable_get(ivar))
    end
  end
  # X11Dependency::Proxy is a base class for the X11 pseudo-deps.
  # Rather than instantiate it directly, a separate class is built
  # for each of the packages that we proxy to X11Dependency.
  class Proxy < self
    PACKAGES = [:libpng, :freetype, :fontconfig]
    class << self
      def defines_const?(const)
        if ::RUBY_VERSION >= "1.9"
          const_defined?(const, false)
        else
          const_defined?(const)
        end
      end
      def for(name, tags=[])
        constant = name.capitalize
        if defines_const?(constant)
          klass = const_get(constant)
        else
          klass = Class.new(self) do
            def initialize(name, tags) super end
          end
          const_set(constant, klass)
        end
        klass.new(name, tags)
      end
    end
  end
end
  |