passenger 3.9.2.beta → 4.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (159) hide show
  1. data/.travis.yml +3 -0
  2. data/NEWS +77 -7
  3. data/README.md +3 -11
  4. data/bin/passenger-install-apache2-module +24 -20
  5. data/bin/passenger-install-nginx-module +25 -23
  6. data/build/agents.rb +11 -0
  7. data/build/apache2.rb +9 -5
  8. data/build/basics.rb +37 -30
  9. data/build/common_library.rb +4 -1
  10. data/build/cplusplus_support.rb +5 -5
  11. data/build/cxx_tests.rb +28 -8
  12. data/build/integration_tests.rb +6 -3
  13. data/build/nginx.rb +3 -3
  14. data/build/packaging.rb +95 -57
  15. data/build/ruby_extension.rb +34 -21
  16. data/build/ruby_tests.rb +4 -2
  17. data/build/test_basics.rb +1 -1
  18. data/dev/run_travis.sh +36 -1
  19. data/doc/Users guide Apache.html +425 -308
  20. data/doc/Users guide Apache.idmap.txt +78 -70
  21. data/doc/Users guide Apache.index.sqlite3 +0 -0
  22. data/doc/Users guide Apache.txt +33 -92
  23. data/doc/Users guide Nginx.html +519 -220
  24. data/doc/Users guide Nginx.idmap.txt +78 -60
  25. data/doc/Users guide Nginx.txt +115 -26
  26. data/doc/Users guide Standalone.html +8 -2
  27. data/doc/users_guide_snippets/analysis_and_system_maintenance.txt +1 -7
  28. data/doc/users_guide_snippets/installation.txt +167 -22
  29. data/doc/users_guide_snippets/rackup_specifications.txt +4 -0
  30. data/doc/users_guide_snippets/since_version.txt +1 -0
  31. data/doc/users_guide_snippets/support_information.txt +3 -7
  32. data/doc/users_guide_snippets/tips.txt +0 -24
  33. data/ext/apache2/Configuration.cpp +11 -33
  34. data/ext/apache2/Configuration.hpp +3 -18
  35. data/ext/apache2/DirectoryMapper.h +20 -70
  36. data/ext/apache2/Hooks.cpp +2 -2
  37. data/ext/common/AgentsStarter.cpp +0 -2
  38. data/ext/common/AgentsStarter.h +0 -1
  39. data/ext/common/AgentsStarter.hpp +1 -3
  40. data/ext/common/ApplicationPool2/AppTypes.cpp +74 -0
  41. data/ext/common/ApplicationPool2/AppTypes.h +202 -0
  42. data/ext/common/ApplicationPool2/Common.h +12 -10
  43. data/ext/common/ApplicationPool2/DirectSpawner.h +256 -0
  44. data/ext/common/ApplicationPool2/DummySpawner.h +90 -0
  45. data/ext/common/ApplicationPool2/Group.h +311 -94
  46. data/ext/common/ApplicationPool2/Implementation.cpp +405 -145
  47. data/ext/common/ApplicationPool2/Options.h +24 -26
  48. data/ext/common/ApplicationPool2/PipeWatcher.h +20 -13
  49. data/ext/common/ApplicationPool2/Pool.h +326 -183
  50. data/ext/common/ApplicationPool2/Process.h +205 -55
  51. data/ext/common/ApplicationPool2/README.md +1 -1
  52. data/ext/common/ApplicationPool2/Session.h +21 -10
  53. data/ext/common/ApplicationPool2/SmartSpawner.h +801 -0
  54. data/ext/common/ApplicationPool2/Spawner.h +141 -1149
  55. data/ext/common/ApplicationPool2/SpawnerFactory.h +132 -0
  56. data/ext/common/ApplicationPool2/SuperGroup.h +146 -223
  57. data/ext/common/Constants.h +4 -2
  58. data/ext/common/Exceptions.h +23 -1
  59. data/ext/common/Logging.cpp +17 -6
  60. data/ext/common/Logging.h +37 -7
  61. data/ext/common/ResourceLocator.h +1 -1
  62. data/ext/common/Utils.cpp +49 -1
  63. data/ext/common/Utils.h +13 -4
  64. data/ext/common/{AnsiColorConstants.h → Utils/AnsiColorConstants.h} +0 -0
  65. data/ext/common/{BCrypt.cpp → Utils/BCrypt.cpp} +0 -0
  66. data/ext/common/{BCrypt.h → Utils/BCrypt.h} +0 -0
  67. data/ext/common/{Blowfish.c → Utils/Blowfish.c} +0 -0
  68. data/ext/common/{Blowfish.h → Utils/Blowfish.h} +0 -0
  69. data/ext/common/Utils/CachedFileStat.hpp +27 -25
  70. data/ext/common/Utils/Curl.h +184 -0
  71. data/ext/common/{HttpConstants.h → Utils/HttpConstants.h} +3 -0
  72. data/ext/common/Utils/IOUtils.cpp +6 -2
  73. data/ext/common/{IniFile.h → Utils/IniFile.h} +0 -0
  74. data/ext/common/Utils/LargeFiles.cpp +30 -0
  75. data/ext/common/Utils/LargeFiles.h +40 -0
  76. data/ext/common/Utils/StrIntUtils.cpp +72 -8
  77. data/ext/common/Utils/StrIntUtils.h +24 -2
  78. data/ext/common/Utils/StringMap.h +12 -2
  79. data/ext/common/Utils/VariantMap.h +51 -2
  80. data/ext/common/Utils/jsoncpp.cpp +1 -1
  81. data/ext/common/agents/Base.cpp +147 -11
  82. data/ext/common/agents/HelperAgent/AgentOptions.h +14 -6
  83. data/ext/common/agents/HelperAgent/Main.cpp +79 -19
  84. data/ext/common/agents/HelperAgent/RequestHandler.h +36 -16
  85. data/ext/common/agents/LoggingAgent/LoggingServer.h +3 -5
  86. data/ext/common/agents/LoggingAgent/Main.cpp +2 -4
  87. data/ext/common/agents/LoggingAgent/RemoteSender.h +18 -24
  88. data/ext/common/agents/SpawnPreparer.cpp +7 -0
  89. data/ext/common/agents/Watchdog/Main.cpp +96 -38
  90. data/ext/nginx/Configuration.c +26 -22
  91. data/ext/nginx/Configuration.h +4 -2
  92. data/ext/nginx/ContentHandler.c +23 -52
  93. data/ext/nginx/ContentHandler.h +5 -11
  94. data/ext/nginx/config +10 -3
  95. data/ext/nginx/ngx_http_passenger_module.c +21 -6
  96. data/ext/nginx/ngx_http_passenger_module.h +4 -1
  97. data/ext/oxt/dynamic_thread_group.hpp +9 -1
  98. data/ext/oxt/system_calls.cpp +2 -2
  99. data/ext/ruby/extconf.rb +2 -1
  100. data/helper-scripts/backtrace-sanitizer.rb +2 -0
  101. data/helper-scripts/wsgi-loader.py +54 -21
  102. data/lib/phusion_passenger.rb +5 -3
  103. data/lib/phusion_passenger/abstract_installer.rb +18 -41
  104. data/lib/phusion_passenger/admin_tools/memory_stats.rb +2 -2
  105. data/lib/phusion_passenger/admin_tools/server_instance.rb +2 -2
  106. data/lib/phusion_passenger/common_library.rb +23 -3
  107. data/lib/phusion_passenger/debug_logging.rb +10 -3
  108. data/lib/phusion_passenger/packaging.rb +1 -0
  109. data/lib/phusion_passenger/platform_info.rb +113 -115
  110. data/lib/phusion_passenger/platform_info/compiler.rb +224 -134
  111. data/lib/phusion_passenger/platform_info/cxx_portability.rb +143 -0
  112. data/lib/phusion_passenger/platform_info/depcheck.rb +371 -0
  113. data/lib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +124 -0
  114. data/lib/phusion_passenger/platform_info/depcheck_specs/compiler_toolchain.rb +97 -0
  115. data/lib/phusion_passenger/platform_info/depcheck_specs/gems.rb +39 -0
  116. data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +118 -0
  117. data/lib/phusion_passenger/platform_info/depcheck_specs/ruby.rb +137 -0
  118. data/lib/phusion_passenger/platform_info/depcheck_specs/utilities.rb +15 -0
  119. data/lib/phusion_passenger/platform_info/operating_system.rb +6 -5
  120. data/lib/phusion_passenger/platform_info/ruby.rb +45 -34
  121. data/lib/phusion_passenger/request_handler.rb +35 -22
  122. data/lib/phusion_passenger/request_handler/thread_handler.rb +5 -6
  123. data/lib/phusion_passenger/ruby_core_enhancements.rb +7 -1
  124. data/lib/phusion_passenger/standalone/runtime_installer.rb +43 -34
  125. data/lib/phusion_passenger/utils/robust_interruption.rb +34 -18
  126. data/passenger.gemspec +25 -0
  127. data/resources/templates/standalone/config.erb +3 -1
  128. data/test/config.json.travis +2 -2
  129. data/test/cxx/ApplicationPool2/DirectSpawnerTest.cpp +37 -5
  130. data/test/cxx/ApplicationPool2/PoolTest.cpp +143 -50
  131. data/test/cxx/ApplicationPool2/ProcessTest.cpp +8 -0
  132. data/test/cxx/ApplicationPool2/SmartSpawnerTest.cpp +28 -17
  133. data/test/cxx/ApplicationPool2/SpawnerTestCases.cpp +31 -26
  134. data/test/cxx/RequestHandlerTest.cpp +17 -1
  135. data/test/cxx/UtilsTest.cpp +84 -10
  136. data/test/integration_tests/apache2_tests.rb +49 -163
  137. data/test/integration_tests/hello_world_wsgi_spec.rb +2 -2
  138. data/test/integration_tests/mycook_spec.rb +1 -1
  139. data/test/integration_tests/nginx_tests.rb +37 -19
  140. data/test/ruby/request_handler_spec.rb +1 -0
  141. data/test/ruby/spec_helper.rb +52 -1
  142. data/test/stub/nginx/nginx.conf.erb +2 -0
  143. data/test/stub/rack/start.rb +5 -0
  144. data/test/stub/rails3.0/Gemfile.lock +30 -30
  145. data/test/stub/rails3.1/Gemfile +1 -1
  146. data/test/stub/rails3.1/Gemfile.lock +3 -3
  147. data/test/stub/rails3.2/Gemfile +1 -1
  148. data/test/stub/rails3.2/Gemfile.lock +4 -4
  149. data/test/stub/rails_apps/2.3/mycook/app/controllers/welcome_controller.rb +1 -1
  150. data/test/stub/rails_apps/2.3/mycook/app/helpers/recipes_helper.rb +2 -0
  151. data/test/stub/rails_apps/2.3/mycook/app/helpers/test_helper.rb +2 -0
  152. data/test/stub/rails_apps/2.3/mycook/app/helpers/uploads_helper.rb +2 -0
  153. data/test/stub/rails_apps/2.3/mycook/app/helpers/welcome_helper.rb +2 -0
  154. data/test/support/nginx_controller.rb +2 -1
  155. metadata +160 -156
  156. data/build/gempackagetask.rb +0 -99
  157. data/build/packagetask.rb +0 -186
  158. data/ext/common/StringListCreator.h +0 -83
  159. data/lib/phusion_passenger/dependencies.rb +0 -657
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # Phusion Passenger - https://www.phusionpassenger.com/
3
- # Copyright (c) 2010, 2011, 2012 Phusion
3
+ # Copyright (c) 2010-2013 Phusion
4
4
  #
5
5
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
6
  #
@@ -28,10 +28,12 @@ module PhusionPassenger
28
28
 
29
29
  ###### Version numbers ######
30
30
 
31
+ PACKAGE_NAME = 'passenger'
32
+
31
33
  # Phusion Passenger version number. Don't forget to edit ext/common/Constants.h too.
32
- VERSION_STRING = '3.9.2.beta'
34
+ VERSION_STRING = '4.0.0.rc4'
33
35
 
34
- PREFERRED_NGINX_VERSION = '1.2.6'
36
+ PREFERRED_NGINX_VERSION = '1.2.7'
35
37
  PREFERRED_PCRE_VERSION = '8.31'
36
38
  STANDALONE_INTERFACE_VERSION = 1
37
39
 
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010 Phusion
2
+ # Copyright (c) 2010-2013 Phusion
3
3
  #
4
4
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
5
5
  #
@@ -106,30 +106,26 @@ protected
106
106
  end
107
107
 
108
108
  def dependencies
109
- return []
109
+ return [[], []]
110
110
  end
111
111
 
112
112
  def check_dependencies(show_new_screen = true)
113
113
  new_screen if show_new_screen
114
- missing_dependencies = []
115
114
  puts "<banner>Checking for required software...</banner>"
116
115
  puts
117
- dependencies.each do |dep|
118
- print " * #{dep.name}... "
119
- result = dep.check
120
- if result.found?
121
- if result.found_at
122
- puts "<green>found at #{result.found_at}</green>"
123
- else
124
- puts "<green>found</green>"
125
- end
126
- else
127
- puts "<red>not found</red>"
128
- missing_dependencies << dep
129
- end
130
- end
131
116
 
132
- if missing_dependencies.empty?
117
+ require 'phusion_passenger/platform_info/depcheck'
118
+ specs, ids = dependencies
119
+ runner = PlatformInfo::Depcheck::ConsoleRunner.new
120
+
121
+ specs.each do |spec|
122
+ PlatformInfo::Depcheck.load(spec)
123
+ end
124
+ ids.each do |id|
125
+ runner.add(id)
126
+ end
127
+
128
+ if runner.check_all
133
129
  return true
134
130
  else
135
131
  puts
@@ -141,13 +137,14 @@ protected
141
137
  else
142
138
  wait(10)
143
139
  end
144
-
140
+
145
141
  line
146
142
  puts
147
143
  puts "<banner>Installation instructions for required software</banner>"
148
144
  puts
149
- missing_dependencies.each do |dep|
150
- print_dependency_installation_instructions(dep)
145
+ runner.missing_dependencies.each do |dep|
146
+ puts " * To install <yellow>#{dep.name}</yellow>:"
147
+ puts " #{dep.install_instructions}"
151
148
  puts
152
149
  end
153
150
  if respond_to?(:users_guide)
@@ -310,26 +307,6 @@ protected
310
307
  return sh("curl", url, "-f", "-L", "-o", output)
311
308
  end
312
309
  end
313
-
314
- private
315
- def print_dependency_installation_instructions(dep)
316
- puts " * To install <yellow>#{dep.name}</yellow>:"
317
- if dep.install_comments
318
- puts " " << dep.install_comments
319
- end
320
- if !dep.install_command.nil?
321
- puts " Please run <b>#{dep.install_command}</b> as root."
322
- elsif !dep.install_instructions.nil?
323
- puts " " << dep.install_instructions
324
- elsif !dep.website.nil?
325
- puts " Please download it from <b>#{dep.website}</b>"
326
- if !dep.website_comments.nil?
327
- puts " (#{dep.website_comments})"
328
- end
329
- else
330
- puts " Search Google."
331
- end
332
- end
333
310
  end
334
311
 
335
312
  end # module PhusionPassenger
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010 Phusion
2
+ # Copyright (c) 2010-2013 Phusion
3
3
  #
4
4
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
5
5
  #
@@ -87,7 +87,7 @@ class MemoryStats
87
87
  # Phusion Passenger is not running.
88
88
  def passenger_processes
89
89
  @passenger_processes ||= list_processes(:match =>
90
- /((^| )Passenger |(^| )Rails:|(^| )Rack:|PassengerHelperAgent|PassengerWatchdog|PassengerLoggingAgent)/)
90
+ /((^| )Passenger |(^| )Rails:|(^| )Rack:|PassengerHelperAgent|PassengerWatchdog|PassengerLoggingAgent|wsgi-loader.py)/)
91
91
  end
92
92
 
93
93
  # Returns the sum of the memory usages of all given processes.
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010 Phusion
2
+ # Copyright (c) 2010-2013 Phusion
3
3
  #
4
4
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
5
5
  #
@@ -276,7 +276,7 @@ class ServerInstance
276
276
  doc = REXML::Document.new(xml)
277
277
 
278
278
  groups = []
279
- doc.elements.each("info/supergroups/group") do |group_xml|
279
+ doc.elements.each("info/supergroups/supergroup/group") do |group_xml|
280
280
  group = Group.new(group_xml.elements["app_root"].text,
281
281
  group_xml.elements["name"].text,
282
282
  group_xml.elements["environment"].text,
@@ -361,6 +361,12 @@ COMMON_LIBRARY = CommonLibraryBuilder.new do
361
361
  Utils/CachedFileStat.h
362
362
  Utils/CachedFileStat.hpp
363
363
  )
364
+ define_component 'Utils/LargeFiles.o',
365
+ :source => 'Utils/LargeFiles.cpp',
366
+ :category => :other,
367
+ :deps => %w(
368
+ Utils/LargeFiles.h
369
+ )
364
370
  define_component 'ApplicationPool2/Implementation.o',
365
371
  :source => 'ApplicationPool2/Implementation.cpp',
366
372
  :category => :other,
@@ -373,6 +379,20 @@ COMMON_LIBRARY = CommonLibraryBuilder.new do
373
379
  ApplicationPool2/Session.h
374
380
  ApplicationPool2/Options.h
375
381
  ApplicationPool2/PipeWatcher.h
382
+ ApplicationPool2/AppTypes.h
383
+ ApplicationPool2/Spawner.h
384
+ ApplicationPool2/SpawnerFactory.h
385
+ ApplicationPool2/SmartSpawner.h
386
+ ApplicationPool2/DirectSpawner.h
387
+ ApplicationPool2/DummySpawner.h
388
+ )
389
+ define_component 'ApplicationPool2/AppTypes.o',
390
+ :source => 'ApplicationPool2/AppTypes.cpp',
391
+ :category => :other,
392
+ :deps => %w(
393
+ ApplicationPool2/AppTypes.h
394
+ Utils/StrIntUtils.h
395
+ Utils/CachedFileStat.h
376
396
  )
377
397
  define_component 'AccountsDatabase.o',
378
398
  :source => 'AccountsDatabase.cpp',
@@ -389,10 +409,10 @@ COMMON_LIBRARY = CommonLibraryBuilder.new do
389
409
  :deps => %w(
390
410
  AgentsStarter.h
391
411
  AgentsStarter.hpp
392
- IniFile.h
393
412
  ResourceLocator.h
394
413
  MessageClient.h
395
414
  ServerInstanceDir.h
415
+ Utils/IniFile.h
396
416
  Utils/VariantMap.h
397
417
  )
398
418
  define_component 'AgentsBase.o',
@@ -437,5 +457,5 @@ COMMON_LIBRARY = CommonLibraryBuilder.new do
437
457
  end
438
458
 
439
459
  # Objects that must be linked into the Nginx binary.
440
- NGINX_LIBS_SELECTOR = [:base, 'AgentsStarter.o', 'Utils/CachedFileStat.o',
441
- 'Utils/Base64.o', 'agents/LoggingAgent/FilterSupport.o']
460
+ NGINX_LIBS_SELECTOR = [:base, 'AgentsStarter.o', 'ApplicationPool2/AppTypes.o',
461
+ 'Utils/CachedFileStat.o', 'Utils/Base64.o', 'agents/LoggingAgent/FilterSupport.o']
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010 Phusion
2
+ # Copyright (c) 2010-2013 Phusion
3
3
  #
4
4
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
5
5
  #
@@ -98,10 +98,17 @@ module DebugLogging
98
98
  now = Time.now
99
99
  time_str = now.strftime("%Y-%m-%d %H:%M:%S.")
100
100
  time_str << sprintf("%04d", now.usec / 100)
101
- if thread_name = Thread.current[:name]
101
+
102
+ current_thread = Thread.current
103
+ if !(thread_id = current_thread[:id])
104
+ current_thread.to_s =~ /:(0x[0-9a-f]+)/i
105
+ thread_id = current_thread[:id] = $1 || '?'
106
+ end
107
+ if thread_name = current_thread[:name]
102
108
  thread_name = "(#{thread_name})"
103
109
  end
104
- output.write("[ pid=#{$$} thr=0x#{Thread.current.object_id.to_s(16)}#{thread_name} file=#{location} time=#{time_str} ]: #{message}\n")
110
+
111
+ output.write("[ #{time_str} #{$$}/#{thread_id}#{thread_name} #{location} ]: #{message}\n")
105
112
  output.flush
106
113
  end
107
114
  end
@@ -56,6 +56,7 @@ module Packaging
56
56
  'LICENSE',
57
57
  'INSTALL.md',
58
58
  'NEWS',
59
+ 'passenger.gemspec',
59
60
  'build/*.rb',
60
61
  'lib/*.rb',
61
62
  'lib/**/*.rb',
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010 Phusion
2
+ # Copyright (c) 2010-2013 Phusion
3
3
  #
4
4
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
5
5
  #
@@ -28,9 +28,11 @@ module PhusionPassenger
28
28
  module PlatformInfo
29
29
  private
30
30
  @@cache_dir = nil
31
-
32
- def self.cache_dir=(value)
33
- @@cache_dir = value
31
+ @@verbose = ['1', 'true', 'on', 'yes'].include?(ENV['VERBOSE'])
32
+ @@log_implementation = lambda do |message|
33
+ message = reindent(message, 3)
34
+ message.sub!(/^ /, '')
35
+ STDERR.puts " * #{message}"
34
36
  end
35
37
 
36
38
  def self.private_class_method(name)
@@ -128,37 +130,98 @@ private
128
130
  return nil
129
131
  end
130
132
  private_class_method :select_executable
131
-
132
- def self.read_file(filename)
133
- return File.read(filename)
134
- rescue
135
- return ""
133
+
134
+ def self.unindent(str)
135
+ str = str.dup
136
+ str.gsub!(/\A([\s\t]*\n)+/, '')
137
+ str.gsub!(/[\s\t\n]+\Z/, '')
138
+ indent = str.split("\n").select{ |line| !line.strip.empty? }.map{ |line| line.index(/[^\s]/) }.compact.min || 0
139
+ str.gsub!(/^[[:blank:]]{#{indent}}/, '')
140
+ return str
141
+ end
142
+ private_class_method :unindent
143
+
144
+ def self.reindent(str, level)
145
+ str = unindent(str)
146
+ str.gsub!(/^/, ' ' * level)
147
+ return str
136
148
  end
137
- private_class_method :read_file
149
+ private_class_method :reindent
150
+
151
+ def self.create_temp_file(name, dir = tmpdir)
152
+ tag = "#{Process.pid}.#{Thread.current.object_id.to_s(16)}"
153
+ if name =~ /\./
154
+ ext = File.extname(name)
155
+ name = File.basename(name, ext) + "-#{tag}#{ext}"
156
+ else
157
+ name = "#{name}-#{tag}"
158
+ end
159
+ filename = "#{dir}/#{name}"
160
+ f = File.open(filename, "w")
161
+ begin
162
+ yield(filename, f)
163
+ ensure
164
+ f.close if !f.closed?
165
+ File.unlink(filename) if File.exist?(filename)
166
+ end
167
+ end
168
+ private_class_method :create_temp_file
169
+
170
+ def self.log(message)
171
+ if verbose?
172
+ @@log_implementation.call(message)
173
+ end
174
+ end
175
+ private_class_method :log
138
176
 
139
177
  public
140
178
  class RuntimeError < ::RuntimeError
141
179
  end
142
-
143
- # Check whether the specified command is in $PATH, and return its
144
- # absolute filename. Returns nil if the command is not found.
145
- #
146
- # This function exists because system('which') doesn't always behave
147
- # correctly, for some weird reason.
148
- def self.find_command(name)
149
- name = name.to_s
150
- ENV['PATH'].to_s.split(File::PATH_SEPARATOR).detect do |directory|
151
- path = File.join(directory, name)
152
- if File.file?(path) && File.executable?(path)
153
- return path
154
- end
155
- end
156
- return nil
180
+
181
+
182
+ def self.cache_dir=(value)
183
+ @@cache_dir = value
157
184
  end
158
-
185
+
186
+ def self.cache_dir
187
+ return @@cache_dir
188
+ end
189
+
190
+ def self.verbose=(val)
191
+ @@verbose = val
192
+ end
193
+
194
+ def self.verbose?
195
+ return @@verbose
196
+ end
197
+
198
+ def self.log_implementation=(impl)
199
+ @@log_implementation = impl
200
+ end
201
+
202
+ def self.log_implementation
203
+ return @@log_implementation
204
+ end
205
+
206
+
159
207
  def self.env_defined?(name)
160
208
  return !ENV[name].nil? && !ENV[name].empty?
161
209
  end
210
+
211
+ def self.string_env(name, default_value = nil)
212
+ value = ENV[name]
213
+ if value.nil? || value.empty?
214
+ return default_value
215
+ else
216
+ return value
217
+ end
218
+ end
219
+
220
+ def self.read_file(filename)
221
+ return File.read(filename)
222
+ rescue
223
+ return ""
224
+ end
162
225
 
163
226
  def self.tmpdir
164
227
  result = ENV['TMPDIR']
@@ -246,94 +309,6 @@ public
246
309
  raise RuntimeError, message
247
310
  end
248
311
  memoize :tmpexedir
249
-
250
- def self.cc
251
- return ENV['CC'] || "gcc"
252
- end
253
-
254
- def self.cxx
255
- return ENV['CXX'] || "g++"
256
- end
257
-
258
- def self.try_compile(language, source, flags = nil)
259
- if language == :c
260
- compiler = cc
261
- elsif language == :cxx
262
- compiler = cxx
263
- else
264
- raise ArgumentError,"Unsupported language '#{language}'"
265
- end
266
- filename = File.join("#{tmpexedir}/passenger-compile-check-#{Process.pid}.c")
267
- File.open(filename, "w") do |f|
268
- f.puts(source)
269
- end
270
- begin
271
- return system("(#{compiler} #{flags} -c '#{filename}' -o '#{filename}.o') >/dev/null 2>/dev/null")
272
- ensure
273
- File.unlink(filename) rescue nil
274
- File.unlink("#{filename}.o") rescue nil
275
- end
276
- end
277
- private_class_method :try_compile
278
-
279
- def self.try_link(language, source, flags = nil)
280
- if language == :c
281
- compiler = cc
282
- elsif language == :cxx
283
- compiler = cxx
284
- else
285
- raise ArgumentError,"Unsupported language '#{language}'"
286
- end
287
- filename = File.join("#{tmpexedir}/passenger-link-check-#{Process.pid}.c")
288
- File.open(filename, "w") do |f|
289
- f.puts(source)
290
- end
291
- begin
292
- return system("(#{compiler} #{flags} '#{filename}' -o '#{filename}.out') >/dev/null 2>/dev/null")
293
- ensure
294
- File.unlink(filename) rescue nil
295
- File.unlink("#{filename}.out") rescue nil
296
- end
297
- end
298
- private_class_method :try_link
299
-
300
- def self.try_compile_and_run(language, source, flags = nil)
301
- if language == :c
302
- compiler = cc
303
- elsif language == :cxx
304
- compiler = cxx
305
- else
306
- raise ArgumentError,"Unsupported language '#{language}'"
307
- end
308
- filename = File.join("#{tmpexedir}/passenger-compile-check-#{Process.pid}.c")
309
- File.open(filename, "w") do |f|
310
- f.puts(source)
311
- end
312
- begin
313
- if system("(#{compiler} #{flags} '#{filename}' -o '#{filename}.out') >/dev/null 2>/dev/null")
314
- if Process.respond_to?(:spawn)
315
- pid = Process.spawn("#{filename}.out",
316
- :out => ["/dev/null", "w"],
317
- :err => ["/dev/null", "w"])
318
-
319
- else
320
- pid = fork do
321
- STDOUT.reopen("/dev/null", "w")
322
- STDERR.reopen("/dev/null", "w")
323
- exec("#{filename}.out")
324
- end
325
- end
326
- pid = Process.waitpid(pid) rescue nil
327
- return pid && $?.exitstatus == 0
328
- else
329
- return false
330
- end
331
- ensure
332
- File.unlink(filename) rescue nil
333
- File.unlink("#{filename}.out") rescue nil
334
- end
335
- end
336
- private_class_method :try_compile_and_run
337
312
 
338
313
  def self.rb_config
339
314
  if defined?(::RbConfig)
@@ -342,7 +317,30 @@ public
342
317
  return ::Config::CONFIG
343
318
  end
344
319
  end
345
- private_class_method :rb_config
320
+
321
+ # Check whether the specified command is in $PATH, and return its
322
+ # absolute filename. Returns nil if the command is not found.
323
+ #
324
+ # This function exists because system('which') doesn't always behave
325
+ # correctly, for some weird reason.
326
+ def self.find_command(name)
327
+ name = name.to_s
328
+ if name =~ /^\//
329
+ if File.executable?(name)
330
+ return name
331
+ else
332
+ return nil
333
+ end
334
+ else
335
+ ENV['PATH'].to_s.split(File::PATH_SEPARATOR).detect do |directory|
336
+ path = File.join(directory, name)
337
+ if File.file?(path) && File.executable?(path)
338
+ return path
339
+ end
340
+ end
341
+ return nil
342
+ end
343
+ end
346
344
  end
347
345
 
348
346
  end # module PhusionPassenger