Created
June 9, 2014 21:03
-
-
Save pcarrier/48d6731200032d914e78 to your computer and use it in GitHub Desktop.
This file contains 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/env ruby | |
require 'yaml' | |
require 'murmurhash3' | |
require 'bundler' | |
require 'set' | |
def node_for name | |
"n#{MurmurHash3::V32.str_hash(name).to_s(16)}" | |
end | |
def gem_for_path path | |
path.gsub(/-[0-9.]+/, '') | |
end | |
RED_GEMS = `find . -name '*.so'`.lines.collect {|l| l.scan /(?<=gems\/)[^\/]+/}.flatten.uniq.map {|p| gem_for_path p} | |
DESCRIBED = Set.new | |
def describe name | |
unless DESCRIBED.include? name | |
DESCRIBED << name | |
if RED_GEMS.include? name | |
puts "#{node_for name} [label=\"#{name}\",fontcolor=red]" | |
else | |
puts "#{node_for name} [label=\"#{name}\"]" | |
end | |
end | |
end | |
lockfile = IO::read 'Gemfile.lock' | |
deps = Hash.new { |h,k| h[k] = [] } | |
name = '' | |
lockfile.lines.each do |line| | |
if line.start_with? ' ' | |
deps[name] <<= line.split(/ +/)[1] | |
elsif line.start_with? ' ' | |
name = line.split(/ +/)[1].chomp | |
end | |
end | |
puts 'digraph G {node [shape=plaintext]; splines="off"' | |
deps.sort_by{|k,vs|vs.length}.each do |k, vs| | |
describe k | |
vs.each do |v| | |
describe v | |
puts "#{node_for k} -> #{node_for v}" | |
end | |
end | |
puts '}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment