Module PlatformInfo |
In: | lib/phusion_passenger/platform_info.rb

This module autodetects various platform-specific information, and provides that information through constants.

Users can change the detection behavior by setting the environment variable `APXS2` to the correct ‘apxs’ (or ‘apxs2’) binary, as provided by Apache.

Methods

- apache2_bindir
- apache2_module_cflags
- apache2_module_ldflags
- apache2_sbindir
- apache2ctl
- apr_config
- apr_config_needed_for_building_apache_modules?
- apr_flags
- apr_libs
- apu_config
- apu_flags
- apu_libs
- apxs2
- debugging_cflags
- find_command
- httpd
- library_extension
- linux_distro
- portability_cflags
- portability_ldflags
- rake
- rspec

Constants

RUBY | = | Config::CONFIG['bindir'] + '/' + Config::CONFIG['RUBY_INSTALL_NAME'] + Config::CONFIG['EXEEXT']
| The absolute path to the current Ruby interpreter.
GEM | = | locate_ruby_executable('gem')
| The correct ‘gem’ command for this Ruby interpreter.

Public Class methods
apache2_bindir()

The absolute path to the Apache 2 ‘bin’ directory.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 307
    307:         def self.apache2_bindir
    308:                 if apxs2.nil?
    309:                         return nil
    310:                 else
    311:                         return `#{apxs2} -q BINDIR 2>/dev/null`.strip
    312:                 end
    313:         end

apache2_module_cflags(with_apr_flags = true)

The C compiler flags that are necessary to compile an Apache module. Includes portability_cflags.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 378
    378:         def self.apache2_module_cflags(with_apr_flags = true)
    379:                 flags = ["-fPIC"]
    380:                 if with_apr_flags
    381:                         flags << apr_flags
    382:                         flags << apu_flags
    383:                 end
    384:                 if !apxs2.nil?
    385:                         apxs2_flags = `#{apxs2} -q CFLAGS`.strip << " -I" << `#{apxs2} -q INCLUDEDIR`.strip
    386:                         apxs2_flags.gsub!(/-O\d? /, '')
    387:
    388:                         # Remove flags not supported by GCC
    389:                         if RUBY_PLATFORM =~ /solaris/ # TODO: Add support for people using SunStudio
    390:                                 # The big problem is Coolstack apxs includes a bunch of solaris -x directives.
    391:                                 options = apxs2_flags.split
    392:                                 options.reject! { |f| f =~ /^\-x/ }
    393:                                 options.reject! { |f| f =~ /^\-Xa/ }
    394:                                 apxs2_flags = options.join(' ')
    395:                         end
    396:
    397:                         apxs2_flags.strip!
    398:                         flags << apxs2_flags
    399:                 end
    400:                 if !httpd.nil? && RUBY_PLATFORM =~ /darwin/
    401:                         # Add possible universal binary flags.
    402:                         architectures = []
    403:                         `file "#{httpd}"`.split("\n").grep(/for architecture/).each do |line|
    404:                                 line =~ /for architecture (.*?)\)/
    405:                                 architectures << "-arch #{$1}"
    406:                         end
    407:                         flags << architectures.join(' ')
    408:                 end
    409:                 flags << portability_cflags
    410:                 return flags.compact.join(' ').strip
    411:         end

apache2_module_ldflags()

Linker flags that are necessary for linking an Apache module. Includes portability_ldflags

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 416
    416:         def self.apache2_module_ldflags
    417:                 flags = "-fPIC #{apr_libs} #{apu_libs} #{portability_ldflags}"
    418:                 flags.strip!
    419:                 return flags
    420:         end

apache2_sbindir()

The absolute path to the Apache 2 ‘sbin’ directory.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 317
    317:         def self.apache2_sbindir
    318:                 if apxs2.nil?
    319:                         return nil
    320:                 else
    321:                         return `#{apxs2} -q SBINDIR`.strip
    322:                 end
    323:         end

apache2ctl()

The absolute path to the ‘apachectl’ or ‘apache2ctl’ binary.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 229
    229:         def self.apache2ctl
    230:                 return find_apache2_executable('apache2ctl', 'apachectl2', 'apachectl')
    231:         end

apr_config()

The absolute path to the ‘apr-config’ or ‘apr-1-config’ executable.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 253
    253:         def self.apr_config
    254:                 if env_defined?('APR_CONFIG')
    255:                         return ENV['APR_CONFIG']
    256:                 elsif apxs2.nil?
    257:                         return nil
    258:                 else
    259:                         filename = `#{apxs2} -q APR_CONFIG 2>/dev/null`.strip
    260:                         if filename.empty?
    261:                                 apr_bindir = `#{apxs2} -q APR_BINDIR 2>/dev/null`.strip
    262:                                 if apr_bindir.empty?
    263:                                         return nil
    264:                                 else
    265:                                         return select_executable(apr_bindir,
    266:                                                 "apr-1-config", "apr-config")
    267:                                 end
    268:                         elsif File.exist?(filename)
    269:                                 return filename
    270:                         else
    271:                                 return nil
    272:                         end
    273:                 end
    274:         end

apr_config_needed_for_building_apache_modules?()

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.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 452
    452:         def self.apr_config_needed_for_building_apache_modules?
    453:                 filename = File.join("/tmp/passenger-platform-check-#{Process.pid}.c")
    454:                 File.open(filename, "w") do |f|
    455:                         f.puts("#include <apr.h>")
    456:                 end
    457:                 begin
    458:                         return !system("(gcc #{apache2_module_cflags(false)} -c '#{filename}' -o '#{filename}.o') >/dev/null 2>/dev/null")
    459:                 ensure
    460:                         File.unlink(filename) rescue nil
    461:                         File.unlink("#{filename}.o") rescue nil
    462:                 end
    463:         end

apr_flags()

The C compiler flags that are necessary for programs that use APR.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 424
    424:         def self.apr_flags
    425:                 return determine_apr_info[0]
    426:         end

apr_libs()

The linker flags that are necessary for linking programs that use APR.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 429
    429:         def self.apr_libs
    430:                 return determine_apr_info[1]
    431:         end

apu_config()

The absolute path to the ‘apu-config’ or ‘apu-1-config’ executable.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 278
    278:         def self.apu_config
    279:                 if env_defined?('APU_CONFIG')
    280:                         return ENV['APU_CONFIG']
    281:                 elsif apxs2.nil?
    282:                         return nil
    283:                 else
    284:                         filename = `#{apxs2} -q APU_CONFIG 2>/dev/null`.strip
    285:                         if filename.empty?
    286:                                 apu_bindir = `#{apxs2} -q APU_BINDIR 2>/dev/null`.strip
    287:                                 if apu_bindir.empty?
    288:                                         return nil
    289:                                 else
    290:                                         return select_executable(apu_bindir,
    291:                                                 "apu-1-config", "apu-config")
    292:                                 end
    293:                         elsif File.exist?(filename)
    294:                                 return filename
    295:                         else
    296:                                 return nil
    297:                         end
    298:                 end
    299:         end

apu_flags()

The C compiler flags that are necessary for programs that use APR-Util.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 434
    434:         def self.apu_flags
    435:                 return determine_apu_info[0]
    436:         end

apu_libs()

The linker flags that are necessary for linking programs that use APR-Util.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 439
    439:         def self.apu_libs
    440:                 return determine_apu_info[1]
    441:         end

apxs2()

The absolute path to the ‘apxs’ or ‘apxs2’ executable, or nil if not found.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 214
    214:         def self.apxs2
    215:                 if env_defined?("APXS2")
    216:                         return ENV["APXS2"]
    217:                 end
    218:                 ['apxs2', 'apxs'].each do |name|
    219:                         command = find_command(name)
    220:                         if !command.nil?
    221:                                 return command
    222:                         end
    223:                 end
    224:                 return nil
    225:         end

debugging_cflags()

C compiler flags that should be passed in order to enable debugging information.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 365
    365:         def self.debugging_cflags
    366:                 if RUBY_PLATFORM =~ /openbsd/
    367:                         # According to OpenBSD's pthreads man page, pthreads do not work
    368:                         # correctly when an app is compiled with -g. It recommends using
    369:                         # -ggdb instead.
    370:                         return '-ggdb'
    371:                 else
    372:                         return '-g'
    373:                 end
    374:         end

find_command(name)

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.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 183
    183:         def self.find_command(name)
    184:                 ENV['PATH'].split(File::PATH_SEPARATOR).detect do |directory|
    185:                         path = File.join(directory, name.to_s)
    186:                         if File.executable?(path)
    187:                                 return path
    188:                         end
    189:                 end
    190:                 return nil
    191:         end

httpd()

The absolute path to the Apache binary (that is, ‘httpd’, ‘httpd2’, ‘apache’ or ‘apache2’).

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 235
    235:         def self.httpd
    236:                 if env_defined?('HTTPD')
    237:                         return ENV['HTTPD']
    238:                 elsif apxs2.nil?
    239:                         ["apache2", "httpd2", "apache", "httpd"].each do |name|
    240:                                 command = find_command(name)
    241:                                 if !command.nil?
    242:                                         return command
    243:                                 end
    244:                         end
    245:                         return nil
    246:                 else
    247:                         return find_apache2_executable(`#{apxs2} -q TARGET`.strip)
    248:                 end
    249:         end

library_extension()

The current platform‘s shared library extension (‘so’ on most Unices).

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 467
    467:         def self.library_extension
    468:                 if RUBY_PLATFORM =~ /darwin/
    469:                         return "bundle"
    470:                 else
    471:                         return "so"
    472:                 end
    473:         end

linux_distro()

An identifier for the current Linux distribution. nil if the operating system is not Linux.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 476
    476:         def self.linux_distro
    477:                 if RUBY_PLATFORM !~ /linux/
    478:                         return nil
    479:                 end
    480:                 lsb_release = read_file("/etc/lsb-release")
    481:                 if lsb_release =~ /Ubuntu/
    482:                         return :ubuntu
    483:                 elsif File.exist?("/etc/debian_version")
    484:                         return :debian
    485:                 elsif File.exist?("/etc/redhat-release")
    486:                         redhat_release = read_file("/etc/redhat-release")
    487:                         if redhat_release =~ /CentOS/
    488:                                 return :centos
    489:                         elsif redhat_release =~ /Fedora/  # is this correct?
    490:                                 return :fedora
    491:                         else
    492:                                 # On official RHEL distros, the content is in the form of
    493:                                 # "Red Hat Enterprise Linux Server release 5.1 (Tikanga)"
    494:                                 return :rhel
    495:                         end
    496:                 elsif File.exist?("/etc/suse-release")
    497:                         return :suse
    498:                 elsif File.exist?("/etc/gentoo-release")
    499:                         return :gentoo
    500:                 else
    501:                         return :unknown
    502:                 end
    503:                 # TODO: Slackware, Mandrake/Mandriva
    504:         end

portability_cflags()

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.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 333
    333:         def self.portability_cflags
    334:                 # _GLIBCPP__PTHREADS is for fixing Boost compilation on OpenBSD.
    335:                 flags = ["-D_REENTRANT -I/usr/local/include"]
    336:                 if RUBY_PLATFORM =~ /solaris/
    337:                         flags << '-D_XOPEN_SOURCE=500 -D_XPG4_2 -D__EXTENSIONS__ -D__SOLARIS__'
    338:                         flags << '-DBOOST_HAS_STDINT_H' unless RUBY_PLATFORM =~ /solaris2.9/
    339:                         flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if RUBY_PLATFORM =~ /solaris2.9/
    340:                         flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/
    341:                 elsif RUBY_PLATFORM =~ /openbsd/
    342:                         flags << '-DBOOST_HAS_STDINT_H -D_GLIBCPP__PTHREADS'
    343:                 elsif RUBY_PLATFORM =~ /aix/
    344:                         flags << '-DOXT_DISABLE_BACKTRACES'
    345:                 elsif RUBY_PLATFORM =~ /sparc-linux/
    346:                         flags << '-DBOOST_SP_USE_PTHREADS'
    347:                 end
    348:                 return flags.compact.join(" ").strip
    349:         end

portability_ldflags()

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.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 355
    355:         def self.portability_ldflags
    356:                 if RUBY_PLATFORM =~ /solaris/
    357:                         return '-lxnet -lrt -lsocket -lnsl -lpthread'
    358:                 else
    359:                         return '-lpthread'
    360:                 end
    361:         end

rake()

Returns the absolute path to the Rake executable that belongs to the current Ruby interpreter. Returns nil if it doesn‘t exist.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 200
    200:         def self.rake
    201:                 return locate_ruby_executable('rake')
    202:         end

rspec()

Returns the absolute path to the RSpec runner program that belongs to the current Ruby interpreter. Returns nil if it doesn‘t exist.

[ show source ]

         # File lib/phusion_passenger/platform_info.rb, line 208
    208:         def self.rspec
    209:                 return locate_ruby_executable('spec')
    210:         end