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,7 +28,13 @@ object DotGraph
} }
def apply(relations: Relations, outputDir: File, sourceToString: File => String, externalToString: File => String) def apply(relations: Relations, outputDir: File, sourceToString: File => String, externalToString: File => String)
{ {
def generateGraph[Key, Value](fileName: String, graphName: String, relation: Relation[Key, Value], def file(name: String) = new File(outputDir, name)
IO.createDirectory(outputDir)
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) keyToString: Key => String, valueToString: Value => String)
{ {
import scala.collection.mutable.{HashMap, HashSet} import scala.collection.mutable.{HashMap, HashSet}
@ -49,12 +55,7 @@ object DotGraph
mappings :+ mappings :+
"}" "}"
IO.writeLines(new File(outputDir, fileName), lines) IO.writeLines(file, lines)
}
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)
} }
def sourceToString(roots: Iterable[File], source: File) = 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("Delegates", delegates(structure, scope, key)) +
printScopes("Related", related) 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[_]] = def reverseDependencies(cMap: CompiledMap, scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =
for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key