Date: 2015-01-23
Categories: misc
OCaml dependency graph via graphviz and dot file
I often want to visualize the dependency graph of OCaml source files, without using ocamldoc. The one-liner I currently use for this is:
# grep -v removes matching lines
ocamldep -one-line *.ml *.mli |grep -v "cmx" |dot_of_depend.py |dot -Tsvg >tmp.svg
The code dot_of_depend.py
, which I put in my personal bin
directory, is as follows (I think I stole this from somewhere on the web, but have been unable to locate the original source):
#!/usr/bin/python
import re
import sys
def sanitize(s):
s=re.sub('.*/','',s)
s=re.sub('[^0-9a-zA-Z]+', '_', s)
return s
f=sys.stdin #open('.depend','r')
counter=0
dictionary={} # for storing map from int to filename
print "digraph depend {"
for line in f:
s=line.split();
for x in range(2, len(s)):
print (sanitize(s[0]))+" -> "+(sanitize(s[x]))
print "}"
This is effectively a light-weight version of the code here http://trevorjim.com/projects/ocamldot/ the functionality of which was then included in ocamldoc. The problem is that ocamldoc is quite heavyweight, whereas ocamldep and the above are really lightweight.
Related posts:
- 2018-12-05 Congratulations to Andrea Giugliano!
- 2018-11-05 What has gone wrong with our universities?
- 2018-07-19 The state of computing in 2018
- 2017-05-15 PhD viva: congratulations to Thomas Gransden
- 2017-01-23 Daniel Morrison PhD
- 2016-10-20 The Tree of Life (film)
- 2016-10-12 Outreach talk at Uppingham School
- 2016-06-05 Do not buy TP-Link products
- 2016-05-11 The meaning of IELTS 6.0
- 2015-09-11 Richard Hamming 1968 Turing Award lecture quote
- 2015-06-22 Working with the nix package manager: OCaml, Isabelle and Lem
- 2015-06-17 J. M. Coetzee novel, Youth
- 2015-01-23 OCaml dependency graph via graphviz and dot file