diff --git a/Rakefile b/Rakefile index 1be872a6b..19aa7f638 100644 --- a/Rakefile +++ b/Rakefile @@ -752,6 +752,25 @@ namespace :dev do revision = `git rev-parse --short HEAD`.chomp create_source_tarball "-#{revision}" end + + desc "Dump dependencies of the task given with TASK environment variable" + task "dependencies" do + if ENV['TASK'].blank? + puts "'TASK' environment variable not set" + exit 1 + end + + task = Rake::Task[ENV['TASK']] + if !task + puts "No task named '#{ENV['MTASK']}'" + exit 1 + end + + prereqs = task.mo_all_prerequisites + longest = prereqs.map { |p| p[0].length }.max + + puts prereqs.map { |p| sprintf("%-#{longest}s => %s", p[0], p[1].sort.join(" ")) }.join("\n") + end end # Installation tasks diff --git a/rake.d/helpers.rb b/rake.d/helpers.rb index 88d9d439c..e385b2171 100644 --- a/rake.d/helpers.rb +++ b/rake.d/helpers.rb @@ -185,6 +185,23 @@ def list_targets? *targets end class Rake::Task + def mo_all_prerequisites + todo = [name] + result = [] + + while !todo.empty? + current = todo.shift + prereqs = Rake::Task[current].prerequisites + + next if prereqs.empty? + + result << [current, prereqs] + todo += prereqs + end + + result.uniq + end + def investigate result = "------------------------------\n" result << "Investigating #{name}\n"