Using GraphViz to visualize the runtime dependencies of the installed ports
If you’re curious to find out how all your installed ports depend upon each other, you might want to run this neat, little script saving its output to a file, and install graphics/graphviz
.
#!/bin/sh # Copyright © 2014, Trond Endrestøl <Trond.Endrestol@ximalas.info> # All rights reserved. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin echo "digraph ports_tree {" ORIGINS=`pkg info -aoq | sort` for o in ${ORIGINS}; do DEPENDENCIES=`pkg query %do ${o} | sort`; if [ -z "${DEPENDENCIES}" ]; then REVDEPENDENCIES=`pkg query %ro ${o} | sort`; if [ -z "${REVDEPENDENCIES}" ]; then # A root port. echo " \"${o}\";"; fi; else for d in ${DEPENDENCIES}; do # ${o} needs ${d}. echo " \"${d}\" -> \"${o}\";"; done; fi; done echo "}"
Here’s a sample from a small VM at home:
digraph ports_tree { "databases/db41" -> "databases/ruby-bdb"; "lang/ruby19" -> "databases/ruby-bdb"; "textproc/expat2" -> "devel/apr1"; "devel/autoconf-wrapper" -> "devel/autoconf"; "devel/m4" -> "devel/autoconf"; "lang/perl5.16" -> "devel/autoconf"; "devel/autoconf" -> "devel/automake"; "devel/automake-wrapper" -> "devel/automake"; "lang/perl5.16" -> "devel/automake"; "devel/m4" -> "devel/bison"; "devel/gmake"; "devel/libtool"; "devel/libsigsegv" -> "devel/m4"; "devel/pkgconf"; "lang/python27" -> "devel/py-setuptools27"; "devel/py-setuptools27" -> "devel/scons"; "lang/python2" -> "devel/scons"; "lang/python27" -> "devel/scons"; "databases/sqlite3" -> "devel/subversion"; "devel/apr1" -> "devel/subversion"; "textproc/expat2" -> "devel/subversion"; "www/serf" -> "devel/subversion"; "lang/python27" -> "lang/python2"; "devel/gettext" -> "lang/python27"; "devel/libffi" -> "lang/ruby19"; "textproc/libyaml" -> "lang/ruby19"; "lang/perl5.16" -> "misc/help2man"; "devel/protobuf" -> "net/mosh"; "lang/perl5.16" -> "net/mosh"; "ports-mgmt/dialog4ports"; "ports-mgmt/pkg"; "databases/ruby-bdb" -> "ports-mgmt/portupgrade"; "lang/ruby19" -> "ports-mgmt/portupgrade"; "shells/bash"; "sysutils/lsof" -> "sysutils/htop"; "lang/perl5.16" -> "sysutils/parallel"; "devel/apr1" -> "www/serf"; "textproc/expat2" -> "www/serf"; }
Here’s a PDF file of the above graph.
The PDF file was generated by a command like this one:
dot -Tpdf -O input-file.gv
The PDF file will usually be named input-file.gv.pdf
.
A graph of a ports tree with approximately 550 vertices and more than 2500 edges, took about 1 minute to generate on an Intel Core i5-2400 running at 3.10 GHz.