From 8059b1a164b207def993df33073318896b0d9b99 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 1 Apr 2011 21:08:08 -0400 Subject: [PATCH] ability write graph of settings dependencies to dot format --- main/DotGraph.scala | 53 +++++++++++++++++++++++---------------------- main/Project.scala | 17 +++++++++++++++ 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/main/DotGraph.scala b/main/DotGraph.scala index 1f6550b1f..c5f4768e7 100644 --- a/main/DotGraph.scala +++ b/main/DotGraph.scala @@ -28,33 +28,34 @@ object DotGraph } def apply(relations: Relations, outputDir: File, sourceToString: File => String, externalToString: File => String) { - def generateGraph[Key, Value](fileName: String, graphName: String, relation: Relation[Key, Value], - keyToString: Key => String, valueToString: Value => String) - { - import scala.collection.mutable.{HashMap, HashSet} - val mappedGraph = new HashMap[String, HashSet[String]] - for( (key, values) <- relation.forwardMap; keyString = keyToString(key); value <- values) - mappedGraph.getOrElseUpdate(keyString, new HashSet[String]) += valueToString(value) - - val mappings = - for { - (dependsOn, dependants) <- mappedGraph.toSeq - dependant <- dependants - if dependant != dependsOn && !dependsOn.isEmpty && !dependant.isEmpty - } - yield "\"" + dependant + "\" -> \"" + dependsOn + "\"" - - val lines = - ("digraph " + graphName + " {") +: - mappings :+ - "}" - - IO.writeLines(new File(outputDir, fileName), lines) - } + def file(name: String) = new File(outputDir, name) IO.createDirectory(outputDir) - generateGraph("int-source-deps", "dependencies", relations.internalSrcDep, sourceToString, sourceToString) - //generateGraph("ext-source-deps", "dependencies", analysis.externalDep, srcToString, srcToString) - generateGraph("binary-dependencies", "externalDependencies", relations.binaryDep, externalToString, sourceToString) + generateGraph(file("int-source-deps"), "dependencies", relations.internalSrcDep, sourceToString, sourceToString) + generateGraph(file("binary-dependencies"), "externalDependencies", relations.binaryDep, externalToString, sourceToString) + } + + def generateGraph[Key, Value](file: File, graphName: String, relation: Relation[Key, Value], + keyToString: Key => String, valueToString: Value => String) + { + import scala.collection.mutable.{HashMap, HashSet} + val mappedGraph = new HashMap[String, HashSet[String]] + for( (key, values) <- relation.forwardMap; keyString = keyToString(key); value <- values) + mappedGraph.getOrElseUpdate(keyString, new HashSet[String]) += valueToString(value) + + val mappings = + for { + (dependsOn, dependants) <- mappedGraph.toSeq + dependant <- dependants + if dependant != dependsOn && !dependsOn.isEmpty && !dependant.isEmpty + } + yield "\"" + dependant + "\" -> \"" + dependsOn + "\"" + + val lines = + ("digraph " + graphName + " {") +: + mappings :+ + "}" + + IO.writeLines(file, lines) } def sourceToString(roots: Iterable[File], source: File) = { diff --git a/main/Project.scala b/main/Project.scala index 77f622efb..d35bdc949 100644 --- a/main/Project.scala +++ b/main/Project.scala @@ -183,6 +183,23 @@ object Project extends Init[Scope] printScopes("Delegates", delegates(structure, scope, key)) + printScopes("Related", related) } + def graphSettings(structure: Load.BuildStructure, basedir: File) + { + def graph(actual: Boolean, name: String) = graphSettings(structure, actual, name, new File(basedir, name + ".dot")) + graph(true, "actual_dependencies") + graph(false, "declared_dependencies") + } + def graphSettings(structure: Load.BuildStructure, actual: Boolean, graphName: String, file: File) + { + type Rel = Relation[ScopedKey[_], ScopedKey[_]] + val cMap = compiled(structure.settings, actual)(structure.delegates, structure.scopeLocal) + val relation = + ((Relation.empty: Rel) /: cMap) { case (r, (key, value)) => + r + (key, value.dependencies) + } + val keyToString = (key: ScopedKey[_]) => Project display key + DotGraph.generateGraph(file, graphName, relation, keyToString, keyToString) + } def reverseDependencies(cMap: CompiledMap, scoped: ScopedKey[_]): Iterable[ScopedKey[_]] = for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key