2024-09-04

how to display a guile module dependency tree

the sph-script repository contains guile-module-dependencies, which you can save and use with guile. sph-lib must also be installed for it to work. add the executable bit with "chmod +x filename" and move the file into a path listed in the environment variable $PATH to have it as a global command line command.

guile-module-dependencies can output the list of modules a module depends on. either as a list with indentation or in the graphviz dot language format to view it as a graph drawing.

guile-module-dependencies command-line interface

parameters
  options ... name
description
  displays a dependency tree for a module.
  module name is given with brackets, for example "(srfi srfi-1)"
options
  --exclude=value  prefixes to exclude
  --format=value  indent or graphviz (dot language)
  --help | -h
  --include=value  prefixes to include, "(a b),(c)"
  --interface
  --max-depth=value
  --no-brackets
  --strip-prefix=value

if the script file is not in a $PATH directory, it can be called as "guile guile-module-dependencies".

example usage

guile-module-dependencies "(sph)" --max-depth=1

output:

(guile)
  (ice-9 ports)
(ice-9 pretty-print)
  (guile)
  (ice-9 match)
  (srfi srfi-1)
  (rnrs bytevectors)

viewing the output as a graph drawing

guile-module-dependencies "(sph)" --max-depth=1 --format=graphviz > t.dot

the xdot tool can render and display .dot files directly:

xdot t.dot

module-dependency-tree-xdot.png

possible enhancements

  • it might be useful to output a flat list of module names without duplicates. this would allow to list just those modules that would need to be extracted together with another module about to be extracted from a codebase