Dependency graph of some OCaml source files

Hello,

Is there a tool that can compute the depency graph for some OCaml modules in a source tree?

Can dune do this?

Output in the graphviz dot format would be cool, so that I can plot the graph.

Regards,
F.

3 Likes

My understanding is that dune uses Chapter 14  Dependency generator (ocamldep) which ships with the OCaml distribution.

1 Like

Ok, I tried but I failed (initially) with ocamldep.
I was missing some options (especially -modules) so that the output is useful to me:

ocamldep -modules -all -one-line -ml-synonym .mlv -mli-synonym .mliv -pp _build/default/build/prefilter.exe src/*.ml src/*.mlv src/*.mliv src/*.mli

So, now, I just miss the conversion to a graph picture.

1 Like

Ok, so there are other tools also:
ocamldoc and its -dot option (Chapter 16  The documentation generator (ocamldoc))
and the more recent dune-deps project (GitHub - mjambon/dune-deps: Show the internal dependencies in your OCaml/Reason/Dune project)
from master Martin Jambon, but this one only for projects already using dune.

I use codept, which you need to opam pin to use. tred is a utility to get better graph visualizations.

codept src/*.ml -modules -dot | tred | dot -Tpng > deps.png

This gives you particularly what you want: dependency graph of source files in your src/ folder.

1 Like

You may be interested in cmgraph which scrapes the compiled modules (.cmi/.cmo/*.cmx) instead of the source code. It needs no compilation switch options since it does not scrape source code.

2 Likes