My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__VERSION__ = '1.0.2'
__author__ = 'rx.wen218@gmail.com'

import sys
import os
from bcscope_utils import androidmk_parser
from optparse import OptionParser

modules = {}
def add_module_to_source(mod_name):
# do nothing if the module is already in modules collection
if mod_name in modules:
pass
else:
mod = all_modules.find_module(mod_name)
if mod:
modules[mod_name] = mod
for dep in mod.depends:
add_module_to_source(dep)

def transfer_to_dot_valid(name):
return name.replace("-", "_").replace(".", "_").replace("+", "")

def generate_dependency_graph(cmd_options):
dot_file_path = cmd_options.output_file
dot_file = open(dot_file_path, "w")
dot_file.write("digraph {\n")
for (mod_name, mod) in modules.items():
if cmd_options.module and mod.name == cmd_options.module:
#highlight target module
dot_file.write("%s[style=bold,color=\"tomato\",label=\"%s\l%s\"]\n"%(transfer_to_dot_valid(mod.name), mod.name, mod.directory))
else:
dot_file.write("%s[label=\"%s\l%s\"]\n"%(transfer_to_dot_valid(mod.name), mod.name, mod.directory))
for (mod_name, mod) in modules.items():
for dep in mod.depends:
dot_file.write("%s->%s\n"%(transfer_to_dot_valid(mod.name), transfer_to_dot_valid(dep)))
dot_file.write("}\n")
dot_file.close()

def parse_directory(dir_to_parse):
mk_files = androidmk_parser.find_android_mk(dir_to_parse)
all_modules = None
for mk_file in mk_files:
all_modules = androidmk_parser.parse_makefile(mk_file, all_modules)
return all_modules

if __name__ == "__main__":
# parse command line options
opt_parser = OptionParser(version = "%prog " + __VERSION__,
description = "command line tool for generating android dependency diagram",
usage = "%prog [OPTION] [dir_to_parse]")
opt_parser.add_option("-o", "--output", dest="output_file",
help="dot diagram file")
opt_parser.add_option("-m", "--module", dest="module",
help="only generate dependency diagram for specified module")
opt_parser.add_option("-l", "--listmodule", action="store_true", default=False,
help="only list modules defined in specified directory [default: %default]")
(cmdline_options, args) = opt_parser.parse_args()

dir_to_parse = os.path.curdir
if len(args) > 0:
dir_to_parse = args[0]

if not cmdline_options.listmodule:
if not cmdline_options.output_file:
print "must specify -o/--output option"
sys.exit(-1)
else:
android_root = androidmk_parser.find_root()
if android_root:
dir_to_parse = android_root
all_modules = parse_directory(dir_to_parse)
if not cmdline_options.module:
modules = all_modules.pool
else:
add_module_to_source(cmdline_options.module)
generate_dependency_graph(cmdline_options)
else:
all_modules = parse_directory(dir_to_parse)
for mod_name in all_modules.pool:
print mod_name


Change log

r301 by rx.wen218 on Feb 3, 2012   Diff
update adepends.py

highlight target module
Go to: 
Project members, sign in to write a code review

Older revisions

r300 by rx.wen218 on Jan 7, 2012   Diff
update adepends tool

- makefile function call can be used
in conjuction with normal string
- add more test cases
...
r299 by rx.wen218 on Dec 30, 2011   Diff
update adepends tool

- support dir, notdir, basename native
make functions
- expand module name that may contain
...
r298 by rx.wen218 on Dec 30, 2011   Diff
create adepends tool to generate
graphviz dot based diagram that
represents the dependecy relationship
between android modules
All revisions of this file

File info

Size: 3218 bytes, 86 lines

File properties

svn:executable
*
Powered by Google Project Hosting