Rakefile: add task for dumping a task's dependencies

This commit is contained in:
Moritz Bunkus 2018-01-01 11:02:38 +01:00
parent 71d6291318
commit 17eb6205e0
2 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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"