aboutsummaryrefslogtreecommitdiff
path: root/tools/config.py
blob: 22defdda50091d56a1053ba64288be66d00a52df (plain)
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
#!/usr/bin/env python3

import argparse
from Kconfiglib import kconfiglib

def search(node, term):
    while node:
        if isinstance(node.item, kconfiglib.Symbol):
            if node.item.name == term:
                return node.item.str_value

        if node.list:
            r = search(node.list, term)
            if r is not None:
                return r

        node = node.next

def searchBug(node, term):
    bugs = ""

    while node:
        if isinstance(node.item, kconfiglib.Symbol):
            if node.item.name.startswith(term):
                if bugs is not "":
                    bugs += ";"
                bugs += node.item.name

        if node.list:
            r = searchBug(node.list, term)
            if r is not None and r is not "":
                if bugs is not "":
                    bugs += ";"
                bugs += r

        node = node.next
    return bugs

def main(args):
    kconf = kconfiglib.Kconfig(args.kconfig)
    if args.dotconfig is not None:
        kconf.load_config(args.dotconfig)

    i = ""
    if args.setting.endswith("BUG"):
        i = searchBug(kconf.top_node, args.setting)
    else:
        i = search(kconf.top_node, args.setting)

    if i is not None:
        print(i)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()

    parser.add_argument("--kconfig", metavar="Kconfig", nargs="?", default="Kconfig", help="Top-level Kconfig file (default: Kconfig)")

    parser.add_argument("--dotconfig", metavar="dotconfig", nargs="?", help=".config")

    parser.add_argument("setting", metavar="CONFIG_KEY", nargs="?", help="Top-level Kconfig file (default: Kconfig)")

    args = parser.parse_args()
    main(args)