forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_deps.rb
executable file
·96 lines (89 loc) · 2.04 KB
/
analyze_deps.rb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env ruby
require 'yaml'
require 'set'
Private = Struct.new(:name)
if ARGV.first == '--all'
ARGV.shift
elsif ARGV.first == '--no-private'
ARGV.shift
YAML::add_domain_type('developer.apple.com,2014', 'private') do |type, val|
nil
end
else
YAML::add_domain_type('developer.apple.com,2014', 'private') do |type, val|
Private.new(val)
end
end
files = {}
ARGV.each do |file|
yaml = YAML::load_file(file)
files[File.basename(file)] = yaml if yaml
end
YAML::dump(files)
# We cheat here and dump everything into the same bucket.
names = {}
files.each do |k, v|
v['provides'].each do |name|
names[name] ||= []
names[name] << k
end if v['provides']
v['nominals'].each do |name|
names[name] ||= []
names[name] << k
end if v['nominals']
v['class-members'].each do |name|
names[name] ||= []
names[name] << k
end if v['class-members']
end
all_deps = {}
all_private_deps = {}
files.each do |k, v|
deps = Set.new()
private_deps = Set.new()
v['top-level'].each do |name|
next unless name
if name.is_a? Private
private_deps.merge(names[name.name] || [])
else
deps.merge(names[name] || [])
end
end if v['top-level']
v['member-access'].each do |name|
next unless name
if name.is_a? Private
private_deps.merge(names[name.name] || [])
else
deps.merge(names[name] || [])
end
end if v['member-access']
v['dynamic-lookup'].each do |name|
next unless name
if name.is_a? Private
private_deps.merge(names[name.name] || [])
else
deps.merge(names[name] || [])
end
end if v['dynamic-lookup']
deps.delete(k)
private_deps.delete(k)
private_deps.subtract(deps)
all_deps[k] = deps.to_a.sort
all_private_deps[k] = private_deps.to_a.sort
end
# Graphviz output!
puts 'digraph dependencies {'
all_deps.each do |k, v|
v.each do |dep|
puts "\t\"#{dep}\" -> \"#{k}\""
end
if v.empty?
puts "\t\"#{k}\""
end
end
all_private_deps.each do |k, v|
v.each do |dep|
puts "\t\"#{dep}\" -> \"#{k}\" [style=dotted]"
end
end
puts '}'