forked from hckuo2/Cozart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify_config.py
executable file
·82 lines (67 loc) · 1.92 KB
/
classify_config.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
#!/usr/bin/env python3
import kconfiglib
import os
import sys
HWDIRS=["drivers", "arch", "sound"]
kconf = kconfiglib.Kconfig(warn=False)
def is_constant_y(sym):
return sym.is_constant and (kconfiglib.expr_value(sym) == 2)
def _find_deps(dep, result, level):
if type(dep) is tuple:
relation = dep[0]
if relation == kconfiglib.AND:
for i in dep[1:]:
_find_deps(i, result, level + 1)
if relation == kconfiglib.EQUAL and is_constant_y(dep[2]):
result.add(dep[1].name)
elif type(dep) is kconfiglib.Symbol:
if is_constant_y(dep):
return
if dep.name not in result:
result.add(dep.name)
_find_deps(dep.direct_dep, result, level + 1)
def find_deps(sym):
result = set()
_find_deps(sym.direct_dep, result, 0)
return result
def has_menunode(sym):
return hasattr(sym, 'nodes') and len(sym.nodes) > 0
def has_multimenunodes(sym):
return hasattr(sym, 'nodes') and len(sym.nodes) > 1
def is_hw(sym):
subdir = sym.nodes[0].filename.split("/")[0]
return subdir in HWDIRS
def is_sw(sym):
return not is_hw(sym)
def get_deps(deps, result):
if type(deps) in [kconfiglib.Symbol, kconfiglib.Choice]:
return result.append(deps)
else:
for d in deps[1:]:
result.append(d)
get_deps(d, result)
def print_deps(sym):
deps = []
get_deps(sym, deps)
for s in deps:
print(s.name)
if __name__ == '__main__':
hw = 0
hb = 0
sw = 0
exceptions = 0
syms = kconf.syms
# for s in syms:
# if has_multimenunodes(syms[s]):
# print(s)
for line in sys.stdin:
deps = []
line = line.strip()
name = line.replace("CONFIG_", "")
if name not in syms:
continue
sym = syms[name]
if is_hw(sym):
print(line, "hw")
else:
print(line, "sw")