passenger 5.0.0.beta3 → 5.0.0.rc1

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 (218) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/.editorconfig +11 -5
  5. data/CHANGELOG +38 -0
  6. data/CONTRIBUTING.md +1 -4
  7. data/Gemfile +0 -1
  8. data/Gemfile.lock +0 -2
  9. data/Rakefile +33 -33
  10. data/bin/passenger +1 -1
  11. data/bin/passenger-config +1 -1
  12. data/bin/passenger-install-apache2-module +800 -800
  13. data/bin/passenger-install-nginx-module +592 -592
  14. data/bin/passenger-memory-stats +127 -127
  15. data/bin/passenger-status +216 -216
  16. data/build/agents.rb +127 -127
  17. data/build/apache2.rb +87 -87
  18. data/build/basics.rb +60 -60
  19. data/build/common_library.rb +165 -165
  20. data/build/cplusplus_support.rb +51 -51
  21. data/build/cxx_tests.rb +268 -268
  22. data/build/debian.rb +143 -143
  23. data/build/documentation.rb +58 -58
  24. data/build/integration_tests.rb +81 -81
  25. data/build/misc.rb +132 -132
  26. data/build/nginx.rb +20 -20
  27. data/build/node_tests.rb +7 -7
  28. data/build/oxt_tests.rb +14 -14
  29. data/build/packaging.rb +570 -570
  30. data/build/preprocessor.rb +260 -260
  31. data/build/rake_extensions.rb +71 -71
  32. data/build/ruby_extension.rb +29 -29
  33. data/build/ruby_tests.rb +6 -6
  34. data/build/test_basics.rb +37 -37
  35. data/debian.template/control.template +3 -5
  36. data/dev/copy_boost_headers +134 -134
  37. data/dev/install_scripts_bootstrap_code.rb +25 -25
  38. data/dev/list_tests +20 -20
  39. data/dev/ruby_server.rb +223 -223
  40. data/dev/runner +18 -18
  41. data/doc/ServerOptimizationGuide.txt.md +55 -2
  42. data/doc/Users guide Nginx.txt +0 -26
  43. data/doc/Users guide Standalone.txt +5 -1
  44. data/doc/users_guide_snippets/tips.txt +9 -0
  45. data/ext/common/ApplicationPool2/Group.h +23 -11
  46. data/ext/common/ApplicationPool2/Implementation.cpp +32 -7
  47. data/ext/common/ApplicationPool2/Pool.h +22 -17
  48. data/ext/common/ApplicationPool2/SmartSpawner.h +4 -1
  49. data/ext/common/ApplicationPool2/Spawner.h +1 -1
  50. data/ext/common/Constants.h +1 -1
  51. data/ext/common/agents/Base.cpp +35 -20
  52. data/ext/common/agents/HelperAgent/Main.cpp +8 -1
  53. data/ext/common/agents/HelperAgent/OptionParser.h +18 -4
  54. data/ext/common/agents/HelperAgent/RequestHandler.h +2 -83
  55. data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +54 -1
  56. data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +7 -4
  57. data/ext/common/agents/Main.cpp +1 -1
  58. data/ext/common/agents/Watchdog/Main.cpp +54 -19
  59. data/ext/nginx/Configuration.c +7 -0
  60. data/ext/nginx/ContentHandler.c +9 -1
  61. data/helper-scripts/backtrace-sanitizer.rb +106 -87
  62. data/helper-scripts/crash-watch.rb +32 -0
  63. data/helper-scripts/download_binaries/extconf.rb +38 -38
  64. data/helper-scripts/meteor-loader.rb +107 -107
  65. data/helper-scripts/prespawn +101 -101
  66. data/helper-scripts/rack-loader.rb +96 -96
  67. data/helper-scripts/rack-preloader.rb +137 -137
  68. data/lib/phusion_passenger.rb +292 -292
  69. data/lib/phusion_passenger/abstract_installer.rb +438 -438
  70. data/lib/phusion_passenger/active_support3_extensions/init.rb +168 -170
  71. data/lib/phusion_passenger/admin_tools.rb +20 -20
  72. data/lib/phusion_passenger/admin_tools/instance.rb +178 -178
  73. data/lib/phusion_passenger/admin_tools/instance_registry.rb +61 -61
  74. data/lib/phusion_passenger/admin_tools/memory_stats.rb +267 -267
  75. data/lib/phusion_passenger/apache2/config_options.rb +182 -182
  76. data/lib/phusion_passenger/common_library.rb +479 -485
  77. data/lib/phusion_passenger/config/about_command.rb +161 -161
  78. data/lib/phusion_passenger/config/admin_command_command.rb +129 -129
  79. data/lib/phusion_passenger/config/agent_compiler.rb +121 -121
  80. data/lib/phusion_passenger/config/build_native_support_command.rb +43 -43
  81. data/lib/phusion_passenger/config/command.rb +25 -25
  82. data/lib/phusion_passenger/config/compile_agent_command.rb +62 -62
  83. data/lib/phusion_passenger/config/compile_nginx_engine_command.rb +88 -73
  84. data/lib/phusion_passenger/config/detach_process_command.rb +72 -72
  85. data/lib/phusion_passenger/config/download_agent_command.rb +246 -227
  86. data/lib/phusion_passenger/config/download_nginx_engine_command.rb +245 -224
  87. data/lib/phusion_passenger/config/install_agent_command.rb +144 -132
  88. data/lib/phusion_passenger/config/install_standalone_runtime_command.rb +205 -185
  89. data/lib/phusion_passenger/config/installation_utils.rb +204 -204
  90. data/lib/phusion_passenger/config/list_instances_command.rb +64 -64
  91. data/lib/phusion_passenger/config/main.rb +152 -152
  92. data/lib/phusion_passenger/config/nginx_engine_compiler.rb +319 -300
  93. data/lib/phusion_passenger/config/reopen_logs_command.rb +67 -67
  94. data/lib/phusion_passenger/config/restart_app_command.rb +155 -155
  95. data/lib/phusion_passenger/config/system_metrics_command.rb +13 -13
  96. data/lib/phusion_passenger/config/utils.rb +95 -95
  97. data/lib/phusion_passenger/config/validate_install_command.rb +198 -198
  98. data/lib/phusion_passenger/console_text_template.rb +25 -25
  99. data/lib/phusion_passenger/constants.rb +90 -90
  100. data/lib/phusion_passenger/debug_logging.rb +106 -106
  101. data/lib/phusion_passenger/loader_shared_helpers.rb +447 -432
  102. data/lib/phusion_passenger/message_channel.rb +312 -312
  103. data/lib/phusion_passenger/message_client.rb +176 -176
  104. data/lib/phusion_passenger/native_support.rb +369 -369
  105. data/lib/phusion_passenger/nginx/config_options.rb +297 -297
  106. data/lib/phusion_passenger/packaging.rb +131 -131
  107. data/lib/phusion_passenger/platform_info.rb +360 -360
  108. data/lib/phusion_passenger/platform_info/apache.rb +767 -767
  109. data/lib/phusion_passenger/platform_info/apache_detector.rb +199 -199
  110. data/lib/phusion_passenger/platform_info/binary_compatibility.rb +107 -107
  111. data/lib/phusion_passenger/platform_info/compiler.rb +570 -570
  112. data/lib/phusion_passenger/platform_info/curl.rb +32 -32
  113. data/lib/phusion_passenger/platform_info/cxx_portability.rb +188 -188
  114. data/lib/phusion_passenger/platform_info/depcheck.rb +372 -372
  115. data/lib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +109 -109
  116. data/lib/phusion_passenger/platform_info/depcheck_specs/compiler_toolchain.rb +4 -4
  117. data/lib/phusion_passenger/platform_info/depcheck_specs/gems.rb +10 -34
  118. data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +101 -101
  119. data/lib/phusion_passenger/platform_info/depcheck_specs/ruby.rb +5 -5
  120. data/lib/phusion_passenger/platform_info/depcheck_specs/utilities.rb +13 -13
  121. data/lib/phusion_passenger/platform_info/linux.rb +55 -55
  122. data/lib/phusion_passenger/platform_info/operating_system.rb +149 -149
  123. data/lib/phusion_passenger/platform_info/ruby.rb +468 -448
  124. data/lib/phusion_passenger/platform_info/zlib.rb +9 -9
  125. data/lib/phusion_passenger/plugin.rb +66 -66
  126. data/lib/phusion_passenger/preloader_shared_helpers.rb +126 -126
  127. data/lib/phusion_passenger/public_api.rb +191 -191
  128. data/lib/phusion_passenger/rack/out_of_band_gc.rb +93 -94
  129. data/lib/phusion_passenger/rack/thread_handler_extension.rb +231 -227
  130. data/lib/phusion_passenger/request_handler.rb +567 -577
  131. data/lib/phusion_passenger/request_handler/thread_handler.rb +379 -381
  132. data/lib/phusion_passenger/ruby_core_enhancements.rb +86 -86
  133. data/lib/phusion_passenger/ruby_core_io_enhancements.rb +74 -74
  134. data/lib/phusion_passenger/simple_benchmarking.rb +25 -25
  135. data/lib/phusion_passenger/standalone/app_finder.rb +153 -150
  136. data/lib/phusion_passenger/standalone/command.rb +44 -40
  137. data/lib/phusion_passenger/standalone/config_utils.rb +53 -53
  138. data/lib/phusion_passenger/standalone/control_utils.rb +38 -59
  139. data/lib/phusion_passenger/standalone/main.rb +73 -73
  140. data/lib/phusion_passenger/standalone/start_command.rb +697 -685
  141. data/lib/phusion_passenger/standalone/start_command/builtin_engine.rb +193 -155
  142. data/lib/phusion_passenger/standalone/start_command/nginx_engine.rb +162 -133
  143. data/lib/phusion_passenger/standalone/status_command.rb +64 -64
  144. data/lib/phusion_passenger/standalone/stop_command.rb +72 -72
  145. data/lib/phusion_passenger/standalone/version_command.rb +9 -9
  146. data/lib/phusion_passenger/union_station/connection.rb +32 -32
  147. data/lib/phusion_passenger/union_station/core.rb +251 -251
  148. data/lib/phusion_passenger/union_station/transaction.rb +126 -126
  149. data/lib/phusion_passenger/utils.rb +199 -167
  150. data/lib/phusion_passenger/utils/ansi_colors.rb +128 -128
  151. data/lib/phusion_passenger/utils/download.rb +196 -196
  152. data/lib/phusion_passenger/utils/file_system_watcher.rb +158 -158
  153. data/lib/phusion_passenger/utils/hosts_file_parser.rb +101 -101
  154. data/lib/phusion_passenger/utils/lock.rb +31 -31
  155. data/lib/phusion_passenger/utils/native_support_utils.rb +31 -31
  156. data/lib/phusion_passenger/utils/progress_bar.rb +26 -26
  157. data/lib/phusion_passenger/utils/shellwords.rb +20 -20
  158. data/lib/phusion_passenger/utils/terminal_choice_menu.rb +206 -206
  159. data/lib/phusion_passenger/utils/unseekable_socket.rb +272 -272
  160. data/lib/phusion_passenger/vendor/crash_watch/app.rb +129 -0
  161. data/lib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +341 -0
  162. data/lib/phusion_passenger/vendor/crash_watch/version.rb +24 -0
  163. data/lib/phusion_passenger/vendor/daemon_controller.rb +877 -0
  164. data/lib/phusion_passenger/vendor/daemon_controller/lock_file.rb +127 -0
  165. data/lib/phusion_passenger/vendor/daemon_controller/spawn.rb +26 -0
  166. data/lib/phusion_passenger/vendor/daemon_controller/version.rb +29 -0
  167. data/packaging/rpm/passenger_spec/passenger.spec.template +0 -1
  168. data/passenger.gemspec +0 -1
  169. data/resources/templates/config/nginx_engine_compiler/possible_solutions_for_download_and_extraction_problems.txt.erb +27 -0
  170. data/resources/templates/standalone/config.erb +19 -15
  171. data/test/integration_tests/apache2_tests.rb +566 -566
  172. data/test/integration_tests/downloaded_binaries_tests.rb +126 -125
  173. data/test/integration_tests/native_packaging_spec.rb +296 -296
  174. data/test/integration_tests/nginx_tests.rb +393 -393
  175. data/test/integration_tests/shared/example_webapp_tests.rb +282 -280
  176. data/test/integration_tests/source_packaging_test.rb +138 -138
  177. data/test/integration_tests/spec_helper.rb +5 -5
  178. data/test/integration_tests/standalone_tests.rb +367 -367
  179. data/test/ruby/debug_logging_spec.rb +133 -133
  180. data/test/ruby/message_channel_spec.rb +186 -186
  181. data/test/ruby/rack/loader_spec.rb +28 -28
  182. data/test/ruby/rack/preloader_spec.rb +34 -34
  183. data/test/ruby/rails3.0/loader_spec.rb +12 -12
  184. data/test/ruby/rails3.0/preloader_spec.rb +18 -18
  185. data/test/ruby/rails3.1/loader_spec.rb +12 -12
  186. data/test/ruby/rails3.1/preloader_spec.rb +18 -18
  187. data/test/ruby/rails3.2/loader_spec.rb +12 -12
  188. data/test/ruby/rails3.2/preloader_spec.rb +18 -18
  189. data/test/ruby/rails4.0/loader_spec.rb +12 -12
  190. data/test/ruby/rails4.0/preloader_spec.rb +18 -18
  191. data/test/ruby/rails4.1/loader_spec.rb +12 -12
  192. data/test/ruby/rails4.1/preloader_spec.rb +18 -18
  193. data/test/ruby/request_handler_spec.rb +730 -730
  194. data/test/ruby/shared/loader_sharedspec.rb +224 -224
  195. data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +327 -327
  196. data/test/ruby/shared/ruby_loader_sharedspec.rb +47 -47
  197. data/test/ruby/spec_helper.rb +65 -65
  198. data/test/ruby/standalone/runtime_installer_spec.rb +384 -384
  199. data/test/ruby/union_station_spec.rb +276 -276
  200. data/test/ruby/utils/file_system_watcher_spec.rb +220 -220
  201. data/test/ruby/utils/hosts_file_parser.rb +248 -248
  202. data/test/ruby/utils/tee_input_spec.rb +215 -215
  203. data/test/ruby/utils/unseekable_socket_spec.rb +57 -57
  204. data/test/ruby/utils_spec.rb +21 -21
  205. data/test/stub/rack/config.ru +87 -87
  206. data/test/stub/rack/library.rb +8 -8
  207. data/test/stub/rack/start.rb +30 -30
  208. data/test/support/apache2_controller.rb +191 -191
  209. data/test/support/nginx_controller.rb +90 -99
  210. data/test/support/placebo-preloader.rb +57 -57
  211. data/test/support/test_helper.rb +435 -435
  212. metadata +11 -21
  213. metadata.gz.asc +7 -7
  214. data/lib/phusion_passenger/standalone/command2.rb +0 -292
  215. data/lib/phusion_passenger/standalone/start2_command.rb +0 -799
  216. data/resources/templates/standalone/download_tool_missing.txt.erb +0 -18
  217. data/resources/templates/standalone/possible_solutions_for_download_and_extraction_problems.txt.erb +0 -17
  218. data/resources/templates/standalone/run_installer_as_root.txt.erb +0 -8
data/build/nginx.rb CHANGED
@@ -22,45 +22,45 @@
22
22
  # THE SOFTWARE.
23
23
 
24
24
  auto_generated_sources = [
25
- 'ext/nginx/ConfigurationCommands.c',
26
- 'ext/nginx/CreateLocationConfig.c',
27
- 'ext/nginx/MergeLocationConfig.c',
28
- 'ext/nginx/CacheLocationConfig.c',
29
- 'ext/nginx/ConfigurationFields.h'
25
+ 'ext/nginx/ConfigurationCommands.c',
26
+ 'ext/nginx/CreateLocationConfig.c',
27
+ 'ext/nginx/MergeLocationConfig.c',
28
+ 'ext/nginx/CacheLocationConfig.c',
29
+ 'ext/nginx/ConfigurationFields.h'
30
30
  ]
31
31
 
32
32
  desc "Build Nginx support files"
33
33
  task :nginx => [
34
- :nginx_without_native_support,
35
- NATIVE_SUPPORT_TARGET
34
+ :nginx_without_native_support,
35
+ NATIVE_SUPPORT_TARGET
36
36
  ].compact
37
37
 
38
38
  # Workaround for https://github.com/jimweirich/rake/issues/274
39
39
  task :_nginx => :nginx
40
40
 
41
41
  task :nginx_without_native_support => [
42
- auto_generated_sources,
43
- AGENT_OUTPUT_DIR + AGENT_EXE,
44
- COMMON_LIBRARY.only(*NGINX_LIBS_SELECTOR).link_objects
42
+ auto_generated_sources,
43
+ AGENT_OUTPUT_DIR + AGENT_EXE,
44
+ COMMON_LIBRARY.only(*NGINX_LIBS_SELECTOR).link_objects
45
45
  ].flatten
46
46
 
47
47
  task :clean => 'nginx:clean'
48
48
  desc "Clean all compiled Nginx files"
49
49
  task 'nginx:clean' => 'common:clean' do
50
- # Nothing to clean at this time.
50
+ # Nothing to clean at this time.
51
51
  end
52
52
 
53
53
  def create_nginx_auto_generated_source_task(source)
54
- dependencies = [
55
- "#{source}.erb",
56
- 'lib/phusion_passenger/nginx/config_options.rb'
57
- ]
58
- file(source => dependencies) do
59
- template = TemplateRenderer.new("#{source}.erb")
60
- template.render_to(source)
61
- end
54
+ dependencies = [
55
+ "#{source}.erb",
56
+ 'lib/phusion_passenger/nginx/config_options.rb'
57
+ ]
58
+ file(source => dependencies) do
59
+ template = TemplateRenderer.new("#{source}.erb")
60
+ template.render_to(source)
61
+ end
62
62
  end
63
63
 
64
64
  auto_generated_sources.each do |source|
65
- create_nginx_auto_generated_source_task(source)
65
+ create_nginx_auto_generated_source_task(source)
66
66
  end
data/build/node_tests.rb CHANGED
@@ -25,11 +25,11 @@
25
25
 
26
26
  desc "Run unit tests for the Node.js libraries"
27
27
  task 'test:node' do
28
- require 'shellwords'
29
- command = "cd test && env NODE_PATH=#{PhusionPassenger.node_libdir} " +
30
- "../node_modules/.bin/mocha -R spec node/*_spec.js"
31
- if grep = string_option('G')
32
- command << " -g #{Shellwords.escape(grep)}"
33
- end
34
- sh(command)
28
+ require 'shellwords'
29
+ command = "cd test && env NODE_PATH=#{PhusionPassenger.node_libdir} " +
30
+ "../node_modules/.bin/mocha -R spec node/*_spec.js"
31
+ if grep = string_option('G')
32
+ command << " -g #{Shellwords.escape(grep)}"
33
+ end
34
+ sh(command)
35
35
  end
data/build/oxt_tests.rb CHANGED
@@ -27,33 +27,33 @@ TEST_OXT_CFLAGS = "#{EXTRA_PRE_CXXFLAGS} -Iext -Itest/support #{TEST_COMMON_CFLA
27
27
  TEST_OXT_LDFLAGS = "#{TEST_BOOST_OXT_LIBRARY} #{PlatformInfo.portability_cxx_ldflags} #{EXTRA_CXX_LDFLAGS}"
28
28
  TEST_OXT_LDFLAGS << " #{PlatformInfo.adress_sanitizer_flag}" if USE_ASAN
29
29
  TEST_OXT_OBJECTS = {
30
- 'oxt_test_main.o' => %w(oxt_test_main.cpp),
31
- 'backtrace_test.o' => %w(backtrace_test.cpp counter.hpp),
32
- 'spin_lock_test.o' => %w(spin_lock_test.cpp),
33
- 'dynamic_thread_group_test.o' => %w(dynamic_thread_group_test.cpp counter.hpp),
34
- 'syscall_interruption_test.o' => %w(syscall_interruption_test.cpp)
30
+ 'oxt_test_main.o' => %w(oxt_test_main.cpp),
31
+ 'backtrace_test.o' => %w(backtrace_test.cpp counter.hpp),
32
+ 'spin_lock_test.o' => %w(spin_lock_test.cpp),
33
+ 'dynamic_thread_group_test.o' => %w(dynamic_thread_group_test.cpp counter.hpp),
34
+ 'syscall_interruption_test.o' => %w(syscall_interruption_test.cpp)
35
35
  }
36
36
 
37
37
  desc "Run unit tests for the OXT library"
38
38
  task 'test:oxt' => 'test/oxt/oxt_test_main' do
39
- sh "cd test && ./oxt/oxt_test_main"
39
+ sh "cd test && ./oxt/oxt_test_main"
40
40
  end
41
41
 
42
42
  # Define task for test/oxt/oxt_test_main.
43
43
  oxt_test_main_dependencies = TEST_OXT_OBJECTS.keys.map do |object|
44
- "test/oxt/#{object}"
44
+ "test/oxt/#{object}"
45
45
  end
46
46
  oxt_test_main_dependencies << TEST_BOOST_OXT_LIBRARY
47
47
  file 'test/oxt/oxt_test_main' => oxt_test_main_dependencies do
48
- objects = TEST_OXT_OBJECTS.keys.map{ |x| "test/oxt/#{x}" }.join(' ')
49
- create_executable("test/oxt/oxt_test_main", objects, TEST_OXT_LDFLAGS)
48
+ objects = TEST_OXT_OBJECTS.keys.map{ |x| "test/oxt/#{x}" }.join(' ')
49
+ create_executable("test/oxt/oxt_test_main", objects, TEST_OXT_LDFLAGS)
50
50
  end
51
51
 
52
52
  # Define tasks for each OXT test source file.
53
53
  TEST_OXT_OBJECTS.each_pair do |target, sources|
54
- file "test/oxt/#{target}" => sources.map{ |x| "test/oxt/#{x}" } do
55
- source = "test/oxt/#{sources[0]}"
56
- object = source.sub(/\.cpp$/, '.o')
57
- compile_cxx source, "#{TEST_OXT_CFLAGS} -o #{object}"
58
- end
54
+ file "test/oxt/#{target}" => sources.map{ |x| "test/oxt/#{x}" } do
55
+ source = "test/oxt/#{sources[0]}"
56
+ object = source.sub(/\.cpp$/, '.o')
57
+ compile_cxx source, "#{TEST_OXT_CFLAGS} -o #{object}"
58
+ end
59
59
  end
data/build/packaging.rb CHANGED
@@ -24,637 +24,637 @@
24
24
  ORIG_TARBALL_FILES = lambda { PhusionPassenger::Packaging.files }
25
25
 
26
26
  def recursive_copy_files(files, destination_dir, preprocess = false, variables = {})
27
- require 'fileutils' if !defined?(FileUtils)
28
- if !STDOUT.tty?
29
- puts "Copying files..."
30
- end
31
- files.each_with_index do |filename, i|
32
- dir = File.dirname(filename)
33
- if !File.exist?("#{destination_dir}/#{dir}")
34
- FileUtils.mkdir_p("#{destination_dir}/#{dir}")
35
- end
36
- if !File.directory?(filename)
37
- if preprocess && filename =~ /\.template$/
38
- real_filename = filename.sub(/\.template$/, '')
39
- FileUtils.install(filename, "#{destination_dir}/#{real_filename}", :preserve => true)
40
- Preprocessor.new.start(filename, "#{destination_dir}/#{real_filename}",
41
- variables)
42
- else
43
- FileUtils.install(filename, "#{destination_dir}/#{filename}", :preserve => true)
44
- end
45
- end
46
- if STDOUT.tty?
47
- printf "\r[%5d/%5d] [%3.0f%%] Copying files...", i + 1, files.size, i * 100.0 / files.size
48
- STDOUT.flush
49
- end
50
- end
51
- if STDOUT.tty?
52
- printf "\r[%5d/%5d] [%3.0f%%] Copying files...\n", files.size, files.size, 100
53
- end
27
+ require 'fileutils' if !defined?(FileUtils)
28
+ if !STDOUT.tty?
29
+ puts "Copying files..."
30
+ end
31
+ files.each_with_index do |filename, i|
32
+ dir = File.dirname(filename)
33
+ if !File.exist?("#{destination_dir}/#{dir}")
34
+ FileUtils.mkdir_p("#{destination_dir}/#{dir}")
35
+ end
36
+ if !File.directory?(filename)
37
+ if preprocess && filename =~ /\.template$/
38
+ real_filename = filename.sub(/\.template$/, '')
39
+ FileUtils.install(filename, "#{destination_dir}/#{real_filename}", :preserve => true)
40
+ Preprocessor.new.start(filename, "#{destination_dir}/#{real_filename}",
41
+ variables)
42
+ else
43
+ FileUtils.install(filename, "#{destination_dir}/#{filename}", :preserve => true)
44
+ end
45
+ end
46
+ if STDOUT.tty?
47
+ printf "\r[%5d/%5d] [%3.0f%%] Copying files...", i + 1, files.size, i * 100.0 / files.size
48
+ STDOUT.flush
49
+ end
50
+ end
51
+ if STDOUT.tty?
52
+ printf "\r[%5d/%5d] [%3.0f%%] Copying files...\n", files.size, files.size, 100
53
+ end
54
54
  end
55
55
 
56
56
  def word_wrap(text, max = 72)
57
- while index = (lines = text.split("\n")).find_index{ |line| line.size > max }
58
- line = lines[index]
59
- pos = max
60
- while pos >= 0 && line[pos..pos] != " "
61
- pos -= 1
62
- end
63
- if pos < 0
64
- raise "Cannot wrap line: #{line}"
65
- else
66
- lines[index] = line[0 .. pos - 1]
67
- lines.insert(index + 1, line[pos + 1 .. -1])
68
- text = lines.join("\n")
69
- end
70
- end
71
- return text
57
+ while index = (lines = text.split("\n")).find_index{ |line| line.size > max }
58
+ line = lines[index]
59
+ pos = max
60
+ while pos >= 0 && line[pos..pos] != " "
61
+ pos -= 1
62
+ end
63
+ if pos < 0
64
+ raise "Cannot wrap line: #{line}"
65
+ else
66
+ lines[index] = line[0 .. pos - 1]
67
+ lines.insert(index + 1, line[pos + 1 .. -1])
68
+ text = lines.join("\n")
69
+ end
70
+ end
71
+ return text
72
72
  end
73
73
 
74
74
  def is_open_source?
75
- return !is_enterprise?
75
+ return !is_enterprise?
76
76
  end
77
77
 
78
78
  def is_enterprise?
79
- return PACKAGE_NAME =~ /enterprise/
79
+ return PACKAGE_NAME =~ /enterprise/
80
80
  end
81
81
 
82
82
  def enterprise_git_url
83
- return "TODO"
83
+ return "TODO"
84
84
  end
85
85
 
86
86
  def git_tag_prefix
87
- if is_open_source?
88
- return "release"
89
- else
90
- return "enterprise"
91
- end
87
+ if is_open_source?
88
+ return "release"
89
+ else
90
+ return "enterprise"
91
+ end
92
92
  end
93
93
 
94
94
  def git_tag
95
- return "#{git_tag_prefix}-#{VERSION_STRING}"
95
+ return "#{git_tag_prefix}-#{VERSION_STRING}"
96
96
  end
97
97
 
98
98
  def homebrew_dir
99
- return "/tmp/homebrew"
99
+ return "/tmp/homebrew"
100
100
  end
101
101
 
102
102
 
103
103
  task :clobber => 'package:clean'
104
104
 
105
105
  task 'package:set_official' do
106
- ENV['OFFICIAL_RELEASE'] = '1'
107
- # These environment variables interfere with 'brew install'
108
- # and maybe other stuff, so unset them.
109
- ENV.delete('CC')
110
- ENV.delete('CXX')
111
- ENV.delete('USE_CCACHE')
106
+ ENV['OFFICIAL_RELEASE'] = '1'
107
+ # These environment variables interfere with 'brew install'
108
+ # and maybe other stuff, so unset them.
109
+ ENV.delete('CC')
110
+ ENV.delete('CXX')
111
+ ENV.delete('USE_CCACHE')
112
112
  end
113
113
 
114
114
  desc "Build, sign & upload gem & tarball"
115
115
  task 'package:release' => ['package:set_official', 'package:gem', 'package:tarball', 'package:sign'] do
116
- PhusionPassenger.require_passenger_lib 'platform_info'
117
- require 'yaml'
118
- require 'uri'
119
- require 'net/http'
120
- require 'net/https'
121
- basename = "#{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}"
122
- version = PhusionPassenger::VERSION_STRING
123
- is_beta = !!version.split('.')[3]
124
-
125
- if !`git status --porcelain | grep -Ev '^\\?\\? '`.empty?
126
- STDERR.puts "-------------------"
127
- abort "*** ERROR: There are uncommitted files. See 'git status'"
128
- end
129
-
130
- begin
131
- website_config = YAML.load_file(File.expand_path("~/.passenger_website.yml"))
132
- rescue Errno::ENOENT
133
- STDERR.puts "-------------------"
134
- abort "*** ERROR: Please put the Phusion Passenger website admin " +
135
- "password in ~/.passenger_website.yml:\n" +
136
- "admin_password: ..."
137
- end
138
-
139
- if !PhusionPassenger::PlatformInfo.find_command("hub")
140
- STDERR.puts "-------------------"
141
- abort "*** ERROR: Please 'brew install hub' first"
142
- end
143
-
144
- if is_open_source?
145
- if boolean_option('HOMEBREW_UPDATE', true) && !is_beta
146
- puts "Updating Homebrew formula..."
147
- Rake::Task['package:update_homebrew'].invoke
148
- else
149
- puts "HOMEBREW_UPDATE set to false, not updating Homebrew formula."
150
- end
151
- end
152
-
153
- sh "git tag -s #{git_tag} -u 0A212A8C -m 'Release #{version}'"
154
-
155
- puts "Proceed with pushing tag to remote Git repo and uploading the gem and signatures? [y/n]"
156
- if STDIN.readline == "y\n"
157
- sh "git push origin #{git_tag}"
158
-
159
- if is_open_source?
160
- sh "s3cmd -P put #{PKG_DIR}/passenger-#{version}.{gem,tar.gz,gem.asc,tar.gz.asc} s3://phusion-passenger/releases/"
161
- sh "gem push #{PKG_DIR}/passenger-#{version}.gem"
162
-
163
- puts "Updating version number on website..."
164
- if is_beta
165
- uri = URI.parse("https://www.phusionpassenger.com/latest_beta_version")
166
- else
167
- uri = URI.parse("https://www.phusionpassenger.com/latest_stable_version")
168
- end
169
- http = Net::HTTP.new(uri.host, uri.port)
170
- http.use_ssl = true
171
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
172
- request = Net::HTTP::Post.new(uri.request_uri)
173
- request.basic_auth("admin", website_config["admin_password"])
174
- request.set_form_data("version" => version)
175
- response = http.request(request)
176
- if response.code != 200 && response.body != "ok"
177
- abort "*** ERROR: Cannot update version number on www.phusionpassenger.com:\n" +
178
- "Status: #{response.code}\n\n" +
179
- response.body
180
- end
181
-
182
- puts "Initiating building of binaries"
183
- Rake::Task['package:initiate_binaries_building'].invoke
184
-
185
- if !is_beta
186
- puts "Initiating building of Debian packages"
187
- Rake::Task['package:initiate_debian_building'].invoke
188
- end
189
-
190
- puts "Building OS X binaries..."
191
- Rake::Task['package:build_osx_binaries'].invoke
192
-
193
- if !is_beta && boolean_option('HOMEBREW_UPDATE', true)
194
- if boolean_option('HOMEBREW_DRY_RUN', false)
195
- puts "HOMEBREW_DRY_RUN set, not submitting pull request. Please find the repo in /tmp/homebrew."
196
- else
197
- puts "Submitting Homebrew pull request..."
198
- sh "cd #{homebrew_dir} && hub pull-request 'Update passenger to version #{version}' -b Homebrew:master"
199
- end
200
- end
201
-
202
- puts "--------------"
203
- puts "All done."
204
- else
205
- dir = "/u/apps/passenger_website/shared"
206
- subdir = string_option('NAME', version)
207
-
208
- sh "scp #{PKG_DIR}/#{basename}.{gem,tar.gz,gem.asc,tar.gz.asc} app@shell.phusion.nl:#{dir}/"
209
- sh "ssh app@shell.phusion.nl 'mkdir -p \"#{dir}/assets/#{subdir}\" && mv #{dir}/#{basename}.{gem,tar.gz,gem.asc,tar.gz.asc} \"#{dir}/assets/#{subdir}/\"'"
210
- command = "curl -F file=@#{PKG_DIR}/#{basename}.gem --user admin:#{website_config['admin_password']} " +
211
- "--output /dev/stderr --write-out '%{http_code}' --silent " +
212
- "https://www.phusionpassenger.com/enterprise_gems/upload"
213
- puts command
214
- result = `#{command}`
215
- if result != "200"
216
- abort "Gem upload failed. HTTP status code: #{result.inspect}"
217
- else
218
- # The response body does not contain a newline,
219
- # so fix terminal output.
220
- puts
221
- end
222
-
223
- puts "Initiating building of binaries"
224
- Rake::Task['package:initiate_binaries_building'].invoke
225
-
226
- if !is_beta
227
- puts "Initiating building of Debian packages"
228
- Rake::Task['package:initiate_debian_building'].invoke
229
- end
230
-
231
- puts "Building OS X binaries..."
232
- Rake::Task['package:build_osx_binaries'].invoke
233
-
234
- puts "--------------"
235
- puts "All done."
236
- end
237
- else
238
- puts "Did not upload anything."
239
- end
116
+ PhusionPassenger.require_passenger_lib 'platform_info'
117
+ require 'yaml'
118
+ require 'uri'
119
+ require 'net/http'
120
+ require 'net/https'
121
+ basename = "#{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}"
122
+ version = PhusionPassenger::VERSION_STRING
123
+ is_beta = !!version.split('.')[3]
124
+
125
+ if !`git status --porcelain | grep -Ev '^\\?\\? '`.empty?
126
+ STDERR.puts "-------------------"
127
+ abort "*** ERROR: There are uncommitted files. See 'git status'"
128
+ end
129
+
130
+ begin
131
+ website_config = YAML.load_file(File.expand_path("~/.passenger_website.yml"))
132
+ rescue Errno::ENOENT
133
+ STDERR.puts "-------------------"
134
+ abort "*** ERROR: Please put the Phusion Passenger website admin " +
135
+ "password in ~/.passenger_website.yml:\n" +
136
+ "admin_password: ..."
137
+ end
138
+
139
+ if !PhusionPassenger::PlatformInfo.find_command("hub")
140
+ STDERR.puts "-------------------"
141
+ abort "*** ERROR: Please 'brew install hub' first"
142
+ end
143
+
144
+ if is_open_source?
145
+ if boolean_option('HOMEBREW_UPDATE', true) && !is_beta
146
+ puts "Updating Homebrew formula..."
147
+ Rake::Task['package:update_homebrew'].invoke
148
+ else
149
+ puts "HOMEBREW_UPDATE set to false, not updating Homebrew formula."
150
+ end
151
+ end
152
+
153
+ sh "git tag -s #{git_tag} -u 0A212A8C -m 'Release #{version}'"
154
+
155
+ puts "Proceed with pushing tag to remote Git repo and uploading the gem and signatures? [y/n]"
156
+ if STDIN.readline == "y\n"
157
+ sh "git push origin #{git_tag}"
158
+
159
+ if is_open_source?
160
+ sh "s3cmd -P put #{PKG_DIR}/passenger-#{version}.{gem,tar.gz,gem.asc,tar.gz.asc} s3://phusion-passenger/releases/"
161
+ sh "gem push #{PKG_DIR}/passenger-#{version}.gem"
162
+
163
+ puts "Updating version number on website..."
164
+ if is_beta
165
+ uri = URI.parse("https://www.phusionpassenger.com/latest_beta_version")
166
+ else
167
+ uri = URI.parse("https://www.phusionpassenger.com/latest_stable_version")
168
+ end
169
+ http = Net::HTTP.new(uri.host, uri.port)
170
+ http.use_ssl = true
171
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
172
+ request = Net::HTTP::Post.new(uri.request_uri)
173
+ request.basic_auth("admin", website_config["admin_password"])
174
+ request.set_form_data("version" => version)
175
+ response = http.request(request)
176
+ if response.code != 200 && response.body != "ok"
177
+ abort "*** ERROR: Cannot update version number on www.phusionpassenger.com:\n" +
178
+ "Status: #{response.code}\n\n" +
179
+ response.body
180
+ end
181
+
182
+ puts "Initiating building of binaries"
183
+ Rake::Task['package:initiate_binaries_building'].invoke
184
+
185
+ if !is_beta
186
+ puts "Initiating building of Debian packages"
187
+ Rake::Task['package:initiate_debian_building'].invoke
188
+ end
189
+
190
+ puts "Building OS X binaries..."
191
+ Rake::Task['package:build_osx_binaries'].invoke
192
+
193
+ if !is_beta && boolean_option('HOMEBREW_UPDATE', true)
194
+ if boolean_option('HOMEBREW_DRY_RUN', false)
195
+ puts "HOMEBREW_DRY_RUN set, not submitting pull request. Please find the repo in /tmp/homebrew."
196
+ else
197
+ puts "Submitting Homebrew pull request..."
198
+ sh "cd #{homebrew_dir} && hub pull-request 'Update passenger to version #{version}' -b Homebrew:master"
199
+ end
200
+ end
201
+
202
+ puts "--------------"
203
+ puts "All done."
204
+ else
205
+ dir = "/u/apps/passenger_website/shared"
206
+ subdir = string_option('NAME', version)
207
+
208
+ sh "scp #{PKG_DIR}/#{basename}.{gem,tar.gz,gem.asc,tar.gz.asc} app@shell.phusion.nl:#{dir}/"
209
+ sh "ssh app@shell.phusion.nl 'mkdir -p \"#{dir}/assets/#{subdir}\" && mv #{dir}/#{basename}.{gem,tar.gz,gem.asc,tar.gz.asc} \"#{dir}/assets/#{subdir}/\"'"
210
+ command = "curl -F file=@#{PKG_DIR}/#{basename}.gem --user admin:'#{website_config['admin_password']}' " +
211
+ "--output /dev/stderr --write-out '%{http_code}' --silent " +
212
+ "https://www.phusionpassenger.com/enterprise_gems/upload"
213
+ puts command
214
+ result = `#{command}`
215
+ if result != "200"
216
+ abort "Gem upload failed. HTTP status code: #{result.inspect}"
217
+ else
218
+ # The response body does not contain a newline,
219
+ # so fix terminal output.
220
+ puts
221
+ end
222
+
223
+ puts "Initiating building of binaries"
224
+ Rake::Task['package:initiate_binaries_building'].invoke
225
+
226
+ if !is_beta
227
+ puts "Initiating building of Debian packages"
228
+ Rake::Task['package:initiate_debian_building'].invoke
229
+ end
230
+
231
+ puts "Building OS X binaries..."
232
+ Rake::Task['package:build_osx_binaries'].invoke
233
+
234
+ puts "--------------"
235
+ puts "All done."
236
+ end
237
+ else
238
+ puts "Did not upload anything."
239
+ end
240
240
  end
241
241
 
242
242
  task 'package:gem' => Packaging::PREGENERATED_FILES do
243
- require 'phusion_passenger'
244
- if ENV['OFFICIAL_RELEASE']
245
- release_file = "#{PhusionPassenger.resources_dir}/release.txt"
246
- File.unlink(release_file) rescue nil
247
- end
248
- begin
249
- if release_file
250
- File.open(release_file, "w").close
251
- end
252
- command = "gem build #{PhusionPassenger::PACKAGE_NAME}.gemspec"
253
- if !boolean_option('SKIP_SIGNING')
254
- command << " --sign --key 0x0A212A8C"
255
- end
256
- sh(command)
257
- ensure
258
- if release_file
259
- File.unlink(release_file) rescue nil
260
- end
261
- end
262
- sh "mkdir -p #{PKG_DIR}"
263
- sh "mv #{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}.gem #{PKG_DIR}/"
243
+ require 'phusion_passenger'
244
+ if ENV['OFFICIAL_RELEASE']
245
+ release_file = "#{PhusionPassenger.resources_dir}/release.txt"
246
+ File.unlink(release_file) rescue nil
247
+ end
248
+ begin
249
+ if release_file
250
+ File.open(release_file, "w").close
251
+ end
252
+ command = "gem build #{PhusionPassenger::PACKAGE_NAME}.gemspec"
253
+ if !boolean_option('SKIP_SIGNING')
254
+ command << " --sign --key 0x0A212A8C"
255
+ end
256
+ sh(command)
257
+ ensure
258
+ if release_file
259
+ File.unlink(release_file) rescue nil
260
+ end
261
+ end
262
+ sh "mkdir -p #{PKG_DIR}"
263
+ sh "mv #{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}.gem #{PKG_DIR}/"
264
264
  end
265
265
 
266
266
  task 'package:tarball' => Packaging::PREGENERATED_FILES do
267
- require 'phusion_passenger'
268
- require 'fileutils'
269
-
270
- basename = "#{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}"
271
- sh "rm -rf #{PKG_DIR}/#{basename}"
272
- sh "mkdir -p #{PKG_DIR}/#{basename}"
273
- recursive_copy_files(ORIG_TARBALL_FILES.call, "#{PKG_DIR}/#{basename}")
274
- if ENV['OFFICIAL_RELEASE']
275
- File.open("#{PKG_DIR}/#{basename}/resources/release.txt", "w").close
276
- end
277
- if PlatformInfo.os_name == "macosx"
278
- sh "cd #{PKG_DIR}/#{basename} && find . -print0 | xargs -0 touch -t '201310270000'"
279
- else
280
- sh "cd #{PKG_DIR}/#{basename} && find . -print0 | xargs -0 touch -d '2013-10-27 00:00:00 UTC'"
281
- end
282
- sh "cd #{PKG_DIR} && tar -c #{basename} | gzip --no-name --best > #{basename}.tar.gz"
283
- sh "rm -rf #{PKG_DIR}/#{basename}"
267
+ require 'phusion_passenger'
268
+ require 'fileutils'
269
+
270
+ basename = "#{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}"
271
+ sh "rm -rf #{PKG_DIR}/#{basename}"
272
+ sh "mkdir -p #{PKG_DIR}/#{basename}"
273
+ recursive_copy_files(ORIG_TARBALL_FILES.call, "#{PKG_DIR}/#{basename}")
274
+ if ENV['OFFICIAL_RELEASE']
275
+ File.open("#{PKG_DIR}/#{basename}/resources/release.txt", "w").close
276
+ end
277
+ if PlatformInfo.os_name == "macosx"
278
+ sh "cd #{PKG_DIR}/#{basename} && find . -print0 | xargs -0 touch -t '201310270000'"
279
+ else
280
+ sh "cd #{PKG_DIR}/#{basename} && find . -print0 | xargs -0 touch -d '2013-10-27 00:00:00 UTC'"
281
+ end
282
+ sh "cd #{PKG_DIR} && tar -c #{basename} | gzip --no-name --best > #{basename}.tar.gz"
283
+ sh "rm -rf #{PKG_DIR}/#{basename}"
284
284
  end
285
285
 
286
286
  task 'package:sign' do
287
- if File.exist?(File.expand_path("~/.gnupg/gpg-agent.conf")) || ENV['GPG_AGENT_INFO']
288
- puts "It looks like you're using gpg-agent, so skipping automatically password caching."
289
- else
290
- begin
291
- require 'highline'
292
- rescue LoadError
293
- abort "Please run `gem install highline` first."
294
- end
295
- h = HighLine.new
296
- password = h.ask("Password for software-signing@phusion.nl GPG key: ") { |q| q.echo = false }
297
- passphrase_opt = "--passphrase-file .gpg-password"
298
- end
299
-
300
- begin
301
- if password
302
- File.open(".gpg-password", "w", 0600) do |f|
303
- f.write(password)
304
- end
305
- end
306
- version = PhusionPassenger::VERSION_STRING
307
- ["passenger-#{version}.gem",
308
- "passenger-#{version}.tar.gz",
309
- "passenger-enterprise-server-#{version}.gem",
310
- "passenger-enterprise-server-#{version}.tar.gz"].each do |name|
311
- if File.exist?("pkg/#{name}")
312
- sh "gpg --sign --detach-sign #{passphrase_opt} --local-user software-signing@phusion.nl --armor pkg/#{name}"
313
- end
314
- end
315
- ensure
316
- File.unlink('.gpg-password') if File.exist?('.gpg-password')
317
- end
287
+ if File.exist?(File.expand_path("~/.gnupg/gpg-agent.conf")) || ENV['GPG_AGENT_INFO']
288
+ puts "It looks like you're using gpg-agent, so skipping automatically password caching."
289
+ else
290
+ begin
291
+ require 'highline'
292
+ rescue LoadError
293
+ abort "Please run `gem install highline` first."
294
+ end
295
+ h = HighLine.new
296
+ password = h.ask("Password for software-signing@phusion.nl GPG key: ") { |q| q.echo = false }
297
+ passphrase_opt = "--passphrase-file .gpg-password"
298
+ end
299
+
300
+ begin
301
+ if password
302
+ File.open(".gpg-password", "w", 0600) do |f|
303
+ f.write(password)
304
+ end
305
+ end
306
+ version = PhusionPassenger::VERSION_STRING
307
+ ["passenger-#{version}.gem",
308
+ "passenger-#{version}.tar.gz",
309
+ "passenger-enterprise-server-#{version}.gem",
310
+ "passenger-enterprise-server-#{version}.tar.gz"].each do |name|
311
+ if File.exist?("pkg/#{name}")
312
+ sh "gpg --sign --detach-sign #{passphrase_opt} --local-user software-signing@phusion.nl --armor pkg/#{name}"
313
+ end
314
+ end
315
+ ensure
316
+ File.unlink('.gpg-password') if File.exist?('.gpg-password')
317
+ end
318
318
  end
319
319
 
320
320
  task 'package:update_homebrew' do
321
- require 'digest/sha1'
322
- version = VERSION_STRING
323
- sha1 = File.open("#{PKG_DIR}/passenger-#{version}.tar.gz", "rb") do |f|
324
- Digest::SHA1.hexdigest(f.read)
325
- end
326
- sh "rm -rf #{homebrew_dir}"
327
- sh "git clone git@github.com:phusion/homebrew.git #{homebrew_dir}"
328
- sh "cd #{homebrew_dir} && git remote add Homebrew https://github.com/Homebrew/homebrew.git"
329
- sh "cd #{homebrew_dir} && git fetch Homebrew"
330
- sh "cd #{homebrew_dir} && git reset --hard Homebrew/master"
331
- formula = File.read("/tmp/homebrew/Library/Formula/passenger.rb")
332
- formula.gsub!(/passenger-.+?\.tar\.gz/, "passenger-#{version}.tar.gz") ||
333
- abort("Unable to substitute Homebrew formula tarball filename")
334
- formula.gsub!(/^ sha1 .*/, " sha1 '#{sha1}'") ||
335
- abort("Unable to substitute Homebrew formula SHA-1")
336
- necessary_dirs = ORIG_TARBALL_FILES.call.map{ |filename| filename.split("/").first }.uniq
337
- necessary_dirs -= Packaging::HOMEBREW_EXCLUDE
338
- necessary_dirs += ["buildout"]
339
- necessary_dirs_str = word_wrap(necessary_dirs.inspect).split("\n").join("\n ")
340
- formula.sub!(/necessary_files = .*?\]/m, "necessary_files = Dir#{necessary_dirs_str}") ||
341
- abort("Unable to substitute file whitelist")
342
- File.open("/tmp/homebrew/Library/Formula/passenger.rb", "w") do |f|
343
- f.write(formula)
344
- end
345
- sh "cd #{homebrew_dir} && git commit -a -m 'passenger #{version}'"
346
- sh "cd #{homebrew_dir} && git push -f"
347
- if boolean_option('HOMEBREW_TEST', true)
348
- sh "cp /tmp/homebrew/Library/Formula/passenger.rb /usr/local/Library/Formula/passenger.rb"
349
- if `brew info passenger` !~ /^Not installed$/
350
- sh "brew uninstall passenger"
351
- end
352
- sh "cp #{PKG_DIR}/passenger-#{version}.tar.gz `brew --cache`/"
353
- sh "brew install passenger"
354
- Rake::Task['test:integration:native_packaging'].invoke
355
- end
321
+ require 'digest/sha1'
322
+ version = VERSION_STRING
323
+ sha1 = File.open("#{PKG_DIR}/passenger-#{version}.tar.gz", "rb") do |f|
324
+ Digest::SHA1.hexdigest(f.read)
325
+ end
326
+ sh "rm -rf #{homebrew_dir}"
327
+ sh "git clone git@github.com:phusion/homebrew.git #{homebrew_dir}"
328
+ sh "cd #{homebrew_dir} && git remote add Homebrew https://github.com/Homebrew/homebrew.git"
329
+ sh "cd #{homebrew_dir} && git fetch Homebrew"
330
+ sh "cd #{homebrew_dir} && git reset --hard Homebrew/master"
331
+ formula = File.read("/tmp/homebrew/Library/Formula/passenger.rb")
332
+ formula.gsub!(/passenger-.+?\.tar\.gz/, "passenger-#{version}.tar.gz") ||
333
+ abort("Unable to substitute Homebrew formula tarball filename")
334
+ formula.gsub!(/^ sha1 .*/, " sha1 '#{sha1}'") ||
335
+ abort("Unable to substitute Homebrew formula SHA-1")
336
+ necessary_dirs = ORIG_TARBALL_FILES.call.map{ |filename| filename.split("/").first }.uniq
337
+ necessary_dirs -= Packaging::HOMEBREW_EXCLUDE
338
+ necessary_dirs += ["buildout"]
339
+ necessary_dirs_str = word_wrap(necessary_dirs.inspect).split("\n").join("\n ")
340
+ formula.sub!(/necessary_files = .*?\]/m, "necessary_files = Dir#{necessary_dirs_str}") ||
341
+ abort("Unable to substitute file whitelist")
342
+ File.open("/tmp/homebrew/Library/Formula/passenger.rb", "w") do |f|
343
+ f.write(formula)
344
+ end
345
+ sh "cd #{homebrew_dir} && git commit -a -m 'passenger #{version}'"
346
+ sh "cd #{homebrew_dir} && git push -f"
347
+ if boolean_option('HOMEBREW_TEST', true)
348
+ sh "cp /tmp/homebrew/Library/Formula/passenger.rb /usr/local/Library/Formula/passenger.rb"
349
+ if `brew info passenger` !~ /^Not installed$/
350
+ sh "brew uninstall passenger"
351
+ end
352
+ sh "cp #{PKG_DIR}/passenger-#{version}.tar.gz `brew --cache`/"
353
+ sh "brew install passenger"
354
+ Rake::Task['test:integration:native_packaging'].invoke
355
+ end
356
356
  end
357
357
 
358
358
  task 'package:initiate_binaries_building' do
359
- require 'yaml'
360
- require 'uri'
361
- require 'net/http'
362
- require 'net/https'
363
- version = VERSION_STRING
364
- begin
365
- website_config = YAML.load_file(File.expand_path("~/.passenger_website.yml"))
366
- rescue Errno::ENOENT
367
- STDERR.puts "-------------------"
368
- abort "*** ERROR: Please put the Phusion Passenger website admin " +
369
- "password in ~/.passenger_website.yml:\n" +
370
- "admin_password: ..."
371
- end
372
- if is_open_source?
373
- type = "open%20source"
374
- jenkins_token = website_config["jenkins_token"]
375
- if !jenkins_token
376
- abort "*** ERROR: Please put the Passenger open source Jenkins " +
377
- "authentication token in ~/.passenger_website.yml, under " +
378
- "the 'jenkins_token' key."
379
- end
380
- else
381
- type = "Enterprise"
382
- jenkins_token = website_config["jenkins_enterprise_token"]
383
- if !jenkins_token
384
- abort "*** ERROR: Please put the Passenger Enterprise Jenkins " +
385
- "authentication token in ~/.passenger_website.yml, under " +
386
- "the 'jenkins_enterprise_token' key."
387
- end
388
- end
389
-
390
- uri = URI.parse("https://oss-jenkins.phusion.nl/buildByToken/buildWithParameters?" +
391
- "job=Passenger%20#{type}%20binaries%20(release)&tag=#{git_tag}")
392
- http = Net::HTTP.new(uri.host, uri.port)
393
- http.use_ssl = true
394
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
395
- request = Net::HTTP::Post.new(uri.request_uri)
396
- request.set_form_data("token" => jenkins_token)
397
- response = http.request(request)
398
- if response.code != 200 && response.body != "Scheduled.\n"
399
- abort "*** ERROR: Cannot initiate building of binaries:\n" +
400
- "Status: #{response.code}\n\n" +
401
- response.body
402
- end
403
- puts "Initiated building of binaries."
359
+ require 'yaml'
360
+ require 'uri'
361
+ require 'net/http'
362
+ require 'net/https'
363
+ version = VERSION_STRING
364
+ begin
365
+ website_config = YAML.load_file(File.expand_path("~/.passenger_website.yml"))
366
+ rescue Errno::ENOENT
367
+ STDERR.puts "-------------------"
368
+ abort "*** ERROR: Please put the Phusion Passenger website admin " +
369
+ "password in ~/.passenger_website.yml:\n" +
370
+ "admin_password: ..."
371
+ end
372
+ if is_open_source?
373
+ type = "open%20source"
374
+ jenkins_token = website_config["jenkins_token"]
375
+ if !jenkins_token
376
+ abort "*** ERROR: Please put the Passenger open source Jenkins " +
377
+ "authentication token in ~/.passenger_website.yml, under " +
378
+ "the 'jenkins_token' key."
379
+ end
380
+ else
381
+ type = "Enterprise"
382
+ jenkins_token = website_config["jenkins_enterprise_token"]
383
+ if !jenkins_token
384
+ abort "*** ERROR: Please put the Passenger Enterprise Jenkins " +
385
+ "authentication token in ~/.passenger_website.yml, under " +
386
+ "the 'jenkins_enterprise_token' key."
387
+ end
388
+ end
389
+
390
+ uri = URI.parse("https://oss-jenkins.phusion.nl/buildByToken/buildWithParameters?" +
391
+ "job=Passenger%20#{type}%20binaries%20(release)&tag=#{git_tag}")
392
+ http = Net::HTTP.new(uri.host, uri.port)
393
+ http.use_ssl = true
394
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
395
+ request = Net::HTTP::Post.new(uri.request_uri)
396
+ request.set_form_data("token" => jenkins_token)
397
+ response = http.request(request)
398
+ if response.code != 200 && response.body != "Scheduled.\n"
399
+ abort "*** ERROR: Cannot initiate building of binaries:\n" +
400
+ "Status: #{response.code}\n\n" +
401
+ response.body
402
+ end
403
+ puts "Initiated building of binaries."
404
404
  end
405
405
 
406
406
  task 'package:initiate_debian_building' do
407
- require 'yaml'
408
- require 'uri'
409
- require 'net/http'
410
- require 'net/https'
411
- version = VERSION_STRING
412
- begin
413
- website_config = YAML.load_file(File.expand_path("~/.passenger_website.yml"))
414
- rescue Errno::ENOENT
415
- STDERR.puts "-------------------"
416
- abort "*** ERROR: Please put the Phusion Passenger website admin " +
417
- "password in ~/.passenger_website.yml:\n" +
418
- "admin_password: ..."
419
- end
420
- if is_open_source?
421
- type = "open%20source"
422
- jenkins_token = website_config["jenkins_token"]
423
- if !jenkins_token
424
- abort "*** ERROR: Please put the Passenger open source Jenkins " +
425
- "authentication token in ~/.passenger_website.yml, under " +
426
- "the 'jenkins_token' key."
427
- end
428
- else
429
- type = "Enterprise"
430
- jenkins_token = website_config["jenkins_enterprise_token"]
431
- if !jenkins_token
432
- abort "*** ERROR: Please put the Passenger Enterprise Jenkins " +
433
- "authentication token in ~/.passenger_website.yml, under " +
434
- "the 'jenkins_enterprise_token' key."
435
- end
436
- end
437
-
438
- uri = URI.parse("https://oss-jenkins.phusion.nl/buildByToken/buildWithParameters?" +
439
- "job=Passenger%20#{type}%20Debian%20packages%20(release)&ref=#{git_tag}")
440
- http = Net::HTTP.new(uri.host, uri.port)
441
- http.use_ssl = true
442
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
443
- request = Net::HTTP::Post.new(uri.request_uri)
444
- request.set_form_data("token" => jenkins_token)
445
- response = http.request(request)
446
- if response.code != 200 && response.body != "Scheduled.\n"
447
- abort "*** ERROR: Cannot initiate building of Debian packages:\n" +
448
- "Status: #{response.code}\n\n" +
449
- response.body
450
- end
451
- puts "Initiated building of Debian packages."
407
+ require 'yaml'
408
+ require 'uri'
409
+ require 'net/http'
410
+ require 'net/https'
411
+ version = VERSION_STRING
412
+ begin
413
+ website_config = YAML.load_file(File.expand_path("~/.passenger_website.yml"))
414
+ rescue Errno::ENOENT
415
+ STDERR.puts "-------------------"
416
+ abort "*** ERROR: Please put the Phusion Passenger website admin " +
417
+ "password in ~/.passenger_website.yml:\n" +
418
+ "admin_password: ..."
419
+ end
420
+ if is_open_source?
421
+ type = "open%20source"
422
+ jenkins_token = website_config["jenkins_token"]
423
+ if !jenkins_token
424
+ abort "*** ERROR: Please put the Passenger open source Jenkins " +
425
+ "authentication token in ~/.passenger_website.yml, under " +
426
+ "the 'jenkins_token' key."
427
+ end
428
+ else
429
+ type = "Enterprise"
430
+ jenkins_token = website_config["jenkins_enterprise_token"]
431
+ if !jenkins_token
432
+ abort "*** ERROR: Please put the Passenger Enterprise Jenkins " +
433
+ "authentication token in ~/.passenger_website.yml, under " +
434
+ "the 'jenkins_enterprise_token' key."
435
+ end
436
+ end
437
+
438
+ uri = URI.parse("https://oss-jenkins.phusion.nl/buildByToken/buildWithParameters?" +
439
+ "job=Passenger%20#{type}%20Debian%20packages%20(release)&ref=#{git_tag}")
440
+ http = Net::HTTP.new(uri.host, uri.port)
441
+ http.use_ssl = true
442
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
443
+ request = Net::HTTP::Post.new(uri.request_uri)
444
+ request.set_form_data("token" => jenkins_token)
445
+ response = http.request(request)
446
+ if response.code != 200 && response.body != "Scheduled.\n"
447
+ abort "*** ERROR: Cannot initiate building of Debian packages:\n" +
448
+ "Status: #{response.code}\n\n" +
449
+ response.body
450
+ end
451
+ puts "Initiated building of Debian packages."
452
452
  end
453
453
 
454
454
  task 'package:build_osx_binaries' do
455
- if is_open_source?
456
- sh "cd ../passenger_autobuilder && " +
457
- "git pull && " +
458
- "./autobuild-osx https://github.com/phusion/passenger.git passenger " +
459
- "psg_autobuilder_chroot@juvia-helper.phusion.nl --tag=#{git_tag}"
460
- else
461
- sh "cd ../passenger_autobuilder && " +
462
- "git pull && " +
463
- "./autobuild-osx #{enterprise_git_url} passenger-enterprise " +
464
- "psg_autobuilder_chroot@juvia-helper.phusion.nl --tag=#{git_tag}"
465
- end
455
+ if is_open_source?
456
+ sh "cd ../passenger_autobuilder && " +
457
+ "git pull && " +
458
+ "./autobuild-osx https://github.com/phusion/passenger.git passenger " +
459
+ "psg_autobuilder_chroot@juvia-helper.phusion.nl --tag=#{git_tag}"
460
+ else
461
+ sh "cd ../passenger_autobuilder && " +
462
+ "git pull && " +
463
+ "./autobuild-osx #{enterprise_git_url} passenger-enterprise " +
464
+ "psg_autobuilder_chroot@juvia-helper.phusion.nl --tag=#{git_tag}"
465
+ end
466
466
  end
467
467
 
468
468
  desc "Remove gem, tarball and signatures"
469
469
  task 'package:clean' do
470
- require 'phusion_passenger'
471
- basename = "#{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}"
472
- sh "rm -f pkg/#{basename}.{gem,gem.asc,tar.gz,tar.gz.asc}"
470
+ require 'phusion_passenger'
471
+ basename = "#{PhusionPassenger::PACKAGE_NAME}-#{PhusionPassenger::VERSION_STRING}"
472
+ sh "rm -f pkg/#{basename}.{gem,gem.asc,tar.gz,tar.gz.asc}"
473
473
  end
474
474
 
475
475
  def change_shebang(filename, value)
476
- contents = File.open(filename, "r") do |f|
477
- f.read
478
- end
479
- contents.gsub!(/\A#\!.+$/, "#!#{value}")
480
- File.open(filename, "w") do |f|
481
- f.write(contents)
482
- end
476
+ contents = File.open(filename, "r") do |f|
477
+ f.read
478
+ end
479
+ contents.gsub!(/\A#\!.+$/, "#!#{value}")
480
+ File.open(filename, "w") do |f|
481
+ f.write(contents)
482
+ end
483
483
  end
484
484
 
485
485
  desc "Create a fakeroot, useful for building native packages"
486
486
  task :fakeroot => [:apache2, :nginx, :doc] do
487
- require 'rbconfig'
488
- require 'fileutils'
489
- include RbConfig
490
-
491
- fs_prefix = ENV['FS_PREFIX'] || "/usr"
492
- fs_bindir = ENV['FS_BINDIR'] || "#{fs_prefix}/bin"
493
- fs_sbindir = ENV['FS_SBINDIR'] || "#{fs_prefix}/sbin"
494
- fs_datadir = ENV['FS_DATADIR'] || "#{fs_prefix}/share"
495
- fs_docdir = ENV['FS_DOCDIR'] || "#{fs_datadir}/doc"
496
- fs_libdir = ENV['FS_LIBDIR'] || "#{fs_prefix}/lib"
497
-
498
- # We don't use CONFIG['archdir'] and the like because we want
499
- # the files to be installed to /usr, and the Ruby interpreter
500
- # on the packaging machine might be in /usr/local.
501
- psg_rubylibdir = ENV['RUBYLIBDIR'] || "#{fs_libdir}/ruby/vendor_ruby"
502
- psg_nodelibdir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/node"
503
- psg_libdir = "#{fs_libdir}/#{GLOBAL_NAMESPACE_DIRNAME}"
504
- psg_native_support_dir = ENV["RUBYARCHDIR"] || "#{fs_libdir}/ruby/#{CONFIG['ruby_version']}/#{CONFIG['arch']}"
505
- psg_support_binaries_dir = "#{fs_libdir}/#{GLOBAL_NAMESPACE_DIRNAME}/support-binaries"
506
- psg_helper_scripts_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/helper-scripts"
507
- psg_resources_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}"
508
- psg_include_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/include"
509
- psg_docdir = "#{fs_docdir}/#{GLOBAL_NAMESPACE_DIRNAME}"
510
- psg_bindir = "#{fs_bindir}"
511
- psg_sbindir = "#{fs_sbindir}"
512
- psg_apache2_module_path = ENV['APACHE2_MODULE_PATH'] || "#{fs_libdir}/apache2/modules/mod_passenger.so"
513
- psg_ruby_extension_source_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/ruby_extension_source"
514
- psg_nginx_module_source_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/ngx_http_passenger_module"
515
-
516
- fakeroot = "pkg/fakeroot"
517
- fake_rubylibdir = "#{fakeroot}#{psg_rubylibdir}"
518
- fake_nodelibdir = "#{fakeroot}#{psg_nodelibdir}"
519
- fake_libdir = "#{fakeroot}#{psg_libdir}"
520
- fake_native_support_dir = "#{fakeroot}#{psg_native_support_dir}"
521
- fake_support_binaries_dir = "#{fakeroot}#{psg_support_binaries_dir}"
522
- fake_helper_scripts_dir = "#{fakeroot}#{psg_helper_scripts_dir}"
523
- fake_resources_dir = "#{fakeroot}#{psg_resources_dir}"
524
- fake_include_dir = "#{fakeroot}#{psg_include_dir}"
525
- fake_docdir = "#{fakeroot}#{psg_docdir}"
526
- fake_bindir = "#{fakeroot}#{psg_bindir}"
527
- fake_sbindir = "#{fakeroot}#{psg_sbindir}"
528
- fake_apache2_module_path = "#{fakeroot}#{psg_apache2_module_path}"
529
- fake_ruby_extension_source_dir = "#{fakeroot}#{psg_ruby_extension_source_dir}"
530
- fake_nginx_module_source_dir = "#{fakeroot}#{psg_nginx_module_source_dir}"
531
-
532
- packaging_method = ENV['NATIVE_PACKAGING_METHOD'] || ENV['PACKAGING_METHOD'] || "deb"
533
-
534
- sh "rm -rf #{fakeroot}"
535
- sh "mkdir -p #{fakeroot}"
536
-
537
- # Ruby sources
538
- sh "mkdir -p #{fake_rubylibdir}"
539
- sh "cp #{PhusionPassenger.ruby_libdir}/phusion_passenger.rb #{fake_rubylibdir}/"
540
- sh "cp -R #{PhusionPassenger.ruby_libdir}/phusion_passenger #{fake_rubylibdir}/"
541
-
542
- # Node.js sources
543
- sh "mkdir -p #{fake_nodelibdir}"
544
- sh "cp -R #{PhusionPassenger.node_libdir}/phusion_passenger #{fake_nodelibdir}/"
545
-
546
- # Phusion Passenger common libraries
547
- sh "mkdir -p #{fake_libdir}"
548
- sh "cp -R #{PhusionPassenger.lib_dir}/common #{fake_libdir}/"
549
- sh "rm -rf #{fake_libdir}/common/libboost_oxt"
550
-
551
- # Ruby extension binaries
552
- sh "mkdir -p #{fake_native_support_dir}"
553
- native_support_archdir = PlatformInfo.ruby_extension_binary_compatibility_id
554
- sh "mkdir -p #{fake_native_support_dir}"
555
- sh "cp -R buildout/ruby/#{native_support_archdir}/*.#{LIBEXT} #{fake_native_support_dir}/"
556
-
557
- # Support binaries
558
- sh "mkdir -p #{fake_support_binaries_dir}"
559
- sh "cp -R #{PhusionPassenger.support_binaries_dir}/* #{fake_support_binaries_dir}/"
560
- sh "rm -rf #{fake_support_binaries_dir}/*.dSYM"
561
- sh "rm -rf #{fake_support_binaries_dir}/*/*.dSYM"
562
- sh "rm -rf #{fake_support_binaries_dir}/*.o"
563
-
564
- # Helper scripts
565
- sh "mkdir -p #{fake_helper_scripts_dir}"
566
- sh "cp -R #{PhusionPassenger.helper_scripts_dir}/* #{fake_helper_scripts_dir}/"
567
-
568
- # Resources
569
- sh "mkdir -p #{fake_resources_dir}"
570
- sh "cp -R resources/* #{fake_resources_dir}/"
571
-
572
- # Headers necessary for building the Nginx module
573
- sh "mkdir -p #{fake_include_dir}"
574
- # Infer headers that the Nginx module needs
575
- headers = []
576
- Dir["ext/nginx/*.[ch]"].each do |filename|
577
- File.read(filename).split("\n").grep(%r{#include "common/(.+)"}) do |match|
578
- headers << ["ext/common/#{$1}", "common/#{$1}"]
579
- end
580
- end
581
- # Manually add headers that could not be inferred through
582
- # the above code
583
- headers.concat([
584
- ["ext/common/Exceptions.h", "common/Exceptions.h"],
585
- ["ext/common/Utils/modp_b64.h", "common/Utils/modp_b64.h"],
586
- ["ext/common/Utils/modp_b64_data.h", "common/Utils/modp_b64_data.h"],
587
- ["ext/boost/detail/endian.hpp", "boost/detail/endian.hpp"]
588
- ])
589
- headers.each do |header|
590
- target = "#{fake_include_dir}/#{header[1]}"
591
- dir = File.dirname(target)
592
- if !File.directory?(dir)
593
- sh "mkdir -p #{dir}"
594
- end
595
- sh "cp #{header[0]} #{target}"
596
- end
597
-
598
- # Nginx module sources
599
- sh "mkdir -p #{fake_nginx_module_source_dir}"
600
- sh "cp ext/nginx/* #{fake_nginx_module_source_dir}/"
601
-
602
- # Documentation
603
- sh "mkdir -p #{fake_docdir}"
604
- sh "cp doc/*.html #{fake_docdir}/"
605
- sh "cp -R doc/images #{fake_docdir}/"
606
-
607
- # User binaries
608
- sh "mkdir -p #{fake_bindir}"
609
- Packaging::USER_EXECUTABLES.each do |exe|
610
- sh "cp bin/#{exe} #{fake_bindir}/"
611
- if !Packaging::EXECUTABLES_WITH_FREE_RUBY.include?(exe)
612
- change_shebang("#{fake_bindir}/#{exe}", "#{fs_bindir}/ruby")
613
- end
614
- end
615
-
616
- # Superuser binaries
617
- sh "mkdir -p #{fake_sbindir}"
618
- Packaging::SUPER_USER_EXECUTABLES.each do |exe|
619
- sh "cp bin/#{exe} #{fake_sbindir}/"
620
- if !Packaging::EXECUTABLES_WITH_FREE_RUBY.include?(exe)
621
- change_shebang("#{fake_sbindir}/#{exe}", "#{fs_bindir}/ruby")
622
- end
623
- end
624
-
625
- # Apache 2 module
626
- sh "mkdir -p #{File.dirname(fake_apache2_module_path)}"
627
- sh "cp #{APACHE2_MODULE} #{fake_apache2_module_path}"
628
-
629
- # Ruby extension sources
630
- sh "mkdir -p #{fake_ruby_extension_source_dir}"
631
- sh "cp -R #{PhusionPassenger.ruby_extension_source_dir}/* #{fake_ruby_extension_source_dir}"
632
-
633
- puts "Creating #{fake_rubylibdir}/phusion_passenger/locations.ini"
634
- File.open("#{fake_rubylibdir}/phusion_passenger/locations.ini", "w") do |f|
635
- f.puts "[locations]"
636
- f.puts "packaging_method=#{packaging_method}"
637
- f.puts "bin_dir=#{psg_bindir}"
638
- f.puts "support_binaries_dir=#{psg_support_binaries_dir}"
639
- f.puts "lib_dir=#{psg_libdir}"
640
- f.puts "helper_scripts_dir=#{psg_helper_scripts_dir}"
641
- f.puts "resources_dir=#{psg_resources_dir}"
642
- f.puts "include_dir=#{psg_include_dir}"
643
- f.puts "doc_dir=#{psg_docdir}"
644
- f.puts "ruby_libdir=#{psg_rubylibdir}"
645
- f.puts "node_libdir=#{psg_nodelibdir}"
646
- f.puts "apache2_module_path=#{psg_apache2_module_path}"
647
- f.puts "ruby_extension_source_dir=#{psg_ruby_extension_source_dir}"
648
- f.puts "nginx_module_source_dir=#{psg_nginx_module_source_dir}"
649
- end
650
-
651
- # Sanity check the locations.ini file
652
- options = PhusionPassenger.parse_ini_file("#{fake_rubylibdir}/phusion_passenger/locations.ini")
653
- PhusionPassenger::REQUIRED_LOCATIONS_INI_FIELDS.each do |field|
654
- if !options[field.to_s]
655
- raise "Bug in build/packaging.rb: the generated locations.ini is missing the '#{field}' field"
656
- end
657
- end
658
-
659
- sh "find #{fakeroot} -name .DS_Store -print0 | xargs -0 rm -f"
487
+ require 'rbconfig'
488
+ require 'fileutils'
489
+ include RbConfig
490
+
491
+ fs_prefix = ENV['FS_PREFIX'] || "/usr"
492
+ fs_bindir = ENV['FS_BINDIR'] || "#{fs_prefix}/bin"
493
+ fs_sbindir = ENV['FS_SBINDIR'] || "#{fs_prefix}/sbin"
494
+ fs_datadir = ENV['FS_DATADIR'] || "#{fs_prefix}/share"
495
+ fs_docdir = ENV['FS_DOCDIR'] || "#{fs_datadir}/doc"
496
+ fs_libdir = ENV['FS_LIBDIR'] || "#{fs_prefix}/lib"
497
+
498
+ # We don't use CONFIG['archdir'] and the like because we want
499
+ # the files to be installed to /usr, and the Ruby interpreter
500
+ # on the packaging machine might be in /usr/local.
501
+ psg_rubylibdir = ENV['RUBYLIBDIR'] || "#{fs_libdir}/ruby/vendor_ruby"
502
+ psg_nodelibdir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/node"
503
+ psg_libdir = "#{fs_libdir}/#{GLOBAL_NAMESPACE_DIRNAME}"
504
+ psg_native_support_dir = ENV["RUBYARCHDIR"] || "#{fs_libdir}/ruby/#{CONFIG['ruby_version']}/#{CONFIG['arch']}"
505
+ psg_support_binaries_dir = "#{fs_libdir}/#{GLOBAL_NAMESPACE_DIRNAME}/support-binaries"
506
+ psg_helper_scripts_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/helper-scripts"
507
+ psg_resources_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}"
508
+ psg_include_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/include"
509
+ psg_docdir = "#{fs_docdir}/#{GLOBAL_NAMESPACE_DIRNAME}"
510
+ psg_bindir = "#{fs_bindir}"
511
+ psg_sbindir = "#{fs_sbindir}"
512
+ psg_apache2_module_path = ENV['APACHE2_MODULE_PATH'] || "#{fs_libdir}/apache2/modules/mod_passenger.so"
513
+ psg_ruby_extension_source_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/ruby_extension_source"
514
+ psg_nginx_module_source_dir = "#{fs_datadir}/#{GLOBAL_NAMESPACE_DIRNAME}/ngx_http_passenger_module"
515
+
516
+ fakeroot = "pkg/fakeroot"
517
+ fake_rubylibdir = "#{fakeroot}#{psg_rubylibdir}"
518
+ fake_nodelibdir = "#{fakeroot}#{psg_nodelibdir}"
519
+ fake_libdir = "#{fakeroot}#{psg_libdir}"
520
+ fake_native_support_dir = "#{fakeroot}#{psg_native_support_dir}"
521
+ fake_support_binaries_dir = "#{fakeroot}#{psg_support_binaries_dir}"
522
+ fake_helper_scripts_dir = "#{fakeroot}#{psg_helper_scripts_dir}"
523
+ fake_resources_dir = "#{fakeroot}#{psg_resources_dir}"
524
+ fake_include_dir = "#{fakeroot}#{psg_include_dir}"
525
+ fake_docdir = "#{fakeroot}#{psg_docdir}"
526
+ fake_bindir = "#{fakeroot}#{psg_bindir}"
527
+ fake_sbindir = "#{fakeroot}#{psg_sbindir}"
528
+ fake_apache2_module_path = "#{fakeroot}#{psg_apache2_module_path}"
529
+ fake_ruby_extension_source_dir = "#{fakeroot}#{psg_ruby_extension_source_dir}"
530
+ fake_nginx_module_source_dir = "#{fakeroot}#{psg_nginx_module_source_dir}"
531
+
532
+ packaging_method = ENV['NATIVE_PACKAGING_METHOD'] || ENV['PACKAGING_METHOD'] || "deb"
533
+
534
+ sh "rm -rf #{fakeroot}"
535
+ sh "mkdir -p #{fakeroot}"
536
+
537
+ # Ruby sources
538
+ sh "mkdir -p #{fake_rubylibdir}"
539
+ sh "cp #{PhusionPassenger.ruby_libdir}/phusion_passenger.rb #{fake_rubylibdir}/"
540
+ sh "cp -R #{PhusionPassenger.ruby_libdir}/phusion_passenger #{fake_rubylibdir}/"
541
+
542
+ # Node.js sources
543
+ sh "mkdir -p #{fake_nodelibdir}"
544
+ sh "cp -R #{PhusionPassenger.node_libdir}/phusion_passenger #{fake_nodelibdir}/"
545
+
546
+ # Phusion Passenger common libraries
547
+ sh "mkdir -p #{fake_libdir}"
548
+ sh "cp -R #{PhusionPassenger.lib_dir}/common #{fake_libdir}/"
549
+ sh "rm -rf #{fake_libdir}/common/libboost_oxt"
550
+
551
+ # Ruby extension binaries
552
+ sh "mkdir -p #{fake_native_support_dir}"
553
+ native_support_archdir = PlatformInfo.ruby_extension_binary_compatibility_id
554
+ sh "mkdir -p #{fake_native_support_dir}"
555
+ sh "cp -R buildout/ruby/#{native_support_archdir}/*.#{LIBEXT} #{fake_native_support_dir}/"
556
+
557
+ # Support binaries
558
+ sh "mkdir -p #{fake_support_binaries_dir}"
559
+ sh "cp -R #{PhusionPassenger.support_binaries_dir}/* #{fake_support_binaries_dir}/"
560
+ sh "rm -rf #{fake_support_binaries_dir}/*.dSYM"
561
+ sh "rm -rf #{fake_support_binaries_dir}/*/*.dSYM"
562
+ sh "rm -rf #{fake_support_binaries_dir}/*.o"
563
+
564
+ # Helper scripts
565
+ sh "mkdir -p #{fake_helper_scripts_dir}"
566
+ sh "cp -R #{PhusionPassenger.helper_scripts_dir}/* #{fake_helper_scripts_dir}/"
567
+
568
+ # Resources
569
+ sh "mkdir -p #{fake_resources_dir}"
570
+ sh "cp -R resources/* #{fake_resources_dir}/"
571
+
572
+ # Headers necessary for building the Nginx module
573
+ sh "mkdir -p #{fake_include_dir}"
574
+ # Infer headers that the Nginx module needs
575
+ headers = []
576
+ Dir["ext/nginx/*.[ch]"].each do |filename|
577
+ File.read(filename).split("\n").grep(%r{#include "common/(.+)"}) do |match|
578
+ headers << ["ext/common/#{$1}", "common/#{$1}"]
579
+ end
580
+ end
581
+ # Manually add headers that could not be inferred through
582
+ # the above code
583
+ headers.concat([
584
+ ["ext/common/Exceptions.h", "common/Exceptions.h"],
585
+ ["ext/common/Utils/modp_b64.h", "common/Utils/modp_b64.h"],
586
+ ["ext/common/Utils/modp_b64_data.h", "common/Utils/modp_b64_data.h"],
587
+ ["ext/boost/detail/endian.hpp", "boost/detail/endian.hpp"]
588
+ ])
589
+ headers.each do |header|
590
+ target = "#{fake_include_dir}/#{header[1]}"
591
+ dir = File.dirname(target)
592
+ if !File.directory?(dir)
593
+ sh "mkdir -p #{dir}"
594
+ end
595
+ sh "cp #{header[0]} #{target}"
596
+ end
597
+
598
+ # Nginx module sources
599
+ sh "mkdir -p #{fake_nginx_module_source_dir}"
600
+ sh "cp ext/nginx/* #{fake_nginx_module_source_dir}/"
601
+
602
+ # Documentation
603
+ sh "mkdir -p #{fake_docdir}"
604
+ sh "cp doc/*.html #{fake_docdir}/"
605
+ sh "cp -R doc/images #{fake_docdir}/"
606
+
607
+ # User binaries
608
+ sh "mkdir -p #{fake_bindir}"
609
+ Packaging::USER_EXECUTABLES.each do |exe|
610
+ sh "cp bin/#{exe} #{fake_bindir}/"
611
+ if !Packaging::EXECUTABLES_WITH_FREE_RUBY.include?(exe)
612
+ change_shebang("#{fake_bindir}/#{exe}", "#{fs_bindir}/ruby")
613
+ end
614
+ end
615
+
616
+ # Superuser binaries
617
+ sh "mkdir -p #{fake_sbindir}"
618
+ Packaging::SUPER_USER_EXECUTABLES.each do |exe|
619
+ sh "cp bin/#{exe} #{fake_sbindir}/"
620
+ if !Packaging::EXECUTABLES_WITH_FREE_RUBY.include?(exe)
621
+ change_shebang("#{fake_sbindir}/#{exe}", "#{fs_bindir}/ruby")
622
+ end
623
+ end
624
+
625
+ # Apache 2 module
626
+ sh "mkdir -p #{File.dirname(fake_apache2_module_path)}"
627
+ sh "cp #{APACHE2_MODULE} #{fake_apache2_module_path}"
628
+
629
+ # Ruby extension sources
630
+ sh "mkdir -p #{fake_ruby_extension_source_dir}"
631
+ sh "cp -R #{PhusionPassenger.ruby_extension_source_dir}/* #{fake_ruby_extension_source_dir}"
632
+
633
+ puts "Creating #{fake_rubylibdir}/phusion_passenger/locations.ini"
634
+ File.open("#{fake_rubylibdir}/phusion_passenger/locations.ini", "w") do |f|
635
+ f.puts "[locations]"
636
+ f.puts "packaging_method=#{packaging_method}"
637
+ f.puts "bin_dir=#{psg_bindir}"
638
+ f.puts "support_binaries_dir=#{psg_support_binaries_dir}"
639
+ f.puts "lib_dir=#{psg_libdir}"
640
+ f.puts "helper_scripts_dir=#{psg_helper_scripts_dir}"
641
+ f.puts "resources_dir=#{psg_resources_dir}"
642
+ f.puts "include_dir=#{psg_include_dir}"
643
+ f.puts "doc_dir=#{psg_docdir}"
644
+ f.puts "ruby_libdir=#{psg_rubylibdir}"
645
+ f.puts "node_libdir=#{psg_nodelibdir}"
646
+ f.puts "apache2_module_path=#{psg_apache2_module_path}"
647
+ f.puts "ruby_extension_source_dir=#{psg_ruby_extension_source_dir}"
648
+ f.puts "nginx_module_source_dir=#{psg_nginx_module_source_dir}"
649
+ end
650
+
651
+ # Sanity check the locations.ini file
652
+ options = PhusionPassenger.parse_ini_file("#{fake_rubylibdir}/phusion_passenger/locations.ini")
653
+ PhusionPassenger::REQUIRED_LOCATIONS_INI_FIELDS.each do |field|
654
+ if !options[field.to_s]
655
+ raise "Bug in build/packaging.rb: the generated locations.ini is missing the '#{field}' field"
656
+ end
657
+ end
658
+
659
+ sh "find #{fakeroot} -name .DS_Store -print0 | xargs -0 rm -f"
660
660
  end