Skip to content

Instantly share code, notes, and snippets.

@krono
Forked from frankshearar/dotify-package-deps.st
Last active December 20, 2015 07:18
Show Gist options
  • Save krono/6091959 to your computer and use it in GitHub Desktop.
Save krono/6091959 to your computer and use it in GitHub Desktop.
Make a dot/graphviz-file from the package-dependencies in Squeak
| allDeps toDigraph |
"Avoid artifacts"
MCWorkingCopy flushObsoletePackageInfos.
PackageOrganizer default flushObsoletePackages: [:p |
p classes size = 0 and: [p methods size = 0]].
Smalltalk garbageCollect.
""
toDigraph := [:hash | | s |
s := WriteStream on: String new.
s nextPutAll: 'digraph {'; lf.
hash keysAndValuesDo: [:pkg :pkgDeps |
s nextPutAll: ' "'; nextPutAll: pkg; nextPutAll: '";'; lf.
pkgDeps do: [:data | | dep weight |
dep := data first. weight := data second.
weight yourself.
s nextPutAll: ' "'; nextPutAll: pkg; nextPutAll: '" -> "'; nextPutAll: dep; nextPutAll: '"'.
((pkg includesSubString: 'Test') and: [pkg ~= 'Tests']) ifTrue: [s nextPutAll: ' [style="dotted"]'].
s nextPut: $;; lf]].
s nextPutAll: '}'.
s contents].
allDeps := Dictionary new.
PackageInfo allPackages do: [:p | | dep depClasses depMethods |
dep := DependencyBrowser new.
dep computePackageDependencies: p packageName.
depClasses := (dep instVarNamed: 'classDeps') keys intersection: (p classes collect: [:c| c name]).
depMethods := depClasses gather: [:depCls | (dep instVarNamed: 'classDeps') at: depCls].
Transcript show: p packageName, ': weight = ', depMethods size printString; cr.
allDeps at: p packageName put: (dep packageDeps collect: [:d | {d. depMethods size}])].
FileStream fileNamed: 'trunkimage-deps.dot' do: [:f |
f nextPutAll: (toDigraph value: allDeps)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment