cpp_dependency_graph 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitattributes +2 -0
- data/.rubocop_todo.yml +21 -0
- data/.vscode/launch.json +1 -1
- data/Gemfile +1 -1
- data/README.md +36 -4
- data/Rakefile +2 -0
- data/TODO.md +10 -2
- data/bin/console +2 -0
- data/cpp_dependency_graph.gemspec +7 -6
- data/docs/README.md +12 -0
- data/examples/leveldb_cyclic_deps.svg +1 -0
- data/examples/rethinkdb_cyclic_deps.svg +1 -0
- data/exe/cpp_dependency_graph +14 -8
- data/lib/cpp_dependency_graph.rb +33 -15
- data/lib/cpp_dependency_graph/bidirectional_hash.rb +14 -13
- data/lib/cpp_dependency_graph/circle_packing_visualiser.rb +20 -0
- data/lib/cpp_dependency_graph/component_dependency_graph.rb +56 -0
- data/lib/cpp_dependency_graph/config.rb +8 -0
- data/lib/cpp_dependency_graph/cycle_detector.rb +8 -10
- data/lib/cpp_dependency_graph/cyclic_link.rb +12 -15
- data/lib/cpp_dependency_graph/dir_tree.rb +41 -0
- data/lib/cpp_dependency_graph/file_dependency_graph.rb +56 -0
- data/lib/cpp_dependency_graph/graph_to_dot_visualiser.rb +38 -0
- data/lib/cpp_dependency_graph/graph_to_graphml_visualiser.rb +8 -0
- data/lib/cpp_dependency_graph/graph_to_html_visualiser.rb +25 -0
- data/lib/cpp_dependency_graph/include_dependency_graph.rb +21 -6
- data/lib/cpp_dependency_graph/include_to_component_resolver.rb +58 -0
- data/lib/cpp_dependency_graph/link.rb +42 -0
- data/lib/cpp_dependency_graph/project.rb +12 -30
- data/lib/cpp_dependency_graph/source_component.rb +8 -7
- data/lib/cpp_dependency_graph/source_file.rb +4 -3
- data/lib/cpp_dependency_graph/tsortable_hash.rb +1 -0
- data/lib/cpp_dependency_graph/version.rb +1 -1
- data/views/circle_packing.html.template +105 -0
- metadata +51 -25
- data/lib/cpp_dependency_graph/component_link.rb +0 -37
- data/lib/cpp_dependency_graph/dependency_graph.rb +0 -49
- data/lib/cpp_dependency_graph/graph_to_html_converter.rb +0 -7
- data/lib/cpp_dependency_graph/graph_visualiser.rb +0 -59
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
class ComponentLink
|
6
|
-
def initialize(source, target, cyclic = false)
|
7
|
-
@source = source
|
8
|
-
@target = target
|
9
|
-
@cyclic = cyclic
|
10
|
-
end
|
11
|
-
|
12
|
-
def source
|
13
|
-
@source
|
14
|
-
end
|
15
|
-
|
16
|
-
def target
|
17
|
-
@target
|
18
|
-
end
|
19
|
-
|
20
|
-
def cyclic?
|
21
|
-
@cyclic
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_s
|
25
|
-
if cyclic?
|
26
|
-
"#{source} <-> #{target}"
|
27
|
-
else
|
28
|
-
"#{source} -> #{target}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_json(*a)
|
33
|
-
{ json_class: self.class.name,
|
34
|
-
source: source, target: target, cyclic: cyclic?
|
35
|
-
}.to_json(*a)
|
36
|
-
end
|
37
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'project'
|
4
|
-
require_relative 'component_link'
|
5
|
-
require_relative 'cycle_detector'
|
6
|
-
|
7
|
-
# Returns a hash of component links
|
8
|
-
class DependencyGraph
|
9
|
-
def initialize(project)
|
10
|
-
@project = project
|
11
|
-
end
|
12
|
-
|
13
|
-
def components
|
14
|
-
@components ||= source_components
|
15
|
-
end
|
16
|
-
|
17
|
-
def all_component_links
|
18
|
-
@all_component_links ||= build_hash_component_links
|
19
|
-
end
|
20
|
-
|
21
|
-
def component_links(name)
|
22
|
-
return {} unless all_component_links.key?(name)
|
23
|
-
incoming_links(name).merge(outgoing_links(name))
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def build_hash_component_links
|
29
|
-
raw_links = @project.source_components.map { |c| [c.name, @project.dependencies(c)] }.to_h
|
30
|
-
cycle_detector = CycleDetector.new(raw_links)
|
31
|
-
component_links = raw_links.map do |source, links|
|
32
|
-
c_links = links.map { |target| ComponentLink.new(source, target, cycle_detector.cyclic?(source, target)) }
|
33
|
-
[source, c_links]
|
34
|
-
end.to_h
|
35
|
-
component_links
|
36
|
-
end
|
37
|
-
|
38
|
-
def outgoing_links(name)
|
39
|
-
all_component_links.slice(name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def incoming_links(target)
|
43
|
-
incoming_c_links = all_component_links.select { |c, c_links| c_links.any? { |link| link.target == target } }
|
44
|
-
incoming_c_links.map do |c_name, _|
|
45
|
-
link = ComponentLink.new(c_name, target, false)
|
46
|
-
[c_name, [link]]
|
47
|
-
end.to_h
|
48
|
-
end
|
49
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'graphviz'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
class GraphVisualiser
|
7
|
-
def generate_dot_file(deps, file)
|
8
|
-
@g = Graphviz::Graph.new(name = 'dependency_graph')
|
9
|
-
|
10
|
-
node_names = deps.flat_map do |_, links|
|
11
|
-
links.map { |link| [link.source, link.target] }.flatten
|
12
|
-
end.uniq
|
13
|
-
nodes = node_names.map { |name| [name, create_node(name)] }.to_h
|
14
|
-
|
15
|
-
deps.each do |source, links|
|
16
|
-
links.each do |link|
|
17
|
-
connection = nodes[source].connect(nodes[link.target])
|
18
|
-
connection.attributes[:color] = 'red' if link.cyclic?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
File.write(file, @g.to_dot)
|
23
|
-
# Graphviz::output(g, path: 'file') # TODO: https://github.com/ioquatix/graphviz/issues/7
|
24
|
-
end
|
25
|
-
|
26
|
-
def generate_html_file(deps, file)
|
27
|
-
node_names = deps.flat_map do |_, links|
|
28
|
-
links.map { |link| [link.source, link.target] }.flatten
|
29
|
-
end.uniq
|
30
|
-
nodes = node_names.map { |name| { name: name } }
|
31
|
-
|
32
|
-
connections = deps.flat_map do |_, links|
|
33
|
-
links.map do |link|
|
34
|
-
{ source: link.source, dest: link.target }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
json_nodes = JSON.pretty_generate(nodes)
|
39
|
-
json_connections = JSON.pretty_generate(connections)
|
40
|
-
# File.write(file, json_nodes + json_connections)
|
41
|
-
|
42
|
-
template_file = resolve_file_path('views/index.html.template')
|
43
|
-
template = File.read(template_file)
|
44
|
-
contents = template % { dependency_links: json_connections }
|
45
|
-
File.write(file, contents)
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def create_node(name)
|
51
|
-
node = @g.add_node(name)
|
52
|
-
node.attributes[:shape] = 'box3d'
|
53
|
-
node
|
54
|
-
end
|
55
|
-
|
56
|
-
def resolve_file_path(path)
|
57
|
-
File.expand_path("../../../#{path}", __FILE__)
|
58
|
-
end
|
59
|
-
end
|