class PhusionPassenger::NativeSupportLoader

Public Instance Methods

start() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 31
def start
        require 'phusion_passenger'
        load_from_source_dir ||
        load_from_load_path ||
        load_from_home ||
        compile_and_load
end
supported?() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 27
def supported?
        return !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx"
end

Private Instance Methods

archdir() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 40
def archdir
        @archdir ||= 'native'
end
compile(target_dirs) click to toggle source
# File lib/phusion_passenger/native_support.rb, line 128
def compile(target_dirs)
        result = nil
        target_dirs.each_with_index do |target_dir, i|
                begin
                        mkdir(target_dir)
                        File.open("#{target_dir}/.permission_test", "w").close
                        File.unlink("#{target_dir}/.permission_test")
                        STDERR.puts "# cd #{target_dir}"
                        Dir.chdir(target_dir) do
                                sh("#{PlatformInfo.ruby_command} '#{extconf_rb}'")
                                sh("make")
                        end
                        result = target_dir
                        break
                rescue Errno::EACCES
                        # If we encountered a permission error, then try
                        # the next target directory. If we get a permission
                        # error on the last one too then propagate the
                        # exception.
                        if i == target_dirs.size - 1
                                raise
                        else
                                STDERR.puts "Encountered permission error, " +
                                        "trying a different directory..."
                                STDERR.puts "-------------------------------"
                        end
                end
        end
        return result
end
compile_and_load() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 95
def compile_and_load
        STDERR.puts "*** Phusion Passenger: no #{library_name} found for " +
                "the current Ruby interpreter. Compiling one..."
        
        require 'fileutils'
        require 'phusion_passenger/platform_info/ruby'
        
        target_dirs = []
        if defined?(NATIVE_SUPPORT_DIR)
                target_dirs << "#{NATIVE_SUPPORT_DIR}/#{archdir}"
        end
        target_dirs << "#{home}/#{LOCAL_DIR}/native_support/#{VERSION_STRING}/#{archdir}"
        
        target_dir = compile(target_dirs)
        require "#{target_dir}/#{library_name}"
end
extconf_rb() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 62
def extconf_rb
        File.join(SOURCE_ROOT, "ext", "ruby", "extconf.rb")
end
home() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 51
def home
        @home ||= begin
                require 'etc' if !defined?(Etc)
                home = Etc.getpwuid(Process.uid).dir
        end
end
libext() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 44
def libext
        @libext ||= begin
                require 'phusion_passenger/platform_info/operating_system'
                PlatformInfo.library_extension
        end
end
library_name() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 58
def library_name
        return "passenger_native_support.#{libext}"
end
load_from_home() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 86
def load_from_home
        begin
                require "#{home}/#{LOCAL_DIR}/native_support/#{VERSION_STRING}/#{archdir}/#{library_name}"
                return true
        rescue LoadError
                return false
        end
end
load_from_load_path() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 79
def load_from_load_path
        require 'passenger_native_support'
        return true
rescue LoadError
        return false
end
load_from_source_dir() click to toggle source
# File lib/phusion_passenger/native_support.rb, line 66
def load_from_source_dir
        if defined?(NATIVE_SUPPORT_DIR)
                begin
                        require "#{NATIVE_SUPPORT_DIR}/#{archdir}/#{library_name}"
                        return true
                rescue LoadError
                        return false
                end
        else
                return false
        end
end
mkdir(dir) click to toggle source
# File lib/phusion_passenger/native_support.rb, line 112
def mkdir(dir)
        begin
                STDERR.puts "# mkdir -p #{dir}"
                FileUtils.mkdir_p(dir)
        rescue Errno::EEXIST
        end
end
sh(*args) click to toggle source
# File lib/phusion_passenger/native_support.rb, line 120
def sh(*args)
        command_string = args.join(' ')
        STDERR.puts "# #{command_string}"
        if !system(*args)
                raise "Could not compile #{library_name} ('#{command_string}' failed)"
        end
end