lib/rake.rb in drake-0.8.1.10.0.1 vs lib/rake.rb in drake-0.8.1.11.0.1
- old
+ new
@@ -27,11 +27,11 @@
#
# This is the main file for the Rake application. Normally it is referenced
# as a library via a require statement, but it can be distributed
# independently as an application.
-RAKEVERSION = '0.8.1.10.0.1'
+RAKEVERSION = '0.8.1.11.0.1'
require 'rbconfig'
require 'getoptlong'
require 'fileutils'
require 'singleton'
@@ -563,21 +563,28 @@
self
end
# Invoke the task if it is needed. Prerequites are invoked first.
def invoke(*args)
- task_args = TaskArguments.new(arg_names, args)
+ run_invoke = lambda {
+ invoke_with_call_chain(
+ TaskArguments.new(arg_names, args),
+ InvocationChain::EMPTY)
+ }
- if application.num_threads > 1
- application.parallel_tasks = Hash.new
+ if application.num_threads == 1
+ run_invoke.call
+ else
+ if application.parallel_lock.locked?
+ raise "Calling Task#invoke within a task is not allowed."
+ end
+ application.parallel_lock.synchronize {
+ application.parallel_tasks.clear
+ run_invoke.call
+ application.invoke_parallel_tasks
+ }
end
-
- invoke_with_call_chain(task_args, InvocationChain::EMPTY)
-
- if application.num_threads > 1
- application.invoke_parallel_tasks
- end
end
# Same as invoke, but explicitly pass a call chain to detect
# circular dependencies.
def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
@@ -756,10 +763,14 @@
end
end # class << Rake::Task
end # class Rake::Task
+ #
+ # DEPRECATED: do not use MultiTask
+ #
+ MultiTask = Task
# #########################################################################
# A FileTask is a task that includes time based dependencies. If any of a
# FileTask's prerequisites have a timestamp that is later than the file
# represented by this task, then the file must be rebuilt (using the
@@ -819,17 +830,10 @@
# than any other time stamp.
def timestamp
Rake::EARLY
end
end
-
- # #########################################################################
- # REMOVED: use command-line option '--threads N' or
- # Rake.application.num_threads = N
- #
- class MultiTask < Task
- end
end # module Rake
# ###########################################################################
# Task Definition Functions ...
@@ -842,10 +846,16 @@
#
def task(*args, &block)
Rake::Task.define_task(*args, &block)
end
+#
+# DEPRECATED: Do not use 'multitask'
+#
+def multitask(*args, &block)
+ task(*args, &block)
+end
# Declare a file task.
#
# Example:
# file "config.cfg" => ["config.template"] do
@@ -879,18 +889,10 @@
mkdir_p t.name if ! File.exist?(t.name)
end
end
end
-#
-# REMOVED: use command-line option '--threads N' or
-# Rake.application.num_threads = N
-#
-def multitask(args, &block)
- Rake::MultiTask.define_task(args, &block)
-end
-
# Create a new rake namespace and use it for evaluating the given block.
# Returns a NameSpace object that can be used to lookup tasks defined in the
# namespace.
#
# E.g.
@@ -945,11 +947,11 @@
Rake.application.add_import(fn)
end
end
#
-# seq -- Force tasks to be executed sequentially.
+# +seq+ : Force tasks to be executed sequentially.
#
(class << self ; self ; end).class_eval {
# use this form to cleanly hide the lambda
seq_lambda = lambda { |*task_names|
(1...task_names.size).each { |n|
@@ -1700,19 +1702,23 @@
# Track the last comment made in the Rakefile.
attr_accessor :last_description
alias :last_comment :last_description # Backwards compatibility
attr_accessor :num_threads
- attr_accessor :parallel_tasks #:nodoc:
+ attr_reader :parallel_tasks #:nodoc:
+ attr_reader :parallel_lock #:nodoc:
def initialize
super
@tasks = Hash.new
@rules = Array.new
@scope = Array.new
@last_description = nil
+
@num_threads = 1
+ @parallel_tasks = Hash.new
+ @parallel_lock = Mutex.new
end
def create_rule(*args, &block)
pattern, arg_names, deps = resolve_args(args)
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
@@ -2397,26 +2403,33 @@
rakefile, location = find_rakefile_location
if (! options.ignore_system) &&
(options.load_system || rakefile.nil?) &&
directory?(system_dir)
puts "(in #{Dir.pwd})" unless options.silent
- Dir["#{system_dir}/*.rake"].each do |name|
+ glob("#{system_dir}/*.rake") do |name|
add_import name
end
else
fail "No Rakefile found (looking for: #{@rakefiles.join(', ')})" if
rakefile.nil?
@rakefile = rakefile
Dir.chdir(location)
puts "(in #{Dir.pwd})" unless options.silent
$rakefile = @rakefile if options.classic_namespace
load File.expand_path(@rakefile) if @rakefile && @rakefile != ''
+ options.rakelib.each do |rlib|
+ glob("#{rlib}/*.rake") do |name|
+ add_import name
+ end
+ end
end
- options.rakelib.each do |rlib|
- Dir["#{rlib}/*.rake"].each do |name| add_import name end
- end
load_imports
end
+
+ def glob(path, &block)
+ Dir[path.gsub("\\", '/')].each(&block)
+ end
+ private :glob
# The directory path containing the system wide rakefiles.
def system_dir
if ENV['RAKE_SYSTEM']
ENV['RAKE_SYSTEM']