OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from __future__ import print_function | 5 from __future__ import print_function |
6 | 6 |
7 import sys | 7 import sys |
8 import os | 8 import os |
9 | 9 |
10 from . import loader | 10 from . import loader |
11 | 11 |
12 | 12 |
13 _GRAPH_HEADER = """strict digraph { | 13 _GRAPH_HEADER = """strict digraph { |
14 concentrate = true; | 14 concentrate = true; |
15 ranksep = 2; | 15 ranksep = 2; |
16 nodesep = 0.25; | 16 nodesep = 0.25; |
17 """ | 17 """ |
18 | 18 |
19 _GRAPH_FOOTER = """} | 19 _GRAPH_FOOTER = """} |
20 """ | 20 """ |
21 | 21 |
22 | 22 |
23 def main(universe, ignore_packages, stdout): | 23 def main(universe, own_package, ignore_packages, stdout): |
24 packages = {} | 24 modulify = lambda dep: 'module_' + clean(dep) |
25 clean = lambda x: x.replace('.', '_dot_').replace('/', '_slash_').replace( | |
26 ':', '_colon_').replace('-', '_dash') | |
27 | |
25 module_to_package = {} | 28 module_to_package = {} |
26 edges = [] | 29 edges = [] |
27 for package, module_name in universe.loop_over_recipe_modules(): | 30 for package, module_name in universe.loop_over_recipe_modules(): |
28 mod = universe.load(package, module_name) | 31 mod = universe.load(package, module_name) |
29 | 32 |
30 for dep in mod.LOADED_DEPS: | 33 for dep in mod.LOADED_DEPS: |
31 edges.append((mod.NAME, dep)) | 34 edges.append(((True, mod.NAME), (True, dep))) |
Paweł Hajdan Jr.
2016/03/30 09:21:58
It's not clear what's the meaning of True here - c
| |
32 packages.setdefault(package.name, []).append(mod.NAME) | |
33 module_to_package[mod.NAME] = package.name | 35 module_to_package[mod.NAME] = package.name |
34 | 36 |
37 recipe_to_package = {} | |
38 universe_view = loader.UniverseView(universe, own_package) | |
39 for path, recipe_name in universe_view.loop_over_recipes(): | |
40 if 'example' in recipe_name: | |
Paweł Hajdan Jr.
2016/03/30 09:21:57
These are hacks. Can we just add command-line argu
| |
41 continue | |
42 | |
43 if 'clank' not in recipe_name: | |
44 continue | |
45 recipe = universe_view.load_recipe(recipe_name) | |
46 for dep in recipe.LOADED_DEPS: | |
47 edges.append(((False, recipe_name), (True, dep))) | |
Paweł Hajdan Jr.
2016/03/30 09:21:57
IMO recipes in the graph should be optional. I'd p
| |
48 recipe_to_package[recipe_name] = package | |
49 | |
35 print(_GRAPH_HEADER, file=stdout) | 50 print(_GRAPH_HEADER, file=stdout) |
36 for edge in edges: | 51 for edge in edges: |
37 if (module_to_package[edge[0]] in ignore_packages or | 52 (first_mod, first_name), (second_mod, second_name) = edge |
38 module_to_package[edge[1]] in ignore_packages): | 53 |
54 if first_mod: | |
55 if module_to_package[first_name] in ignore_packages: | |
56 continue | |
57 first_name = modulify(first_name) | |
Paweł Hajdan Jr.
2016/03/30 09:21:58
Why do we need calls to modulify?
That's probably
| |
58 else: | |
59 if recipe_to_package[first_name] in ignore_packages: | |
60 continue | |
61 | |
62 if module_to_package[second_name] in ignore_packages: | |
39 continue | 63 continue |
40 print(' %s -> %s' % (edge[0], edge[1]), file=stdout) | 64 second_name = modulify(second_name) |
65 | |
66 print(' %s -> %s' % (clean(first_name), second_name), file=stdout) | |
67 | |
68 packages = {} | |
69 for module, package in module_to_package.iteritems(): | |
70 packages.setdefault(package, []).append(module) | |
41 for package, modules in packages.iteritems(): | 71 for package, modules in packages.iteritems(): |
42 if package in ignore_packages: | 72 if package in ignore_packages: |
43 continue | 73 continue |
44 # The "cluster_" prefix has magic meaning for graphviz and makes it | 74 # The "cluster_" prefix has magic meaning for graphviz and makes it |
45 # draw a box around the subgraph. | 75 # draw a box around the subgraph. |
46 print(' subgraph "cluster_%s" { label="%s"; %s; }' % ( | 76 print(' subgraph "cluster_%s" { label="%s"; %s; }' % ( |
47 package, package, '; '.join(modules)), file=stdout) | 77 package, package, '; '.join( |
78 modulify(x) for x in modules)), file=stdout) | |
79 | |
80 recipe_names = [clean(name) for name in recipe_to_package.keys()] | |
81 print(' subgraph "cluster_recipes" { label="recipes"; %s; }' % ( | |
82 '; '.join(recipe_names)), file=stdout) | |
48 print(_GRAPH_FOOTER, file=stdout) | 83 print(_GRAPH_FOOTER, file=stdout) |
OLD | NEW |