ability write graph of settings dependencies to dot format

This commit is contained in:
Mark Harrah 2011-04-01 21:08:08 -04:00
parent 28c8473783
commit 8059b1a164
2 changed files with 44 additions and 26 deletions

View File

@ -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) =
{

View File

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