Created
April 29, 2017 00:40
-
-
Save schnittchen/f2e0bce53ff89f7d72750da6daad55df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## There are dependencies we cannot see, e.g. when a task | |
## invokes another one programmatically | |
# find all tasks for which we provide an action | |
tasks1 = Rake.application.tasks.select { |task| | |
task.actions.any? | |
}.reject { |task| | |
task.actions.first.source_location.first["/gems"] | |
} | |
# add those that depend on a task in task1 | |
# (not a transitive closure) | |
tasks2 = Rake.application.tasks.select { |task| | |
tasks1.include?(task) || (task.prerequisites & tasks1.map(&:name)).any? | |
} | |
TaskData = Struct.new(:task, :dependent_count, :children, :inline, :full, :display) do | |
def render_independently? | |
!(dependent_count == 1 && children.length < 2) | |
end | |
end | |
data = tasks2.each_with_object({}) { |task, hash| | |
hash[task.name] = TaskData.new(task, 0) | |
} | |
tasks2.each do |task| | |
task.prerequisites.each do |dep| | |
data[dep].dependent_count += 1 | |
end | |
data[task.name].children = task.prerequisites.map { |name| data[name] } | |
end | |
data.values.each do |td| | |
if td.children.none? | |
td.inline = td.full = td.task.name | |
td.display = td.task.name | |
elsif td.render_independently? | |
td.inline = td.task.name | |
end | |
end | |
data.length.times do | |
data.values.each do |td| | |
if td.children.all?(&:inline) | |
td.full = "#{td.task.name} => [#{td.children.map(&:inline).join ", "}]" | |
td.inline ||= td.full | |
end | |
end | |
end | |
data.values | |
.select(&:render_independently?) | |
.each do |td| | |
puts td.full | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment