lib/autobuild/utility.rb in autobuild-1.10.0.rc13 vs lib/autobuild/utility.rb in autobuild-1.10.0.rc14
- old
+ new
@@ -9,19 +9,28 @@
attr_reader :package
# @return [String,nil] the reference directory for {#source_dir=}. If
# nil, will use the package's source directory
attr_accessor :source_ref_dir
- def initialize(name, package)
+ # Whether #install should be called even if the task failed
+ #
+ # The default is false. Set it to true for instance if the utility
+ # results are a report of the success/errors (e.g. test run results)
+ def install_on_error?
+ @install_on_error
+ end
+
+ def initialize(name, package, install_on_error: false)
@name = name
@task = nil
@package = package
@available = true
@enabled = true
@source_ref_dir = nil
@source_dir = nil
@target_dir = nil
+ @install_on_error = !!install_on_error
end
# Directory in which the utility will generate some files The
# interpretation of relative directories is package-specific. The
# default implementation interpret them as relative to the source
@@ -52,10 +61,12 @@
#
# @return [String,nil]
def target_dir
if @target_dir
File.expand_path(@target_dir, File.expand_path(Autobuild.send("#{name}_prefix") || name, package.prefix))
+ else
+ File.join(package.logdir, "#{name}-results", package.name)
end
end
# Defines the task code for this utility. The given block is called and
# then the utility byproducts get installed (if any).
@@ -93,10 +104,14 @@
end
rescue Interrupt
raise
rescue ::Exception => e
+ if install_on_error? && !@installed && target_dir
+ install
+ end
+
if Autobuild.send("pass_#{name}_errors")
raise
else
package.warn "%s: failed to call #{name}"
if e.kind_of?(SubcommandFailed)
@@ -144,9 +159,10 @@
target_dir = self.target_dir
source_dir = self.source_dir
FileUtils.rm_rf target_dir
FileUtils.mkdir_p File.dirname(target_dir)
FileUtils.cp_r source_dir, target_dir
+ Autoproj.message " copied #{name} results for #{package.name} to #{target_dir}"
@installed = true
end
# Can be called in the block given to {task} to announce that the