Add Formula#logs

This commit is contained in:
Jack Nagel 2015-04-25 22:07:06 -04:00
parent f5d6d80d5b
commit 16dfe3dd40
7 changed files with 18 additions and 19 deletions

View File

@ -6,7 +6,7 @@ require 'stringio'
module Homebrew
def gistify_logs f
files = load_logs(f.name)
files = load_logs(f.logs)
s = StringIO.new
Homebrew.dump_verbose_config(s)
@ -58,9 +58,8 @@ module Homebrew
request.basic_auth(user, password)
end
def load_logs name
def load_logs(dir)
logs = {}
dir = HOMEBREW_LOGS/name
dir.children.sort.each do |file|
contents = file.size? ? file.read : "empty log"
logs[file.basename.to_s] = { :content => contents }

View File

@ -18,9 +18,8 @@ module Homebrew
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
sandbox = Sandbox.new
logd = HOMEBREW_LOGS/formula.name
logd.mkpath
sandbox.record_log(logd/"sandbox.postinstall.log")
formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.postinstall.log")
sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula)
sandbox.allow_write_cellar(formula)

View File

@ -38,9 +38,8 @@ module Homebrew
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
sandbox = Sandbox.new
logd = HOMEBREW_LOGS/f.name
logd.mkpath
sandbox.record_log(logd/"sandbox.test.log")
formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.test.log")
sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(f)
sandbox.exec(*args)

View File

@ -175,7 +175,7 @@ class BuildError < RuntimeError
Homebrew.dump_build_env(env)
puts
onoe "#{formula.name} #{formula.version} did not build"
unless (logs = Dir["#{HOMEBREW_LOGS}/#{formula.name}/*"]).empty?
unless (logs = Dir["#{formula.logs}/*"]).empty?
puts "Logs:"
puts logs.map{|fn| " #{fn}"}.join("\n")
end

View File

@ -410,6 +410,10 @@ class Formula
# there after pouring a bottle.
def bottle_prefix; prefix+'.bottle' end
def logs
HOMEBREW_LOGS+name
end
# override this to provide a plist
def plist; nil; end
alias :startup_plist :plist
@ -510,7 +514,7 @@ class Formula
begin
yield self
ensure
cp Dir["config.log", "CMakeCache.txt"], HOMEBREW_LOGS+name
cp Dir["config.log", "CMakeCache.txt"], logs
end
end
end
@ -790,9 +794,8 @@ class Formula
@exec_count ||= 0
@exec_count += 1
logd = HOMEBREW_LOGS/name
logfn = "#{logd}/%02d.%s" % [@exec_count, File.basename(cmd).split(' ').first]
mkdir_p(logd)
logfn = "#{logs}/%02d.%s" % [@exec_count, File.basename(cmd).split(' ').first]
logs.mkpath
File.open(logfn, "w") do |log|
log.puts Time.now, "", cmd, args, ""

View File

@ -462,7 +462,7 @@ class FormulaInstaller
end
def build
FileUtils.rm Dir["#{HOMEBREW_LOGS}/#{formula.name}/*"]
FileUtils.rm_rf(formula.logs)
@start_time = Time.now
@ -481,9 +481,8 @@ class FormulaInstaller
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
sandbox = Sandbox.new
logd = HOMEBREW_LOGS/formula.name
logd.mkpath
sandbox.record_log(logd/"sandbox.build.log")
formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.build.log")
sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula)
sandbox.allow_write_cellar(formula)

View File

@ -50,7 +50,7 @@ class Sandbox
end
def allow_write_log(formula)
allow_write_path HOMEBREW_LOGS/formula.name
allow_write_path formula.logs
end
def deny_write_homebrew_library