Permalink
Browse files

Make the native_support compilation failure output less verbose so th…

…at it's less scary to users.
  • Loading branch information...
1 parent 1b49bd4 commit 3c2bcad4949132a6a81cf44ab410c9f8fe61908d @FooBarWidget FooBarWidget committed Jan 30, 2014
Showing with 78 additions and 38 deletions.
  1. +63 −34 lib/phusion_passenger/native_support.rb
  2. +15 −4 lib/phusion_passenger/utils/tmpio.rb
@@ -213,7 +213,6 @@ def compile_and_load
STDERR.puts " --> Compiling #{library_name} for the current Ruby interpreter..."
STDERR.puts " (set PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0 to disable)"
- STDERR.puts " -------------------------------"
require 'fileutils'
require 'shellwords'
@@ -268,9 +267,17 @@ def real_download(site, name, output_dir, logger, options)
return PhusionPassenger::Utils::Download.download(url, filename, real_options)
end
- def mkdir(dir)
+ def log(message, options = {})
+ if logger = options[:logger]
+ logger.puts(message)
+ else
+ STDERR.puts " #{message}"
+ end
+ end
+
+ def mkdir(dir, options = {})
begin
- STDERR.puts " # mkdir -p #{dir}"
+ log("# mkdir -p #{dir}", options)
FileUtils.mkdir_p(dir)
rescue Errno::EEXIST
end
@@ -282,39 +289,57 @@ def sh(command_string)
end
end
- def sh_nonfatal(command_string)
- STDERR.puts " # #{command_string}"
- PhusionPassenger::Utils.mktmpdir("passenger-native-support-") do |tmpdir|
- s_tmpdir = Shellwords.escape(tmpdir)
- result = system("#{command_string} >#{s_tmpdir}/log 2>&1")
- system("cat #{s_tmpdir}/log | sed 's/^/ /' >&2")
- return result
+ def sh_nonfatal(command_string, options = {})
+ log("# #{command_string}", options)
+ if logger = options[:logger]
+ s_logpath = Shellwords.escape(logger.path)
+ return system("(#{command_string}) >>#{s_logpath} 2>&1")
+ else
+ Utils.mktmpdir("passenger-native-support-") do |tmpdir|
+ s_tmpdir = Shellwords.escape(tmpdir)
+ result = system("(#{command_string}) >#{s_tmpdir}/log 2>&1")
+ system("cat #{s_tmpdir}/log | sed 's/^/ /' >&2")
+ return result
+ end
end
end
def compile(target_dirs)
- try_directories(target_dirs) do |target_dir|
- result =
- sh_nonfatal("#{PlatformInfo.ruby_command} #{Shellwords.escape extconf_rb}") &&
- sh_nonfatal("make clean && make")
- if result
- STDERR.puts " Compilation succesful."
- [target_dir, false]
- else
- STDERR.puts " Compilation failed."
- [nil, false]
+ logger = Utils::TmpIO.new('passenger_native_support',
+ :mode => File::WRONLY | File::APPEND,
+ :binary => false,
+ :suffix => ".log",
+ :unlink_immediately => false)
+ options = { :logger => logger }
+ begin
+ try_directories(target_dirs, options) do |target_dir|
+ result =
+ sh_nonfatal("#{PlatformInfo.ruby_command} #{Shellwords.escape extconf_rb}",
+ options) &&
+ sh_nonfatal("make clean && make", options)
+ if result
+ log "Compilation succesful. The logs are here:"
+ log logger.path
+ [target_dir, false]
+ else
+ log "Warning: compilation didn't succeed. To learn why, read this file:"
+ log logger.path
+ [nil, false]
+ end
end
end
+ ensure
+ logger.close if logger
end
- def try_directories(dirs)
+ def try_directories(dirs, options = {})
result = nil
dirs.each_with_index do |dir, i|
begin
- mkdir(dir)
+ mkdir(dir, options)
File.open("#{dir}/.permission_test", "w").close
File.unlink("#{dir}/.permission_test")
- STDERR.puts " # cd #{dir}"
+ log("# cd #{dir}", options)
Dir.chdir(dir) do
result, should_retry = yield(dir)
return result if !should_retry
@@ -325,26 +350,30 @@ def try_directories(dirs)
# error on the last one too then propagate the
# exception.
if i == dirs.size - 1
- STDERR.puts " Encountered permission error, " +
- "but no more directories to try. Giving up."
- STDERR.puts " -------------------------------"
+ log("Encountered permission error, " +
+ "but no more directories to try. Giving up.",
+ options)
+ log("-------------------------------", options)
return nil
else
- STDERR.puts " Encountered permission error, " +
- "trying a different directory..."
- STDERR.puts " -------------------------------"
+ log("Encountered permission error, " +
+ "trying a different directory...",
+ options)
+ log("-------------------------------", options)
end
rescue Errno::ENOTDIR
# This can occur when locations.ini set buildout_dir
# to an invalid path. Just ignore this error.
if i == dirs.size - 1
- STDERR.puts " Not a valid directory, " +
- "but no more directories to try. Giving up."
- STDERR.puts " -------------------------------"
+ log("Not a valid directory, " +
+ "but no more directories to try. Giving up.",
+ options)
+ log("-------------------------------", options)
return nil
else
- STDERR.puts " Not a valid directory. Trying a different one..."
- STDERR.puts " -------------------------------"
+ log("Not a valid directory. Trying a different one...",
+ options)
+ log("-------------------------------", options)
end
end
end
@@ -12,14 +12,25 @@ class TmpIO < File
# creates and returns a new File object. The File is unlinked
# immediately, switched to binary mode, and userspace output
# buffering is disabled
- def self.new(namespace)
+ def self.new(namespace, options = nil)
+ if options
+ mode = options[:mode] || RDWR
+ binary = options.fetch(:binary, true)
+ suffix = options[:suffix]
+ unlink_immediately = options.fetch(:unlink_immediately, true)
+ else
+ mode = RDWR
+ binary = true
+ suffix = nil
+ unlink_immediately = true
+ end
fp = begin
- super("#{Dir::tmpdir}/#{namespace}-#{rand}", RDWR|CREAT|EXCL, 0600)
+ super("#{Dir::tmpdir}/#{namespace}-#{rand(0x100000000).to_s(36)}#{suffix}", mode | CREAT | EXCL, 0600)
rescue Errno::EEXIST
retry
end
- unlink(fp.path)
- fp.binmode
+ unlink(fp.path) if unlink_immediately
+ fp.binmode if binary
fp.sync = true
fp
end

0 comments on commit 3c2bcad

Please sign in to comment.