Created
May 13, 2012 15:22
-
-
Save eagletmt/2688907 to your computer and use it in GitHub Desktop.
cabal-upgrade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
IGNORE_PKG = [ | |
] | |
JOBS = 4 | |
Thread.abort_on_exception = true | |
th = Thread.start do | |
`cab outdated`.lines.map { |line| line.split.first }.delete_if { |pkg| IGNORE_PKG.include? pkg } | |
end | |
def pkgname(s) | |
m = s.match /\A([A-Za-z0-9-]+?)-[0-9.]+\z/ | |
m[1] | |
end | |
revdep = Hash.new { |h, k| h[k] = [] } | |
`ghc-pkg dot`.lines.to_a[1 .. -2].each do |line| | |
m = line.chomp.match /\A"([^"]+)" -> "([^"]+)"\z/ | |
revdep[pkgname m[2]] << pkgname(m[1]) | |
end | |
def revdep.dfs(pkg) | |
self[pkg].flat_map do |req| | |
[req] + dfs(req) | |
end.select { |p| self[p].empty? } | |
end | |
outdated = th.value | |
roots = [] | |
outdated.each do |pkg| | |
roots += revdep.dfs pkg | |
puts "cab uninstall -r #{pkg}" | |
end | |
if not roots.empty? | |
puts "cabal install -j#{JOBS} --haddock-hyperlink-source #{roots.uniq.join(' ')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment