separate build and test logs

This commit is contained in:
Andrew Janke 2016-08-19 12:27:37 -04:00 committed by GitHub
commit 5d603c3e8f
5 changed files with 43 additions and 7 deletions

View File

@ -27,7 +27,7 @@ module Homebrew
if Sandbox.formula?(formula) if Sandbox.formula?(formula)
sandbox = Sandbox.new sandbox = Sandbox.new
formula.logs.mkpath formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.postinstall.log") sandbox.record_log(formula.logs/"postinstall.sandbox.log")
sandbox.allow_write_temp_and_cache sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula) sandbox.allow_write_log(formula)
sandbox.allow_write_cellar(formula) sandbox.allow_write_cellar(formula)

View File

@ -63,7 +63,7 @@ module Homebrew
if Sandbox.test? if Sandbox.test?
sandbox = Sandbox.new sandbox = Sandbox.new
f.logs.mkpath f.logs.mkpath
sandbox.record_log(f.logs/"sandbox.test.log") sandbox.record_log(f.logs/"test.sandbox.log")
sandbox.allow_write_temp_and_cache sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(f) sandbox.allow_write_log(f)
sandbox.allow_write_xcode sandbox.allow_write_xcode

View File

@ -130,6 +130,11 @@ class Formula
# @private # @private
attr_accessor :local_bottle_path attr_accessor :local_bottle_path
# When performing a build, test, or other loggable action, indicates which
# log file location to use.
# @private
attr_reader :active_log_type
# The {BuildOptions} for this {Formula}. Lists the arguments passed and any # The {BuildOptions} for this {Formula}. Lists the arguments passed and any
# {#options} in the {Formula}. Note that these may differ at different times # {#options} in the {Formula}. Note that these may differ at different times
# during the installation of a {Formula}. This is annoying but the result of # during the installation of a {Formula}. This is annoying but the result of
@ -735,12 +740,30 @@ class Formula
prefix+".bottle" prefix+".bottle"
end end
# The directory where the formula's installation logs will be written. # The directory where the formula's installation or test logs will be written.
# @private # @private
def logs def logs
HOMEBREW_LOGS+name HOMEBREW_LOGS+name
end end
# The prefix, if any, to use in filenames for logging current activity
def active_log_prefix
if active_log_type
"#{active_log_type}."
else
""
end
end
# Runs a block with the given log type in effect for its duration
def with_logging(log_type)
old_log_type = @active_log_type
@active_log_type = log_type
yield
ensure
@active_log_type = old_log_type
end
# This method can be overridden to provide a plist. # This method can be overridden to provide a plist.
# For more examples read Apple's handy manpage: # For more examples read Apple's handy manpage:
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/plist.5.html # https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/plist.5.html
@ -861,6 +884,17 @@ class Formula
method(:post_install).owner == self.class method(:post_install).owner == self.class
end end
# @private
def run_post_install
build = self.build
self.build = Tab.for_formula(self)
with_logging("post_install") do
post_install
end
ensure
self.build = build
end
# Tell the user about any caveats regarding this package. # Tell the user about any caveats regarding this package.
# @return [String] # @return [String]
# <pre>def caveats # <pre>def caveats
@ -1384,7 +1418,9 @@ class Formula
ENV["HOME"] = @testpath ENV["HOME"] = @testpath
setup_home @testpath setup_home @testpath
begin begin
with_logging("test") do
test test
end
rescue Exception rescue Exception
staging.retain! if ARGV.debug? staging.retain! if ARGV.debug?
raise raise
@ -1476,7 +1512,7 @@ class Formula
@exec_count ||= 0 @exec_count ||= 0
@exec_count += 1 @exec_count += 1
logfn = "#{logs}/%02d.%s" % [@exec_count, File.basename(cmd).split(" ").first] logfn = "#{logs}/#{active_log_prefix}%02d.%s" % [@exec_count, File.basename(cmd).split(" ").first]
logs.mkpath logs.mkpath
File.open(logfn, "w") do |log| File.open(logfn, "w") do |log|

View File

@ -597,7 +597,7 @@ class FormulaInstaller
if Sandbox.formula?(formula) if Sandbox.formula?(formula)
sandbox = Sandbox.new sandbox = Sandbox.new
formula.logs.mkpath formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.build.log") sandbox.record_log(formula.logs/"build.sandbox.log")
sandbox.allow_write_temp_and_cache sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula) sandbox.allow_write_log(formula)
sandbox.allow_write_xcode sandbox.allow_write_xcode

View File

@ -13,7 +13,7 @@ begin
formula = ARGV.resolved_formulae.first formula = ARGV.resolved_formulae.first
formula.extend(Debrew::Formula) if ARGV.debug? formula.extend(Debrew::Formula) if ARGV.debug?
formula.post_install formula.run_post_install
rescue Exception => e rescue Exception => e
Marshal.dump(e, error_pipe) Marshal.dump(e, error_pipe)
error_pipe.close error_pipe.close