log/ posts/ Introducing debtree

Package dependency graphs on steroids

How an innocent and simple question can lead to strange development.

I was looking for a simple command that would tell me what the dependency path is from one package to some other package. That is, without having to go by trial-and-error using e.g. aptitude.

Actually, I am getting quite annoyed by the fact that I regularly see e.g. gconf2 being pulled in when I install something on my (KDE-based) systems and I wanted to see how exactly they got pulled in. It should be possible to install e.g. xchat without being forced to install gconf2 too, right? For Sarge I had a similar issue with the gimp.

Anyway, possibly there already is something to print dependency paths, but I did not find it. As I had some time free after dropping out of the Installer team, I decided to scratch my own itch.

To get the paths I decided to recurse through dependencies using grep-available and friends, basically building a tree. An old wish was to play with dot, so I thought it would be nice to visualize the tree and so verify my code (conveniently forgetting about apt-cache dotty...).

I soon had something basic working and after that it turned out to be irresistible (and surprisingly easy) to keep adding functionality.

The result is that I can now produce graphs like:

debtree example

This is a fairly simple example. A lot of graphs are much more interesting.

Oh, yes, it also answers my original question:

$ debtree xchat gconf2
xchat -> xchat-common (D) -> gconf2 (D)

The script is quite flexible and now looks solid enough for a first (Beta) release. After a few optimizations the shell script is even acceptably fast (or at least not slow) on my box.

Euhh, what? Shell script?

Yes. As I don't really know any of the popular languages used in Open Source, writing this in e.g. perl would just have taken too much time. OTOH, after some three years of working on D-I, I have become quite fluent in shell script. After all, about 80% of the installer (almost all functionality that does the actual installations — including the partitioner) is written in shell, so complex systems in shell are perfectly possible; thanks to Joey we even have a web server in shell! And it keeps surprising me how structured you can work in shell if you try a little. So there.

Of course I'd like to see debtree re-implemented in another language, mainly to improve performance. Probably in C++ as that is what apt-cache is written in and its 'dotty' function could be a nice starting point. You'll understand from the above that I'm not going to do this myself, so if anybody is interested in working with me to do this, please contact me. debtree seems like it would be a nice addition to Debian, maybe even alongside apt-cache in apt...

Enjoy!