aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2013-01-02 12:40:03 -0600
committerWilliam Hubbs <w.d.hubbs@gmail.com>2013-01-02 18:00:04 -0600
commit630d23283aea2304396069c6a9c305913ccb02aa (patch)
treed2d70b3df2f26aca8a03d2e6a3a2a803965bd940
parent7bda62d844a31b5dda34706c80850027a17f03e7 (diff)
Add tools directory
This directory will contain tools which are not necessary for OpenRC to run, but which some users have found useful. The first of these is deptree2dot, which converts /run/openrc/deptree to a .dot file for use with graphviz. This can assist in finding circular dependencies.
-rw-r--r--README1
-rw-r--r--src/Makefile4
-rw-r--r--src/tools/Makefile5
-rw-r--r--src/tools/deptree2dot44
4 files changed, 54 insertions, 0 deletions
diff --git a/README b/README
index 2740f542..e787ea76 100644
--- a/README
+++ b/README
@@ -18,6 +18,7 @@ MKSELINUX=yes
MKSTATICLIBS=no
MKTERMCAP=ncurses
MKTERMCAP=termcap
+MKTOOLS=yes
PKG_PREFIX=/usr/pkg
LOCAL_PREFIX=/usr/local
PREFIX=/usr/local
diff --git a/src/Makefile b/src/Makefile
index e3750347..ffbf8d6e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,5 +3,9 @@
SUBDIR= test libeinfo librc rc
+ifeq (${MKTOOLS},yes)
+SUBDIR+= tools
+endif
+
MK= ../mk
include ${MK}/subdir.mk
diff --git a/src/tools/Makefile b/src/tools/Makefile
new file mode 100644
index 00000000..92ff5063
--- /dev/null
+++ b/src/tools/Makefile
@@ -0,0 +1,5 @@
+DIR= ${UPREFIX}/bin
+BIN= deptree2dot
+
+MK= ../../mk
+include ${MK}/scripts.mk
diff --git a/src/tools/deptree2dot b/src/tools/deptree2dot
new file mode 100644
index 00000000..07ba17af
--- /dev/null
+++ b/src/tools/deptree2dot
@@ -0,0 +1,44 @@
+#!/usr/bin/perl -w
+# -*- cperl -*-
+# Copyright © 2012 Diego Elio Pettenò <flameeyes@flameeyes.eu>
+# Released under the 2-clause BSD license.
+#
+#Example usage:
+#deptree2dot > deptree.dot
+#deptree2dot | dot -Tpng -o deptree.png
+
+my $deptree = defined($ARGV[0]) ? $ARGV[0] : "/run/openrc/deptree";
+
+open DEPTREE, $deptree or exit 1;
+
+print "digraph deptree {\n";
+
+my @deptree;
+
+while(my $line = readline(DEPTREE)) {
+ $line =~ /^depinfo_([0-9]+)_([a-z]+)(?:_[0-9]+)?='(.*)'\n$/;
+ my $index = $1;
+ my $prop = $2;
+ my $value = $3; $value =~ s/[-\.:~]/_/g;
+
+ if ( $prop eq "service" ) {
+ $deptree[$index] = $value;
+ printf "%s [shape=box];\n", $value;
+ } else {
+ my $service = $deptree[$index];
+
+ if ( $prop eq "ineed" ) {
+ printf "%s -> %s;\n", $service, $value;
+ } elsif ( $prop eq "iuse" ) {
+ printf "%s -> %s [color=blue];\n", $service, $value;
+ } elsif ( $prop eq "ibefore" ) {
+ printf "%s -> %s [style=dotted];\n", $service, $value;
+ } elsif ( $prop eq "iafter" ) {
+ printf "%s -> %s [style=dotted color=purple];\n", $value, $service;
+ } elsif ( $prop eq "iprovide" ) {
+ printf "%s -> %s [color=red];\n", $value, $service;
+ }
+ }
+}
+
+print "}\n";