lib/phusion_passenger.rb in passenger-4.0.30 vs lib/phusion_passenger.rb in passenger-4.0.31

- old
+ new

@@ -28,11 +28,11 @@ ###### Names and version numbers ###### PACKAGE_NAME = 'passenger' # Run 'rake ext/common/Constants.h' after changing this number. - VERSION_STRING = '4.0.30' + VERSION_STRING = '4.0.31' PREFERRED_NGINX_VERSION = '1.4.4' NGINX_SHA256_CHECKSUM = '7c989a58e5408c9593da0bebcd0e4ffc3d892d1316ba5042ddb0be5b0b4102b9' PREFERRED_PCRE_VERSION = '8.32' @@ -69,11 +69,14 @@ :nginx_module_source_dir ].freeze OPTIONAL_LOCATIONS_INI_FIELDS = [ # Directory in which downloaded Phusion Passenger binaries are stored. # Only available when originally packaged. - :download_cache_dir + :download_cache_dir, + # Directory in which the build system's output is stored, e.g. + # the compiled agent executables. Only available when originally packaged. + :buildout_dir ].freeze # Follows the logic of ext/common/ResourceLocator.h, so don't forget to modify that too. def self.locate_directories(source_root_or_location_configuration_file = nil) source_root_or_location_configuration_file ||= find_location_configuration_file @@ -81,17 +84,26 @@ if root_or_file && File.file?(root_or_file) filename = root_or_file options = parse_ini_file(filename) - @natively_packaged = get_bool_option(filename, options, 'natively_packaged') + @natively_packaged = get_bool_option(filename, options, 'natively_packaged') + if natively_packaged? + @native_packaging_method = get_option(filename, options, 'native_packaging_method') + end REQUIRED_LOCATIONS_INI_FIELDS.each do |field| instance_variable_set("@#{field}", get_option(filename, options, field.to_s).freeze) end OPTIONAL_LOCATIONS_INI_FIELDS.each do |field| instance_variable_set("@#{field}", get_option(filename, options, field.to_s, false).freeze) end + if !originally_packaged? + # Since these options are only supposed to be available when + # originally packaged, force them to be nil when natively packaged. + @download_cache_dir = nil + @buildout_dir = nil + end else @source_root = File.dirname(File.dirname(FILE_LOCATION)) @natively_packaged = false @bin_dir = "#{@source_root}/bin".freeze @agents_dir = "#{@source_root}/buildout/agents".freeze @@ -104,10 +116,11 @@ @node_libdir = "#{@source_root}/node_lib".freeze @apache2_module_path = "#{@source_root}/buildout/apache2/mod_passenger.so".freeze @ruby_extension_source_dir = "#{@source_root}/ext/ruby" @nginx_module_source_dir = "#{@source_root}/ext/nginx" @download_cache_dir = "#{@source_root}/download_cache" + @buildout_dir = "#{@source_root}/buildout" REQUIRED_LOCATIONS_INI_FIELDS.each do |field| if instance_variable_get("@#{field}").nil? raise "BUG: @#{field} not set" end end @@ -122,10 +135,16 @@ def self.natively_packaged? return @natively_packaged end + # If Phusion Passenger is natively packaged, returns which packaging + # method was used. Can be 'deb' or 'rpm'. + def self.native_packaging_method + return @native_packaging_method + end + # Whether the current Phusion Passenger installation is installed # from a release package, e.g. an official gem or official tarball. # Retruns false if e.g. the gem was built by the user, or if this # install is from a git repository. def self.installed_from_release_package? @@ -138,11 +157,10 @@ return @source_root end # Generate getters for the directory types in locations.ini. getters_code = "" - @ruby_libdir = File.dirname(FILE_LOCATION) (REQUIRED_LOCATIONS_INI_FIELDS + OPTIONAL_LOCATIONS_INI_FIELDS).each do |field| getters_code << %Q{ def self.#{field} return @#{field} end @@ -178,12 +196,23 @@ def self.binaries_ca_cert_path return "#{resources_dir}/oss-binaries.phusionpassenger.com.crt" end - if !$LOAD_PATH.include?(ruby_libdir) - $LOAD_PATH.unshift(ruby_libdir) - $LOAD_PATH.uniq! + # Instead of calling `require 'phusion_passenger/foo'`, you should call + # `PhusionPassenger.require_passenger_lib 'foo'`. This is because when Phusion + # Passenger is natively packaged, it may still be run with arbitrary Ruby + # interpreters. Adding ruby_libdir to $LOAD_PATH is then dangerous because ruby_libdir + # may be the distribution's Ruby's vendor_ruby directory, which may be incompatible + # with the active Ruby interpreter. This method looks up the exact filename directly. + # + # Using this method also has two more advantages: + # + # 1. It is immune to Bundler's load path mangling code. + # 2. It is faster than plan require() because it doesn't need to + # scan the entire load path. + def self.require_passenger_lib(name) + require("#{ruby_libdir}/phusion_passenger/#{name}") end private def self.find_location_configuration_file