aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula.rb
diff options
context:
space:
mode:
authorMax Howell2012-09-11 20:59:59 -0400
committerMax Howell2012-09-25 11:31:56 -0400
commita217b03952fca6df22ecc62523d9c85883aef856 (patch)
tree82d30ca49fa0224ac6339a5c4399b3de6ba4c49f /Library/Homebrew/formula.rb
parent1100818100ae07fa49419b4ab69ebbeb59a7615d (diff)
downloadbrew-a217b03952fca6df22ecc62523d9c85883aef856.tar.bz2
Clean up and improve build-error output and logs
All logs are now stored from each command executed in Formula.install. Error output is truncated to five lines in an attempt to not overwhelm the user and to encourage users to read the error output and report the bug properly. Maybe we can get that figure up from 70% to 90%.
Diffstat (limited to 'Library/Homebrew/formula.rb')
-rw-r--r--Library/Homebrew/formula.rb53
1 files changed, 33 insertions, 20 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index bf784d0ce..78269c88d 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -223,25 +223,17 @@ class Formula
# we allow formulas to do anything they want to the Ruby process
# so load any deps before this point! And exit asap afterwards
yield self
- rescue Interrupt, RuntimeError, SystemCallError => e
- puts if Interrupt === e # don't print next to the ^C
- unless ARGV.debug?
- %w(config.log CMakeCache.txt).select{|f| File.exist? f}.each do |f|
- HOMEBREW_LOGS.install f
- puts "#{f} was copied to #{HOMEBREW_LOGS}"
+ rescue RuntimeError, SystemCallError => e
+ if not ARGV.debug?
+ %w(config.log CMakeCache.txt).each do |fn|
+ (HOMEBREW_LOGS/name).install(fn) if File.file?(fn)
end
raise
end
- onoe e.inspect
- puts e.backtrace
+ onoe e.inspect
+ puts e.backtrace unless e.kind_of? BuildError
ohai "Rescuing build..."
- if (e.was_running_configure? rescue false) and File.exist? 'config.log'
- puts "It looks like an autotools configure failed."
- puts "Gist 'config.log' and any error output when reporting an issue."
- puts
- end
-
puts "When you exit this shell Homebrew will attempt to finalise the installation."
puts "If nothing is installed or the shell exits with a non-zero error code,"
puts "Homebrew will abort. The installation prefix is:"
@@ -529,23 +521,30 @@ protected
if ARGV.verbose?
safe_system cmd, *args
else
+ @exec_count ||= 0
+ @exec_count += 1
+ logd = HOMEBREW_LOGS/name
+ logfn = "#{logd}/%02d.%s" % [@exec_count, File.basename(cmd).split(' ').first]
+ mkdir_p(logd)
+
rd, wr = IO.pipe
pid = fork do
+ ENV['VERBOSE'] = '1' # helps with many tool's logging outputs
rd.close
$stdout.reopen wr
$stderr.reopen wr
args.collect!{|arg| arg.to_s}
exec(cmd, *args) rescue nil
+ puts "Failed to execute: #{cmd}"
exit! 1 # never gets here unless exec threw or failed
end
wr.close
- out = ''
- out << rd.read until rd.eof?
+
+ f = File.open(logfn, 'w')
+ f.write(rd.read) until rd.eof?
+
Process.wait
- unless $?.success?
- puts out
- raise
- end
+ raise unless $?.success?
end
removed_ENV_variables.each do |key, value|
@@ -553,7 +552,21 @@ protected
end if removed_ENV_variables
rescue
+ if f
+ f.flush
+ Kernel.system "/usr/bin/tail -n 5 #{logfn}"
+ require 'cmd/--config'
+ $f = f
+ def Homebrew.puts(*foo); $f.puts *foo end
+ f.puts
+ Homebrew.dump_build_config
+ class << Homebrew; undef :puts end
+ else
+ puts "No logs recorded :(" unless ARGV.verbose?
+ end
raise BuildError.new(self, cmd, args, $?)
+ ensure
+ f.close if f
end
public