forked from aosp-mirror/platform_build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soong_to_convert.py
executable file
·134 lines (107 loc) · 4.4 KB
/
soong_to_convert.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tool to prioritize which modules to convert to Soong.
Generally, you'd use this through the make integration, which automatically
generates the CSV input file that this tool expects:
$ m $OUT/soong_to_convert.txt
$ less $OUT/soong_to_convert.txt
The output is a list of modules that are probably ready to convert to Soong:
# Blocked on Module (potential problems)
283 libEGL (srcs_dotarm)
246 libicuuc (dotdot_incs dotdot_srcs)
221 libspeexresampler
215 libcamera_metadata
...
0 zram-perf (dotdot_incs)
The number at the beginning of the line shows how many native modules depend
on that module.
All of their dependencies have been satisfied, and any potential problems
that Make can detect are listed in parenthesis after the module:
dotdot_srcs: LOCAL_SRC_FILES contains paths outside $(LOCAL_PATH)
dotdot_incs: LOCAL_C_INCLUDES contains paths include '..'
srcs_dotarm: LOCAL_SRC_FILES contains source files like <...>.c.arm
aidl: LOCAL_SRC_FILES contains .aidl sources
objc: LOCAL_SRC_FILES contains Objective-C sources
proto: LOCAL_SRC_FILES contains .proto sources
rs: LOCAL_SRC_FILES contains renderscript sources
vts: LOCAL_SRC_FILES contains .vts sources
Not all problems can be discovered, but this is a starting point.
"""
from __future__ import print_function
import csv
import sys
def count_deps(depsdb, module, seen):
"""Based on the depsdb, count the number of transitive dependencies.
You can pass in an reversed dependency graph to conut the number of
modules that depend on the module."""
count = 0
seen.append(module)
if module in depsdb:
for dep in depsdb[module]:
if dep in seen:
continue
count += 1 + count_deps(depsdb, dep, seen)
return count
def process(reader):
"""Read the input file and produce a list of modules ready to move to Soong
"""
problems = dict()
deps = dict()
reverse_deps = dict()
module_types = dict()
for (module, module_type, problem, dependencies, makefiles, installed) in reader:
module_types[module] = module_type
problems[module] = problem
deps[module] = [d for d in dependencies.strip().split(' ') if d != ""]
for dep in deps[module]:
if not dep in reverse_deps:
reverse_deps[dep] = []
reverse_deps[dep].append(module)
results = []
for module in problems:
# Only display actionable conversions, ones without missing dependencies
if len(deps[module]) != 0:
continue
extra = ""
if len(problems[module]) > 0:
extra = " ({})".format(problems[module])
results.append((count_deps(reverse_deps, module, []), module + extra, module_types[module]))
return sorted(results, key=lambda result: (-result[0], result[1]))
def filter(results, module_type):
return [x for x in results if x[2] == module_type]
def display(results):
"""Displays the results"""
count_header = "# Blocked on"
count_width = len(count_header)
print("{} Module (potential problems)".format(count_header))
for (count, module, module_type) in results:
print("{:>{}} {}".format(count, count_width, module))
def main(filename):
"""Read the CSV file, print the results"""
with open(filename, 'rb') as csvfile:
results = process(csv.reader(csvfile))
native_results = filter(results, "native")
java_results = filter(results, "java")
print("native modules ready to convert")
display(native_results)
print("")
print("java modules ready to convert")
display(java_results)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("usage: soong_conversion.py <file>", file=sys.stderr)
sys.exit(1)
main(sys.argv[1])