Module: PhusionPassenger::PlatformInfo
- Defined in:
- lib/phusion_passenger/platform_info.rb,
lib/phusion_passenger/platform_info/curl.rb,
lib/phusion_passenger/platform_info/ruby.rb,
lib/phusion_passenger/platform_info/zlib.rb,
lib/phusion_passenger/platform_info/linux.rb,
lib/phusion_passenger/platform_info/apache.rb,
lib/phusion_passenger/platform_info/compiler.rb,
lib/phusion_passenger/platform_info/operating_system.rb,
lib/phusion_passenger/platform_info/documentation_tools.rb,
lib/phusion_passenger/platform_info/binary_compatibility.rb
Overview
Users can change the detection behavior by setting the environment variable APXS2
to the correct ‘apxs’ (or ‘apxs2’) binary, as provided by Apache.
Constant Summary collapse
- GEM_HOME =
gem_home
- RUBY_ENGINE =
"ruby"
Class Method Summary collapse
-
.apache2_bindir ⇒ Object
The absolute path to the Apache 2 ‘bin’ directory, or nil if unknown.
-
.apache2_module_cflags(with_apr_flags = true) ⇒ Object
The C compiler flags that are necessary to compile an Apache module.
-
.apache2_module_ldflags ⇒ Object
Linker flags that are necessary for linking an Apache module.
-
.apache2_sbindir ⇒ Object
The absolute path to the Apache 2 ‘sbin’ directory, or nil if unknown.
-
.apache2ctl ⇒ Object
The absolute path to the ‘apachectl’ or ‘apache2ctl’ binary, or nil if not found.
-
.apr_config ⇒ Object
The absolute path to the ‘apr-config’ or ‘apr-1-config’ executable, or nil if not found.
-
.apr_config_needed_for_building_apache_modules? ⇒ Boolean
Returns whether it is necessary to use information outputted by ‘apr-config’ and ‘apu-config’ in order to compile an Apache module.
-
.apr_flags ⇒ Object
The C compiler flags that are necessary for programs that use APR.
-
.apr_libs ⇒ Object
The linker flags that are necessary for linking programs that use APR.
-
.apu_config ⇒ Object
The absolute path to the ‘apu-config’ or ‘apu-1-config’ executable, or nil if not found.
-
.apu_flags ⇒ Object
The C compiler flags that are necessary for programs that use APR-Util.
-
.apu_libs ⇒ Object
The linker flags that are necessary for linking programs that use APR-Util.
-
.apxs2 ⇒ Object
The absolute path to the ‘apxs’ or ‘apxs2’ executable, or nil if not found.
- .asciidoc ⇒ Object
- .cc ⇒ Object
- .compiler_supports_visibility_flag? ⇒ Boolean
- .compiler_supports_wno_attributes_flag? ⇒ Boolean
-
.compiler_visibility_flag_generates_warnings? ⇒ Boolean
Returns whether compiling C++ with -fvisibility=hidden might result in tons of useless warnings, like this: code.google.com/p/phusion-passenger/issues/detail?id=526 This appears to be a bug in older g++ versions: gcc.gnu.org/ml/gcc-patches/2006-07/msg00861.html Warnings should be suppressed with -Wno-attributes.
-
.cpu_architectures ⇒ Object
Returns a list of all CPU architecture names that the current machine CPU supports.
- .curl_flags ⇒ Object
- .curl_libs ⇒ Object
- .curl_supports_ssl? ⇒ Boolean
- .cxx ⇒ Object
-
.debugging_cflags ⇒ Object
C compiler flags that should be passed in order to enable debugging information.
- .env_defined?(name) ⇒ Boolean
- .export_dynamic_flags ⇒ Object
-
.find_command(name) ⇒ Object
Check whether the specified command is in $PATH, and return its absolute filename.
-
.gem_command ⇒ Object
Returns the correct ‘gem’ command for this Ruby interpreter.
- .gnu_make ⇒ Object
- .has_math_library? ⇒ Boolean
-
.httpd ⇒ Object
The absolute path to the Apache binary (that is, ‘httpd’, ‘httpd2’, ‘apache’ or ‘apache2’), or nil if not found.
-
.in_rvm? ⇒ Boolean
Returns whether the current Ruby interpreter is managed by RVM.
-
.library_extension ⇒ Object
The current platform’s shared library extension (‘so’ on most Unices).
-
.linux_distro ⇒ Object
An identifier for the current Linux distribution.
-
.linux_distro_tags ⇒ Object
Autodetects the current Linux distribution and return a number of identifier tags.
-
.locate_ruby_tool(name) ⇒ Object
Locates a Ruby tool command, e.g.
-
.os_name ⇒ Object
Returns the operating system’s name.
-
.passenger_binary_compatibility_id ⇒ Object
Returns an identifier string that describes the current platform’s binary compatibility with regard to Phusion Passenger binaries, both the Ruby extension and the C++ binaries.
-
.portability_cflags ⇒ Object
Compiler flags that should be used for compiling every C/C++ program, for portability reasons.
-
.portability_ldflags ⇒ Object
Linker flags that should be used for linking every C/C++ program, for portability reasons.
-
.rake ⇒ Object
Returns the absolute path to the Rake executable that belongs to the current Ruby interpreter.
-
.rake_command ⇒ Object
Returns the correct command string for invoking the Rake executable that belongs to the current Ruby interpreter.
-
.rspec ⇒ Object
Returns the absolute path to the RSpec runner program that belongs to the current Ruby interpreter.
-
.ruby_command ⇒ Object
Returns correct command for invoking the current Ruby interpreter.
-
.ruby_executable ⇒ Object
Returns the full path to the current Ruby interpreter’s executable file.
-
.ruby_extension_binary_compatibility_ids ⇒ Object
Returns an array of identifiers that describe the current Ruby interpreter’s extension binary compatibility.
-
.ruby_sudo_command ⇒ Object
Returns either ‘sudo’ or ‘rvmsudo’ depending on whether the current Ruby interpreter is managed by RVM.
-
.ruby_supports_fork? ⇒ Boolean
Returns whether the Ruby interpreter supports process forking.
-
.rvm_path ⇒ Object
If the current Ruby interpreter is managed by RVM, returns the directory in which RVM places its working files.
-
.rvm_ruby_string ⇒ Object
If the current Ruby interpreter is managed by RVM, returns the RVM name which identifies the current Ruby interpreter plus the currently active gemset, e.g.
-
.supports_lfence_instruction? ⇒ Boolean
Returns whether the OS’s main CPU architecture supports the x86/x86_64 lfence instruction.
-
.supports_sfence_instruction? ⇒ Boolean
Returns whether the OS’s main CPU architecture supports the x86/x86_64 sfence instruction.
- .zlib_flags ⇒ Object
- .zlib_libs ⇒ Object
Class Method Details
.apache2_bindir ⇒ Object
The absolute path to the Apache 2 ‘bin’ directory, or nil if unknown.
140 141 142 143 144 145 146 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 140 def self.apache2_bindir if apxs2.nil? return nil else return `#{apxs2} -q BINDIR 2>/dev/null`.strip end end |
.apache2_module_cflags(with_apr_flags = true) ⇒ Object
The C compiler flags that are necessary to compile an Apache module. Also includes APR and APU compiler flags if with_apr_flags is true.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 164 def self.apache2_module_cflags(with_apr_flags = true) flags = ["-fPIC"] if compiler_supports_visibility_flag? flags << "-fvisibility=hidden -DVISIBILITY_ATTRIBUTE_SUPPORTED" if compiler_visibility_flag_generates_warnings? && compiler_supports_wno_attributes_flag? flags << "-Wno-attributes" end end if with_apr_flags flags << apr_flags flags << apu_flags end if !apxs2.nil? apxs2_flags = `#{apxs2} -q CFLAGS`.strip << " -I" << `#{apxs2} -q INCLUDEDIR`.strip apxs2_flags.gsub!(/-O\d? /, '') # Remove flags not supported by GCC if RUBY_PLATFORM =~ /solaris/ # TODO: Add support for people using SunStudio # The big problem is Coolstack apxs includes a bunch of solaris -x directives. = apxs2_flags.split .reject! { |f| f =~ /^\-x/ } .reject! { |f| f =~ /^\-Xa/ } .reject! { |f| f =~ /^\-fast/ } .reject! { |f| f =~ /^\-mt/ } apxs2_flags = .join(' ') end apxs2_flags.strip! flags << apxs2_flags end if !httpd.nil? && RUBY_PLATFORM =~ /darwin/ # The default Apache install on OS X is a universal binary. # Figure out which architectures it's compiled for and do the same # thing for mod_passenger. We use the 'file' utility to do this. # # Running 'file' on the Apache executable usually outputs something # like this: # # /usr/sbin/httpd: Mach-O universal binary with 4 architectures # /usr/sbin/httpd (for architecture ppc7400): Mach-O executable ppc # /usr/sbin/httpd (for architecture ppc64): Mach-O 64-bit executable ppc64 # /usr/sbin/httpd (for architecture i386): Mach-O executable i386 # /usr/sbin/httpd (for architecture x86_64): Mach-O 64-bit executable x86_64 # # But on some machines, it may output just: # # /usr/sbin/httpd: Mach-O fat file with 4 architectures # # (http://code.google.com/p/phusion-passenger/issues/detail?id=236) output = `file "#{httpd}"`.strip if output =~ /Mach-O fat file/ && output !~ /for architecture/ architectures = ["-arch i386 -arch ppc -arch x86_64 -arch ppc64"] else architectures = [] output.split("\n").grep(/for architecture/).each do |line| line =~ /for architecture (.*?)\)/ architectures << "-arch #{$1}" end end flags << architectures.compact.join(' ') end return flags.compact.join(' ').strip end |
.apache2_module_ldflags ⇒ Object
Linker flags that are necessary for linking an Apache module. Already includes APR and APU linker flags.
231 232 233 234 235 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 231 def self.apache2_module_ldflags flags = "-fPIC #{apr_libs} #{apu_libs}" flags.strip! return flags end |
.apache2_sbindir ⇒ Object
The absolute path to the Apache 2 ‘sbin’ directory, or nil if unknown.
150 151 152 153 154 155 156 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 150 def self.apache2_sbindir if apxs2.nil? return nil else return `#{apxs2} -q SBINDIR`.strip end end |
.apache2ctl ⇒ Object
The absolute path to the ‘apachectl’ or ‘apache2ctl’ binary, or nil if not found.
60 61 62 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 60 def self.apache2ctl return find_apache2_executable('apache2ctl', 'apachectl2', 'apachectl') end |
.apr_config ⇒ Object
The absolute path to the ‘apr-config’ or ‘apr-1-config’ executable, or nil if not found.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 86 def self.apr_config if env_defined?('APR_CONFIG') return ENV['APR_CONFIG'] elsif apxs2.nil? return nil else filename = `#{apxs2} -q APR_CONFIG 2>/dev/null`.strip if filename.empty? apr_bindir = `#{apxs2} -q APR_BINDIR 2>/dev/null`.strip if apr_bindir.empty? return nil else return select_executable(apr_bindir, "apr-1-config", "apr-config") end elsif File.exist?(filename) return filename else return nil end end end |
.apr_config_needed_for_building_apache_modules? ⇒ Boolean
Returns whether it is necessary to use information outputted by ‘apr-config’ and ‘apu-config’ in order to compile an Apache module. When Apache is installed with –with-included-apr, the APR/APU headers are placed into the same directory as the Apache headers, and so ‘apr-config’ and ‘apu-config’ won’t be necessary in that case.
266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 266 def self.apr_config_needed_for_building_apache_modules? filename = File.join("/tmp/passenger-platform-check-#{Process.pid}.c") File.open(filename, "w") do |f| f.puts("#include <apr.h>") end begin return !system("(gcc #{apache2_module_cflags(false)} -c '#{filename}' -o '#{filename}.o') >/dev/null 2>/dev/null") ensure File.unlink(filename) rescue nil File.unlink("#{filename}.o") rescue nil end end |
.apr_flags ⇒ Object
The C compiler flags that are necessary for programs that use APR.
239 240 241 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 239 def self.apr_flags return determine_apr_info[0] end |
.apr_libs ⇒ Object
The linker flags that are necessary for linking programs that use APR.
244 245 246 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 244 def self.apr_libs return determine_apr_info[1] end |
.apu_config ⇒ Object
The absolute path to the ‘apu-config’ or ‘apu-1-config’ executable, or nil if not found.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 112 def self.apu_config if env_defined?('APU_CONFIG') return ENV['APU_CONFIG'] elsif apxs2.nil? return nil else filename = `#{apxs2} -q APU_CONFIG 2>/dev/null`.strip if filename.empty? apu_bindir = `#{apxs2} -q APU_BINDIR 2>/dev/null`.strip if apu_bindir.empty? return nil else return select_executable(apu_bindir, "apu-1-config", "apu-config") end elsif File.exist?(filename) return filename else return nil end end end |
.apu_flags ⇒ Object
The C compiler flags that are necessary for programs that use APR-Util.
249 250 251 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 249 def self.apu_flags return determine_apu_info[0] end |
.apu_libs ⇒ Object
The linker flags that are necessary for linking programs that use APR-Util.
254 255 256 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 254 def self.apu_libs return determine_apu_info[1] end |
.apxs2 ⇒ Object
The absolute path to the ‘apxs’ or ‘apxs2’ executable, or nil if not found.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 44 def self.apxs2 if env_defined?("APXS2") return ENV["APXS2"] end ['apxs2', 'apxs'].each do |name| command = find_command(name) if !command.nil? return command end end return nil end |
.asciidoc ⇒ Object
29 30 31 |
# File 'lib/phusion_passenger/platform_info/documentation_tools.rb', line 29 def self.asciidoc return find_command('asciidoc') || find_command('mizuho-asciidoc') end |
.cc ⇒ Object
159 160 161 |
# File 'lib/phusion_passenger/platform_info.rb', line 159 def self.cc return ENV['CC'] || "gcc" end |
.compiler_supports_visibility_flag? ⇒ Boolean
49 50 51 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 49 def self.compiler_supports_visibility_flag? return try_compile(:c, '', '-fvisibility=hidden') end |
.compiler_supports_wno_attributes_flag? ⇒ Boolean
54 55 56 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 54 def self.compiler_supports_wno_attributes_flag? return try_compile(:c, '', '-Wno-attributes') end |
.compiler_visibility_flag_generates_warnings? ⇒ Boolean
Returns whether compiling C++ with -fvisibility=hidden might result in tons of useless warnings, like this: code.google.com/p/phusion-passenger/issues/detail?id=526 This appears to be a bug in older g++ versions: gcc.gnu.org/ml/gcc-patches/2006-07/msg00861.html Warnings should be suppressed with -Wno-attributes.
65 66 67 68 69 70 71 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 65 def self.compiler_visibility_flag_generates_warnings? if RUBY_PLATFORM =~ /linux/ && `#{cxx} -v 2>&1` =~ /gcc version (.*?)/ return $1 <= "4.1.2" else return false end end |
.cpu_architectures ⇒ Object
Returns a list of all CPU architecture names that the current machine CPU supports. If there are multiple such architectures then the first item in the result denotes that OS runtime’s main/preferred architecture.
This function normalizes some names. For example x86 is always reported as “x86” regardless of whether the OS reports it as “i386” or “i686”. x86_64 is always reported as “x86_64” even if the OS reports it as “amd64”.
Please note that even if the CPU supports multiple architectures, the operating system might not. For example most x86 CPUs nowadays also support x86_64, but x86_64 Linux systems require various x86 compatibility libraries to be installed before x86 executables can be run. This function does not detect whether these compatibility libraries are installed. The only guarantee that you have is that the OS can run executables in the architecture denoted by the first item in the result.
For example, on x86_64 Linux this function can return [“x86_64”, “x86”]. This indicates that the CPU supports both of these architectures, and that the OS’s main/preferred architecture is x86_64. Most executables on the system are thus be x86_64. It is guaranteed that the OS can run x86_64 executables, but not x86 executables per se.
Another example: on MacOS X this function can return either
- “x86_64”, “x86”
-
or [“x86”, “x86_64”]. The former result indicates
OS X 10.6 (Snow Leopard) and beyond because starting from that version everything is 64-bit by default. The latter result indicates an OS X version older than 10.6.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/phusion_passenger/platform_info/operating_system.rb', line 77 def self.cpu_architectures if os_name == "macosx" arch = `uname -p`.strip if arch == "i386" # Macs have been x86 since around 2007. I think all of them come with # a recent enough Intel CPU that supports both x86 and x86_64, and I # think every OS X version has both the x86 and x86_64 runtime installed. major, minor, *rest = `sw_vers -productVersion`.strip.split(".") major = major.to_i minor = minor.to_i if major >= 10 || (major == 10 && minor >= 6) # Since Snow Leopard x86_64 is the default. ["x86_64", "x86"] else # Before Snow Leopard x86 was the default. ["x86", "x86_64"] end else arch end else arch = `uname -p`.strip # On some systems 'uname -p' returns something like # 'Intel(R) Pentium(R) M processor 1400MHz'. if arch == "unknown" || arch =~ / / arch = `uname -m`.strip end if arch =~ /^i.86$/ arch = "x86" elsif arch == "amd64" arch = "x86_64" end if arch == "x86" # Most x86 operating systems nowadays are probably running on # a CPU that supports both x86 and x86_64, but we're not gonna # go through the trouble of checking that. The main architecture # is what we usually care about. ["x86"] elsif arch == "x86_64" # I don't think there's a single x86_64 CPU out there # that doesn't support x86 as well. ["x86_64", "x86"] else [arch] end end end |
.curl_flags ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/phusion_passenger/platform_info/curl.rb', line 29 def self.curl_flags result = `(curl-config --cflags) 2>/dev/null`.strip if result.empty? return nil else version = `curl-config --vernum`.strip if version >= '070c01' # Curl >= 7.12.1 supports curl_easy_reset() result << " -DHAS_CURL_EASY_RESET" end return result end end |
.curl_libs ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/phusion_passenger/platform_info/curl.rb', line 44 def self.curl_libs result = `(curl-config --libs) 2>/dev/null`.strip if result.empty? return nil else return result end end |
.curl_supports_ssl? ⇒ Boolean
54 55 56 57 |
# File 'lib/phusion_passenger/platform_info/curl.rb', line 54 def self.curl_supports_ssl? features = `(curl-config --feature) 2>/dev/null` return features =~ /SSL/ end |
.cxx ⇒ Object
163 164 165 |
# File 'lib/phusion_passenger/platform_info.rb', line 163 def self.cxx return ENV['CXX'] || "g++" end |
.debugging_cflags ⇒ Object
C compiler flags that should be passed in order to enable debugging information.
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 163 def self.debugging_cflags if RUBY_PLATFORM =~ /openbsd/ # According to OpenBSD's pthreads man page, pthreads do not work # correctly when an app is compiled with -g. It recommends using # -ggdb instead. return '-ggdb' else return '-g' end end |
.env_defined?(name) ⇒ Boolean
155 156 157 |
# File 'lib/phusion_passenger/platform_info.rb', line 155 def self.env_defined?(name) return !ENV[name].nil? && !ENV[name].empty? end |
.export_dynamic_flags ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 174 def self.export_dynamic_flags if RUBY_PLATFORM =~ /linux/ return '-rdynamic' else return nil end end |
.find_command(name) ⇒ Object
Check whether the specified command is in $PATH, and return its absolute filename. Returns nil if the command is not found.
This function exists because system(‘which’) doesn’t always behave correctly, for some weird reason.
145 146 147 148 149 150 151 152 153 |
# File 'lib/phusion_passenger/platform_info.rb', line 145 def self.find_command(name) ENV['PATH'].split(File::PATH_SEPARATOR).detect do |directory| path = File.join(directory, name.to_s) if File.executable?(path) return path end end return nil end |
.gem_command ⇒ Object
Returns the correct ‘gem’ command for this Ruby interpreter.
110 111 112 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 110 def self.gem_command return locate_ruby_tool('gem') end |
.gnu_make ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 30 def self.gnu_make gmake = find_command('gmake') if !gmake gmake = find_command('make') if gmake if `#{gmake} --version 2>&1` =~ /GNU/ return gmake else return nil end else return nil end else return gmake end end |
.has_math_library? ⇒ Boolean
74 75 76 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 74 def self.has_math_library? return try_link(:c, "int main() { return 0; }\n", '-lmath') end |
.httpd ⇒ Object
The absolute path to the Apache binary (that is, ‘httpd’, ‘httpd2’, ‘apache’ or ‘apache2’), or nil if not found.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/phusion_passenger/platform_info/apache.rb', line 67 def self.httpd if env_defined?('HTTPD') return ENV['HTTPD'] elsif apxs2.nil? ["apache2", "httpd2", "apache", "httpd"].each do |name| command = find_command(name) if !command.nil? return command end end return nil else return find_apache2_executable(`#{apxs2} -q TARGET`.strip) end end |
.in_rvm? ⇒ Boolean
Returns whether the current Ruby interpreter is managed by RVM.
154 155 156 157 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 154 def self.in_rvm? bindir = Config::CONFIG['bindir'] return bindir.include?('/.rvm/') || bindir.include?('/rvm/') end |
.library_extension ⇒ Object
The current platform’s shared library extension (‘so’ on most Unices).
42 43 44 45 46 47 48 |
# File 'lib/phusion_passenger/platform_info/operating_system.rb', line 42 def self.library_extension if RUBY_PLATFORM =~ /darwin/ return "bundle" else return "so" end end |
.linux_distro ⇒ Object
An identifier for the current Linux distribution. nil if the operating system is not Linux.
30 31 32 33 34 35 36 37 |
# File 'lib/phusion_passenger/platform_info/linux.rb', line 30 def self.linux_distro = if return .first else return nil end end |
.linux_distro_tags ⇒ Object
Autodetects the current Linux distribution and return a number of identifier tags. The first tag identifies the distribution while the other tags indicate which distributions it is likely compatible with. Returns nil if the operating system is not Linux.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/phusion_passenger/platform_info/linux.rb', line 43 def self. if RUBY_PLATFORM !~ /linux/ return nil end lsb_release = read_file("/etc/lsb-release") if lsb_release =~ /Ubuntu/ return [:ubuntu, :debian] elsif File.exist?("/etc/debian_version") return [:debian] elsif File.exist?("/etc/redhat-release") redhat_release = read_file("/etc/redhat-release") if redhat_release =~ /CentOS/ return [:centos, :redhat] elsif redhat_release =~ /Fedora/ return [:fedora, :redhat] elsif redhat_release =~ /Mandriva/ return [:mandriva, :redhat] else # On official RHEL distros, the content is in the form of # "Red Hat Enterprise Linux Server release 5.1 (Tikanga)" return [:rhel, :redhat] end elsif File.exist?("/etc/suse-release") return [:suse] elsif File.exist?("/etc/gentoo-release") return [:gentoo] else return [:unknown] end # TODO: Slackware end |
.locate_ruby_tool(name) ⇒ Object
Locates a Ruby tool command, e.g. ‘gem’, ‘rake’, ‘bundle’, etc. Instead of naively looking in $PATH, this function uses a variety of search heuristics to find the command that’s really associated with the current Ruby interpreter. It should never locate a command that’s actually associated with a different Ruby interpreter. Returns nil when nothing’s found.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 246 def self.locate_ruby_tool(name) result = locate_ruby_tool_by_basename(name) if !result exeext = Config::CONFIG['EXEEXT'] exeext = nil if exeext.empty? if exeext result = locate_ruby_tool_by_basename("#{name}#{exeext}") end if !result result = locate_ruby_tool_by_basename(transform_according_to_ruby_exec_format(name)) end if !result && exeext result = locate_ruby_tool_by_basename(transform_according_to_ruby_exec_format(name) + exeext) end end return result end |
.os_name ⇒ Object
Returns the operating system’s name. This name is in lowercase and contains no spaces, and thus is suitable to be used in some kind of ID. E.g. “linux”, “macosx”.
32 33 34 35 36 37 38 |
# File 'lib/phusion_passenger/platform_info/operating_system.rb', line 32 def self.os_name if Config::CONFIG['target_os'] =~ /darwin/ && (sw_vers = find_command('sw_vers')) return "macosx" else return RUBY_PLATFORM.sub(/.*?-/, '') end end |
.passenger_binary_compatibility_id ⇒ Object
Returns an identifier string that describes the current platform’s binary compatibility with regard to Phusion Passenger binaries, both the Ruby extension and the C++ binaries. Two systems with the same binary compatibility identifiers are able to run the same Phusion Passenger binaries.
The the string depends on the following factors:
-
The Ruby extension binary compatibility identifiers.
-
The operating system name.
-
Operating system runtime identifier. This may include the kernel version, libc version, C++ ABI version, etc. Everything that is of interest for binary compatibility with Phusion Passenger’s C++ components.
-
Operating system default runtime architecture. This is not the same as the CPU architecture; some CPUs support multiple architectures, e.g. Intel Core 2 Duo supports x86 and x86_64. Some operating systems actually support multiple runtime architectures: a lot of x86_64 Linux distributions also include 32-bit runtimes, and OS X Snow Leopard is x86_64 by default but all system libraries also support x86. This component identifies the architecture that is used when compiling a binary with the system’s C++ compiler with its default options.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/phusion_passenger/platform_info/binary_compatibility.rb', line 103 def self.passenger_binary_compatibility_id ruby_engine, ruby_ext_version, ruby_arch, os_name = ruby_extension_binary_compatibility_ids if os_name == "macosx" # RUBY_PLATFORM gives us the kernel version, but we want # the OS X version. os_version_string = `sw_vers -productVersion`.strip # sw_vers returns something like "10.6.2". We're only # interested in the first two digits (MAJOR.MINOR) since # tiny releases tend to be binary compatible with each # other. components = os_version_string.split(".") os_version = "#{components[0]}.#{components[1]}" os_runtime = os_version os_arch = cpu_architectures[0] if os_version >= "10.5" && os_arch =~ /^i.86$/ # On Snow Leopard, 'uname -m' returns i386 but # we *know* that everything is x86_64 by default. os_arch = "x86_64" end else os_arch = cpu_architectures[0] cpp = find_command('cpp') if cpp macros = `#{cpp} -dM < /dev/null` # Can be something like "4.3.2" # or "4.2.1 20070719 (FreeBSD)" macros =~ /__VERSION__ "(.+)"/ compiler_version = $1 compiler_version.gsub!(/ .*/, '') if compiler_version macros =~ /__GXX_ABI_VERSION (.+)$/ cxx_abi_version = $1 else compiler_version = nil cxx_abi_version = nil end if compiler_version && cxx_abi_version os_runtime = "gcc#{compiler_version}-#{cxx_abi_version}" else os_runtime = [compiler_version, cxx_abi_version].compact.join("-") if os_runtime.empty? os_runtime = `uname -r`.strip end end end if ruby_engine == "jruby" # For JRuby it's kinda useless to prepend "java" as extension # architecture because JRuby doesn't allow any other extension # architecture. identifier = "" else identifier = "#{ruby_arch}-" end identifier << "#{ruby_engine}#{ruby_ext_version}-" # If the extension architecture is the same as the OS architecture # then there's no need to specify it twice. if ruby_arch != os_arch identifier << "#{os_arch}-" end identifier << "#{os_name}-#{os_runtime}" return identifier end |
.portability_cflags ⇒ Object
Compiler flags that should be used for compiling every C/C++ program, for portability reasons. These flags should be specified as last when invoking the compiler.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 82 def self.portability_cflags flags = ["-D_REENTRANT -I/usr/local/include"] # Google SparseHash flags. # Figure out header for hash function object and its namespace. # Based on stl_hash.m4 and stl_hash_fun.m4 in the Google SparseHash sources. hash_namespace = nil ok = false ['__gnu_cxx', '', 'std', 'stdext'].each do |namespace| ['ext/hash_map', 'hash_map'].each do |hash_map_header| ok = try_compile(:cxx, %Q{ #include <#{hash_map_header}> int main() { #{namespace}::hash_map<int, int> m; return 0; } }) if ok hash_namespace = namespace flags << "-DHASH_NAMESPACE=\"#{namespace}\"" end end break if ok end ['ext/hash_fun.h', 'functional', 'tr1/functional', 'ext/stl_hash_fun.h', 'hash_fun.h', 'stl_hash_fun.h', 'stl/_hash_fun.h'].each do |hash_function_header| ok = try_compile(:cxx, %Q{ #include <#{hash_function_header}> int main() { #{hash_namespace}::hash<int>()(5); return 0; } }) if ok flags << "-DHASH_FUN_H=\"<#{hash_function_header}>\"" break end end if RUBY_PLATFORM =~ /solaris/ flags << '-pthreads' flags << '-D_XOPEN_SOURCE=500 -D_XPG4_2 -D__EXTENSIONS__ -D__SOLARIS__ -D_FILE_OFFSET_BITS=64' flags << '-DBOOST_HAS_STDINT_H' unless RUBY_PLATFORM =~ /solaris2.9/ flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if RUBY_PLATFORM =~ /solaris2.9/ flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/ elsif RUBY_PLATFORM =~ /openbsd/ flags << '-DBOOST_HAS_STDINT_H -D_GLIBCPP__PTHREADS' elsif RUBY_PLATFORM =~ /aix/ flags << '-DOXT_DISABLE_BACKTRACES' elsif RUBY_PLATFORM =~ /(sparc-linux|arm-linux|^arm.*-linux|sh4-linux)/ # http://code.google.com/p/phusion-passenger/issues/detail?id=200 # http://groups.google.com/group/phusion-passenger/t/6b904a962ee28e5c # http://groups.google.com/group/phusion-passenger/browse_thread/thread/aad4bd9d8d200561 flags << '-DBOOST_SP_USE_PTHREADS' end flags << '-DHAS_SFENCE' if supports_sfence_instruction? flags << '-DHAS_LFENCE' if supports_lfence_instruction? return flags.compact.join(" ").strip end |
.portability_ldflags ⇒ Object
Linker flags that should be used for linking every C/C++ program, for portability reasons. These flags should be specified as last when invoking the linker.
151 152 153 154 155 156 157 158 159 |
# File 'lib/phusion_passenger/platform_info/compiler.rb', line 151 def self.portability_ldflags if RUBY_PLATFORM =~ /solaris/ result = '-lxnet -lrt -lsocket -lnsl -lpthread' else result = '-lpthread' end flags << ' -lmath' if has_math_library? return result end |
.rake ⇒ Object
Returns the absolute path to the Rake executable that belongs to the current Ruby interpreter. Returns nil if it doesn’t exist.
The return value may not be the actual correct invocation for Rake. Use rake_command for that.
121 122 123 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 121 def self.rake return locate_ruby_tool('rake') end |
.rake_command ⇒ Object
Returns the correct command string for invoking the Rake executable that belongs to the current Ruby interpreter. Returns nil if Rake is not found.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 129 def self.rake_command filename = rake # If the Rake executable is a Ruby program then we need to run # it in the correct Ruby interpreter just in case Rake doesn't # have the correct shebang line; we don't want a totally different # Ruby than the current one to be invoked. if filename && is_ruby_program?(filename) return "#{ruby_command} #{filename}" else # If it's not a Ruby program then it's probably a wrapper # script as is the case with e.g. RVM (~/.rvm/wrappers). return filename end end |
.rspec ⇒ Object
Returns the absolute path to the RSpec runner program that belongs to the current Ruby interpreter. Returns nil if it doesn’t exist.
148 149 150 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 148 def self.rspec return locate_ruby_tool('spec') end |
.ruby_command ⇒ Object
Returns correct command for invoking the current Ruby interpreter. In case of RVM this function will return the path to the RVM wrapper script that executes the current Ruby interpreter in the currently active gem set.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 48 def self.ruby_command if in_rvm? name = rvm_ruby_string dir = rvm_path if name && dir filename = "#{dir}/wrappers/#{name}/ruby" if File.exist?(filename) contents = File.open(filename, 'rb') do |f| f.read end # Old wrapper scripts reference $HOME which causes # things to blow up when run by a different user. if contents.include?("$HOME") filename = nil end else filename = nil end if filename return filename else STDERR.puts "Your RVM wrapper scripts are too old. Please " + "update them first by running 'rvm update --head && " + "rvm reload && rvm repair all'." exit 1 end else # Something's wrong with the user's RVM installation. # Raise an error so that the user knows this instead of # having things fail randomly later on. # 'name' is guaranteed to be non-nil because rvm_ruby_string # already raises an exception on error. STDERR.puts "Your RVM installation appears to be broken: the RVM " + "path cannot be found. Please fix your RVM installation " + "or contact the RVM developers for support." exit 1 end else return ruby_executable end end |
.ruby_executable ⇒ Object
Returns the full path to the current Ruby interpreter’s executable file. This might not be the actual correct command to use for invoking the Ruby interpreter; use ruby_command instead.
94 95 96 97 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 94 def self.ruby_executable @@ruby_executable ||= Config::CONFIG['bindir'] + '/' + Config::CONFIG['RUBY_INSTALL_NAME'] + Config::CONFIG['EXEEXT'] end |
.ruby_extension_binary_compatibility_ids ⇒ Object
Returns an array of identifiers that describe the current Ruby interpreter’s extension binary compatibility. A Ruby extension compiled for a certain Ruby interpreter can also be loaded on a different Ruby interpreter with the same binary compatibility identifiers.
The identifiers depend on the following factors:
-
Ruby engine name.
-
Ruby extension version. This is not the same as the Ruby language version, which identifies language-level compatibility. This is rather about binary compatibility of extensions. MRI seems to break source compatibility between tiny releases, though patchlevel releases tend to be source and binary compatible.
-
Ruby extension architecture. This is not necessarily the same as the operating system runtime architecture or the CPU architecture. For example, in case of JRuby, the extension architecture is just “java” because all extensions target the Java platform; the architecture the JVM was compiled for has no effect on compatibility. On systems with universal binaries support there may be multiple architectures. In this case the architecture is “universal” because extensions must be able to support all of the Ruby executable’s architectures.
-
The operating system for which the Ruby interpreter was compiled.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/phusion_passenger/platform_info/binary_compatibility.rb', line 59 def self.ruby_extension_binary_compatibility_ids ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby" ruby_ext_version = RUBY_VERSION if RUBY_PLATFORM =~ /darwin/ if RUBY_PLATFORM =~ /universal/ ruby_arch = "universal" else # Something like: # "/opt/ruby-enterprise/bin/ruby: Mach-O 64-bit executable x86_64" ruby_arch = `file -L "#{ruby_executable}"`.strip ruby_arch.sub!(/.* /, '') end elsif RUBY_PLATFORM == "java" ruby_arch = "java" else ruby_arch = cpu_architectures[0] end return [ruby_engine, ruby_ext_version, ruby_arch, os_name] end |
.ruby_sudo_command ⇒ Object
Returns either ‘sudo’ or ‘rvmsudo’ depending on whether the current Ruby interpreter is managed by RVM.
232 233 234 235 236 237 238 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 232 def self.ruby_sudo_command if in_rvm? return "rvmsudo" else return "sudo" end end |
.ruby_supports_fork? ⇒ Boolean
Returns whether the Ruby interpreter supports process forking.
100 101 102 103 104 105 106 107 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 100 def self.ruby_supports_fork? # MRI >= 1.9.2's respond_to? returns false for methods # that are not implemented. return Process.respond_to?(:fork) && RUBY_ENGINE != "jruby" && RUBY_ENGINE != "macruby" && Config::CONFIG['target_os'] !~ /mswin|windows|mingw/ end |
.rvm_path ⇒ Object
If the current Ruby interpreter is managed by RVM, returns the directory in which RVM places its working files. Otherwise returns nil.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 162 def self.rvm_path if in_rvm? [ENV['rvm_path'], "~/.rvm", "/usr/local/rvm"].each do |path| next if path.nil? path = File.(path) return path if File.directory?(path) end # Failure to locate the RVM path is probably caused by the # user customizing $rvm_path. Older RVM versions don't # export $rvm_path, making us unable to detect its value. STDERR.puts "Unable to locate the RVM path. Your RVM installation " + "is probably too old. Please update it with " + "'rvm update --head && rvm reload && rvm repair all'." exit 1 else return nil end end |
.rvm_ruby_string ⇒ Object
If the current Ruby interpreter is managed by RVM, returns the RVM name which identifies the current Ruby interpreter plus the currently active gemset, e.g. something like this: “ruby-1.9.2-p0@mygemset”
Returns nil otherwise.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/phusion_passenger/platform_info/ruby.rb', line 188 def self.rvm_ruby_string if in_rvm? # RVM used to export the necessary information through # environment variables, but doesn't always do that anymore # in the latest versions in order to fight env var pollution. # Scanning $LOAD_PATH seems to be the only way to obtain # the information. # Getting the RVM name of the Ruby interpreter ("ruby-1.9.2") # isn't so hard, we can extract it from the #ruby_executable # string. Getting the gemset name is a bit harder, so let's # try various strategies... # $GEM_HOME usually contains the gem set name. if GEM_HOME && GEM_HOME.include?("rvm/gems/") return File.basename(GEM_HOME) end # User somehow managed to nuke $GEM_HOME. Extract info # from $LOAD_PATH. matching_path = $LOAD_PATH.find_all do |item| item.include?("rvm/gems/") end if matching_path subpath = matching_path.to_s.gsub(/^.*rvm\/gems\//, '') result = subpath.split('/').first return result if result end # On Ruby 1.9, $LOAD_PATH does not contain any gem paths until # at least one gem has been required so the above can fail. # We're out of options now, we can't detect the gem set. # Raise an exception so that the user knows what's going on # instead of having things fail in obscure ways later. STDERR.puts "Unable to autodetect the currently active RVM gem " + "set name. Please contact this program's author for support." exit 1 end return nil end |
.supports_lfence_instruction? ⇒ Boolean
Returns whether the OS’s main CPU architecture supports the x86/x86_64 lfence instruction.
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/phusion_passenger/platform_info/operating_system.rb', line 144 def self.supports_lfence_instruction? arch = cpu_architectures[0] return arch == "x86_64" || (arch == "x86" && try_compile_and_run(:c, %Q{ int main() { __asm__ __volatile__ ("lfence" ::: "memory"); return 0; } })) end |
.supports_sfence_instruction? ⇒ Boolean
Returns whether the OS’s main CPU architecture supports the x86/x86_64 sfence instruction.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/phusion_passenger/platform_info/operating_system.rb', line 129 def self.supports_sfence_instruction? arch = cpu_architectures[0] return arch == "x86_64" || (arch == "x86" && try_compile_and_run(:c, %Q{ int main() { __asm__ __volatile__ ("sfence" ::: "memory"); return 0; } })) end |
.zlib_flags ⇒ Object
29 30 31 |
# File 'lib/phusion_passenger/platform_info/zlib.rb', line 29 def self.zlib_flags return nil end |
.zlib_libs ⇒ Object
33 34 35 |
# File 'lib/phusion_passenger/platform_info/zlib.rb', line 33 def self.zlib_libs return '-lz' end |