a life of coding

Wednesday, September 02, 2009

Cleaning MacPorts Dependencies

Sometimes MacPorts gets a little carried away with dependencies. I recently tried installing mercurial on 10.6, and found MacPorts yak shaving various X11 libraries. After deciding that this yak didn't need to be shaved, I cancelled the install and downloaded the Mac OS X mercurial installer (index).

Unfortunately, canceling a port install leaves behind extra packages. Which packages? Good question. I knew that I had asked for some packages (libidl, graphviz, bash-completion), but I didn't know which packages were only installed as dependencies of my half completed mercurial request. Given a package, port can find the packages that are dependent on it. Hmm, this sounds like some programming homework...

Given a map of package names to a list of packages dependent on that package:
  1. find packages with no dependencies, which were not explicitly installed by the user
  2. if there are none, you are done
    1. add them to a list of packages to remove
    2. remove their map entry
    3. remove them wherever they appear as dependent on another package
  3. recurse!