Commit 7e42b6ad authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Improve MiniRake rule enhancement for Rake compatibility

Support pathmap notation, recursive dependencies search, and so on.
parent b377b7d5
...@@ -206,25 +206,41 @@ module MiniRake ...@@ -206,25 +206,41 @@ module MiniRake
# task with the prerequisites and actions from the rule. Set the # task with the prerequisites and actions from the rule. Set the
# source attribute of the task appropriately for the rule. Return # source attribute of the task appropriately for the rule. Return
# the enhanced task or nil of no rule was found. # the enhanced task or nil of no rule was found.
def enhance_with_matching_rule(task_name) def enhance_with_matching_rule(task_name, level=0)
fail "Rule Recursion Too Deep: #{task_name}" if level >= 16
RULES.each do |pattern, extensions, block| RULES.each do |pattern, extensions, block|
if pattern.match(task_name) next unless pattern && pattern.match(task_name)
ext = extensions.first sources = extensions.flat_map do |ext|
deps = extensions[1..-1]
case ext case ext
when /%/
task_name.pathmap(ext)
when %r{/}
ext
when /^\./
source = task_name.sub(pattern, ext)
source == ext ? task_name.ext(ext) : source
when String when String
source = task_name.sub(/\.[^.]*$/, ext) ext
when Proc when Proc, Method
source = ext.call(task_name) ext.arity == 1 ? ext.call(task_name) : ext.call
else else
fail "Don't know how to handle rule dependent: #{ext.inspect}" fail "Don't know how to handle rule dependent: #{ext.inspect}"
end end
if File.exist?(source) end
task = FileTask.define_task({task_name => [source]+deps}, &block) prereqs = sources.map do |source|
task.source = source if File.exist?(source) || TASKS[source]
return task source
elsif parent = enhance_with_matching_rule(source, level + 1)
parent.name
else
break nil
end end
end end
if prereqs
task = FileTask.define_task(task_name => prereqs, &block)
task.source = prereqs.first
return task
end
end end
nil nil
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment