lib/autobuild/utility.rb in autobuild-1.17.0 vs lib/autobuild/utility.rb in autobuild-1.18.0
- old
+ new
@@ -26,11 +26,11 @@
@available = true
@enabled = true
@source_ref_dir = nil
@source_dir = nil
@target_dir = nil
- @install_on_error = !!install_on_error
+ @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
@@ -41,13 +41,11 @@
attr_writer :source_dir
# Absolute path to where this utulity should output its results. Returns nil if
# {source_dir} has not been set.
def source_dir
- if @source_dir
- File.expand_path(@source_dir, source_ref_dir || package.srcdir)
- end
+ File.expand_path(@source_dir, source_ref_dir || package.srcdir) if @source_dir
end
# Directory in which the utility would install some files.
# If it is relative, it is interpreted as relative to the utility's
# prefix directory (Autobuild.#{name}_prefix)
@@ -60,11 +58,13 @@
# Returns nil if {target_dir} is not set.
#
# @return [String,nil]
def target_dir
if @target_dir
- File.expand_path(@target_dir, File.expand_path(Autobuild.send("#{name}_prefix") || name, package.prefix))
+ utility_prefix = Autobuild.send("#{name}_prefix") || name
+ File.expand_path(@target_dir,
+ File.expand_path(utility_prefix, package.prefix))
else
File.join(package.logdir, "#{name}-results", package.name)
end
end
@@ -77,10 +77,11 @@
# method that call this method internally
#
# @return [Rake::Task]
def task(&block)
return if @task
+
@task = package.task task_name do
# This flag allows to disable this utility's task
# once {task} has been called
if enabled?
@installed = false
@@ -90,29 +91,24 @@
end
end
end
end
- package.task name => task_name
+ package.task name => task_name
@task
end
def call_task_block
yield if block_given?
# Allow the user to install manually in the task
# block
- if !@installed && target_dir
- install
- end
-
+ install if !@installed && target_dir
rescue Interrupt
raise
rescue ::Exception => e
- if install_on_error? && !@installed && target_dir
- install
- end
+ install if install_on_error? && !@installed && target_dir
if Autobuild.send("pass_#{name}_errors")
raise
else
package.warn "%s: failed to call #{name}"
@@ -152,20 +148,23 @@
# Allows to disable the utility regardless of the value of {available?}
attr_writer :enabled
def install
- if !File.directory?(source_dir)
- raise "#{source_dir} was expected to be a directory, but it is not. Check the package's #{name} generation. The generated #{name} products should be in #{source_dir}"
+ unless File.directory?(source_dir)
+ raise "#{source_dir} was expected to be a directory, but it is not. "\
+ "Check the package's #{name} generation. "\
+ "The generated #{name} products should be in #{source_dir}"
end
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} from #{source_dir} to #{target_dir}"
+ Autoproj.message " copied #{name} results for #{package.name} "\
+ "from #{source_dir} to #{target_dir}"
@installed = true
end
# Can be called in the block given to {task} to announce that the
@@ -186,10 +185,9 @@
# True if the underlying package already has a task generated by this
# utility
#
# @return [Boolean]
def has_task?
- !!Rake.application.lookup(task_name)
+ Rake.application.lookup(task_name)
end
end
end
-