summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-08-07 23:55:51 +0900
committerGitHub <[email protected]>2019-08-07 23:55:51 +0900
commit438638b42e13297d38198b15f2fc007e0f5a44a8 (patch)
treeb01b2610b75d58768e02bdc9f6133c0ced0b9efa
parentb377b7d58062d555cc45249ae038c8b2875eec9e (diff)
parent7e42b6ad3f449cb49568dcd5b7439f7ba3908dae (diff)
downloadmruby-438638b42e13297d38198b15f2fc007e0f5a44a8.tar.gz
mruby-438638b42e13297d38198b15f2fc007e0f5a44a8.zip
Merge pull request #4620 from shuujii/improve-MiniRake-rule-enhancement-for-Rake-compatibility
Improve MiniRake rule enhancement for Rake compatibility
-rwxr-xr-xminirake38
1 files changed, 27 insertions, 11 deletions
diff --git a/minirake b/minirake
index cd2d85854..8df395e97 100755
--- a/minirake
+++ b/minirake
@@ -206,25 +206,41 @@ module MiniRake
# task with the prerequisites and actions from the rule. Set the
# source attribute of the task appropriately for the rule. Return
# 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|
- if pattern.match(task_name)
- ext = extensions.first
- deps = extensions[1..-1]
+ next unless pattern && pattern.match(task_name)
+ sources = extensions.flat_map do |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
- source = task_name.sub(/\.[^.]*$/, ext)
- when Proc
- source = ext.call(task_name)
+ ext
+ when Proc, Method
+ ext.arity == 1 ? ext.call(task_name) : ext.call
else
fail "Don't know how to handle rule dependent: #{ext.inspect}"
end
- if File.exist?(source)
- task = FileTask.define_task({task_name => [source]+deps}, &block)
- task.source = source
- return task
+ end
+ prereqs = sources.map do |source|
+ if File.exist?(source) || TASKS[source]
+ source
+ elsif parent = enhance_with_matching_rule(source, level + 1)
+ parent.name
+ else
+ break nil
end
end
+ if prereqs
+ task = FileTask.define_task(task_name => prereqs, &block)
+ task.source = prereqs.first
+ return task
+ end
end
nil
end