public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Hongli Lai (Phusion) (author)
Thu Apr 03 05:04:24 -0700 2008
commit  3dd968d7eff557447de197b509e4907c94a55a3b
tree    d26792832914a844d4c33567b753084e25f640e4
parent  67c896b56da45752c1715e3d7be2823d51462a06
passenger / lib / passenger / dependencies.rb
100644 270 lines (248 sloc) 6.828 kb
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
require 'passenger/platform_info'
module Passenger
 
# Represents a dependency software that Passenger requires. It's used by the
# installer to check whether all dependencies are available. A Dependency object
# contains full information about a dependency, such as its name, code for
# detecting whether it is installed, and installation instructions for the
# current platform.
class Dependency # :nodoc: all
  [:name, :install_command, :install_instructions, :install_comments,
   :website, :website_comments, :provides].each do |attr_name|
    attr_writer attr_name
    
    define_method(attr_name) do
      call_init_block
      return instance_variable_get("@#{attr_name}")
    end
  end
  
  def initialize(&block)
    @included_by = []
    @init_block = block
  end
  
  def define_checker(&block)
    @checker = block
  end
  
  def check
    call_init_block
    result = Result.new
    @checker.call(result)
    return result
  end
 
private
  class Result
    def found(filename_or_boolean = nil)
      if filename_or_boolean.nil?
        @found = true
      else
        @found = filename_or_boolean
      end
    end
    
    def not_found
      found(false)
    end
    
    def found?
      return !@found.nil? && @found
    end
    
    def found_at
      if @found.is_a?(TrueClass) || @found.is_a?(FalseClass)
        return nil
      else
        return @found
      end
    end
  end
 
  def call_init_block
    if @init_block
      init_block = @init_block
      @init_block = nil
      init_block.call(self)
    end
  end
end
 
# Namespace which contains the different dependencies that Passenger may require.
# See Dependency for more information.
module Dependencies # :nodoc: all
  include PlatformInfo
  
  GCC = Dependency.new do |dep|
    dep.name = "GNU C++ compiler"
    dep.define_checker do |result|
      gxx = PlatformInfo.find_command('g++')
      if gxx.nil?
        result.not_found
      else
        result.found(gxx)
      end
    end
    if RUBY_PLATFORM =~ /linux/
      case LINUX_DISTRO
      when :ubuntu, :debian
        dep.install_command = "apt-get install build-essential"
      when :rhel, :fedora, :centos
        dep.install_command = "yum install gcc-c++"
      when :gentoo
        dep.install_command = "emerge -av gcc"
      end
    elsif RUBY_PLATFORM =~ /darwin/
      dep.install_instructions = "Please install the Apple Development Tools: http://developer.apple.com/tools/"
    end
    dep.website = "http://gcc.gnu.org/"
  end
  
  Ruby_DevHeaders = Dependency.new do |dep|
    dep.name = "Ruby development headers"
    dep.define_checker do |result|
      require 'rbconfig'
      begin
        require 'mkmf'
        result.found(File.exist?(Config::CONFIG['archdir'] + "/ruby.h"))
      rescue LoadError
        result.not_found
      end
    end
    if RUBY_PLATFORM =~ /linux/
      case LINUX_DISTRO
      when :ubuntu, :debian
        dep.install_command = "apt-get install ruby1.8-dev"
      when :rhel, :fedora, :centos
        dep.install_command = "yum install ruby-devel"
      when :gentoo
        dep.install_command = "emerge -av ruby"
      end
    elsif RUBY_PLATFORM =~ /freebsd/
      dep.install_command = "make -C /usr/ports/lang/ruby18 install"
    end
    dep.website = "http://www.ruby-lang.org/"
    dep.install_instructions = "Please reinstall Ruby by downloading it from <bold>#{dep.website}</b>"
  end
  
  Ruby_OpenSSL = Dependency.new do |dep|
    dep.name = "OpenSSL support for Ruby"
    dep.define_checker do |result|
      begin
        require 'openssl'
        result.found
      rescue LoadError
        result.not_found
      end
    end
    if RUBY_PLATFORM =~ /linux/
      case LINUX_DISTRO
      when :ubuntu, :debian
        dep.install_command = "apt-get install libopenssl-ruby"
      end
    else
      dep.website = "http://www.ruby-lang.org/"
      dep.install_instructions = "Please (re)install Ruby with OpenSSL " <<
        "support by downloading it from <bold>#{dep.website}</bold>."
    end
  end
  
  RubyGems = Dependency.new do |dep|
    dep.name = "RubyGems"
    dep.define_checker do |result|
      begin
        require 'rubygems'
        result.found
      rescue LoadError
        result.not_found
      end
    end
    dep.website = "http://www.rubygems.org/"
    dep.install_instructions = "Please download it from <b>#{dep.website}</b>. " <<
      "Extract the tarball, and run <b>ruby setup.rb</b>"
  end
  
  Rake = Dependency.new do |dep|
    dep.name = "Rake"
    dep.define_checker do |result|
      rake = PlatformInfo.find_command("rake")
      if rake.nil?
        result.not_found
      else
        result.found(rake)
      end
    end
    dep.website = "http://rake.rubyforge.org/"
    dep.install_instructions = "Please install RubyGems first, then run <b>gem install rake</b>"
  end
  
  Apache2 = Dependency.new do |dep|
    dep.name = "Apache 2"
    dep.define_checker do |result|
      if HTTPD.nil?
        result.not_found
      else
        result.found(HTTPD)
      end
    end
    if RUBY_PLATFORM =~ /linux/
      case LINUX_DISTRO
      when :ubuntu, :debian
        dep.install_command = "apt-get install apache2-mpm-prefork"
      when :rhel, :fedora, :centos
        dep.install_command = "yum install httpd"
      when :gentoo
        dep.install_command = "emerge -av apache"
      end
    elsif RUBY_PLATFORM =~ /freebsd/
      dep.install_command = "make -C /usr/ports/www/apache22 install"
      dep.provides = [Apache2_DevHeaders, APR_Headers]
    end
    dep.website = "http://httpd.apache.org/"
  end
  
  Apache2_DevHeaders = Dependency.new do |dep|
    dep.name = "Apache 2 development headers"
    dep.define_checker do |result|
      if APXS2.nil?
        result.not_found
      else
        result.found(APXS2)
      end
    end
    if RUBY_PLATFORM =~ /linux/
      case LINUX_DISTRO
      when :ubuntu, :debian
        dep.install_command = "apt-get install apache2-prefork-dev"
        dep.provides = [Apache2]
      when :rhel, :fedora, :centos
        dep.install_command = "yum install httpd-devel"
        dep.provides = [Apache2]
      when :gentoo
        dep.install_command = "emerge -av apache"
        dep.provides = [Apache2]
      end
    elsif RUBY_PLATFORM =~ /freebsd/
      dep.install_command = "make -C /usr/ports/www/apache22 install"
    end
    dep.website = "http://httpd.apache.org/"
  end
  
  APR_DevHeaders = Dependency.new do |dep|
    dep.name = "Apache Portable Runtime (APR) development headers"
    dep.define_checker do |result|
      result.found(!APR1_FLAGS.nil?)
    end
    if RUBY_PLATFORM =~ /linux/
      case LINUX_DISTRO
      when :ubuntu, :debian
        dep.install_command = "apt-get install libapr1-dev"
      when :rhel, :fedora, :centos
        dep.install_command = "yum install apr-devel"
      when :gentoo
        dep.install_command = "emerge -av apr"
      end
    end
    dep.website = "http://httpd.apache.org/"
    dep.website_comments = "APR is an integrated part of Apache."
  end
  
  FastThread = Dependency.new do |dep|
    dep.name = "fastthread"
    dep.define_checker do |result|
      begin
        begin
          require 'rubygems'
        rescue LoadError
        end
        require 'fastthread'
        result.found
      rescue LoadError
        result.not_found
      end
    end
    dep.install_instructions = "Please install RubyGems first, then run <b>gem install fastthread</b>"
  end
end
 
end # module Passenger