Announcing dune-deps: produces a project-centric dependency graph

I’m happy to announce the availability of dune-deps, a command-line tool that scans a dune project and gathers the dependencies into a graph. The output is in the dot format, supported by the dot command from graphviz.

It shows the dependencies between the following:

  • libraries defined by the project,
  • executables defined by the project,
  • direct dependencies on external libraries.

Dependencies are extracted by parsing dune files. As an example, here’s what we obtain for the sources of opam, which has over 50K lines of code:

The commands for this are:

# obtain the project's sources
$ git clone --depth=1 https://github.com/ocaml/opam.git

# extract dependencies and eliminate superfluous graph edges
$ dune-deps opam | tred > deps.dot

# render the graph
$ dot -Tpng deps.dot -o deps.png

A suggestion is to include such graph in your project’s README.md.

Enjoy.

22 Likes

Very nice tool! Thanks @mjambon :slight_smile:

1 Like

Since the original announcement, I received some good feedback from users working on large projects. Thank you!

The latest version released today is 1.2.0. It is already available on opam-repository (thank you @kit-ty-kate). The changes since the original release, besides bug fixes, include:

  • Ability to select or ignore dune files and folders to scan. For example, dune-deps foo bar -x bar/test uses all the dune files found in folders foo and bar but will ignore bar/test. This is useful for ignoring uninteresting parts of the project and for ignoring parse errors (see bug #4).
  • Executable name disambiguation. For example, private executables of the same name like foo/main and bar/baz/main are now rendered as main<foo> and main<baz> respectively instead of just main.
  • Optional exclusion of all executables or all external libraries with --no-exe and --no-ext.
  • Ability to show only the dependencies and/or the reverse dependencies of selected libraries. See below.

Whole-project graphs for large projects tend to be unreadable. To deal with that, I added support for an “hourglass view” (:hourglass:) option for showing only the dependencies and reverse dependencies of a component of interest.

The following is obtained with -h opam-client on the opam project:

Please let us know if this works for your favorite projects! The source code of dune-deps makes it somewhat easier now to experiment with new strategies for eliminating nodes. See the Filter and Filterable modules.

Check out dune-deps --help for detailed documentation on the options.

3 Likes

By the way, would be nice to add also the version information to the graph.

2 Likes

A suggestion is to include such graph in your project’s README.md .

That’s a nice idea - it’d be great to have this available as a GitHub action so anyone could do this with just a click or two!

2 Likes

What kind of version information are you referring to?

So, I made a generic yaml workflow that people can stick into their git/github project. This will automatically maintain the dependency graph .deps/deps.png which can be included in a readme.

2 Likes