Visualise macports dependencies

to clean up your installed macports and remove cruft you need to uninstall them in the correct order – according to their dependencies.

A graphical visualisation might help doing so:

Call

$ ./port-deps2dot.rb | dot -Tpdf -o port-deps.pdf ; open port-deps.pdf

with the ruby script port-deps2dot.rb (github gist) as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/ruby -w
 
# visualize macports dependencies.
# pipe the result through graphviz, e.g.
# $ ./port-deps2dot.rb | dot -Tpdf -o port-deps.pdf ; open port-deps.pdf
 
def scan_deps
	pat = /^([^:]+):(.+)$/
	name = ''
	deps = []
	IO.popen('port info --name --pretty --depends installed') do |f|
		f.each_line do |l|
			case l
				when /^--$/
					yield name, deps
					name = ''
					deps = []
				when /^([^:]+):(.+)$/
					if 'name' == "#$1"
						name = "#$2".strip
					else
						deps.concat("#$2".split(/\s*,\s*/))
					end
				else
					raise "Fall-through for '#{l}'"
			end
		end
	end
end
 
all = {}
 
scan_deps do |name,deps|
	d = all[name]
	all[name] = d = [] if d.nil?
	deps.collect! {|i| i.strip}
	d.concat deps
	d.sort!
	d.uniq!
end
 
head = < <END_OF_STRING
#!/usr/bin/dot -Tpdf -o port-deps.pdf
/*
	See http://www.graphviz.org/Documentation.php
*/
digraph "port deps" {
	rankdir=LR;
    label="port deps";
    node [style=filled,fillcolor=lightblue,shape=ellipse];
    top_level [shape=point];
END_OF_STRING
 
puts head
 
all.keys.sort.each do |name|
	deps = all[name]
	if deps.count > 0
		deps.each {|d| puts "\t\"#{name}\" -> \"#{d}\";" }
	else
		puts "\t\"#{name}\";"
	end
end
 
foot = < <END_OF_STRING
}
END_OF_STRING
 
puts foot

Flattr this!

Comments 3

  1. mro wrote:

    See also http://www.puredarwin.org/developers/macports/macports-dependencies-overview

    Posted 16 Aug 2010 at 11:35 am
  2. Shayan wrote:

    I can’t run the code, can’t code in ruby either to solve the problem:

    ./port-deps2dot.rb:45: syntax error, unexpected ‚{‚, expecting $end

    Posted 24 Jan 2011 at 1:32 pm
  3. Marcus Rohrmoser wrote:

    Thx, I added a github gist because wordpress messes up angle brackets.

    Posted 25 Jan 2011 at 10:40 am

Post a Comment

Your email is never published nor shared. Required fields are marked *