Commit f7817f77 authored by Drew's avatar Drew

Add prunedDependencyGraph, a dependency calculation engine

parent f3d8b062
......@@ -45,6 +45,26 @@ final public class Package {
// The optional properties. All optional properties must have a default value.
public var version: String = ""
public var tasks: [String:Task] = [:]
/**Calculate the pruned dependency graph for the given task
- returns: A list of tasks in a reasonable order to be processed. */
public func prunedDependencyGraph(task: Task) -> [Task] {
var pruned : [Task] = []
if let dependencies = task["dependencies"]?.vector {
for next in dependencies {
guard let depName = next.string else { fatalError("Non-string dependency \(next)")}
guard let nextTask = tasks[depName] else { fatalError("Can't find so-called task \(depName)")}
let nextGraph = prunedDependencyGraph(nextTask)
for nextItem in nextGraph {
let filteredTasks = pruned.filter() {$0.key == nextItem.key}
if filteredTasks.count >= 1 { continue }
pruned.append(nextItem)
}
}
}
pruned.append(task)
return pruned
}
public init(name: String) {
self.name = name
......
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