-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathkconfig-bool-options.py
executable file
·50 lines (32 loc) · 1.16 KB
/
kconfig-bool-options.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
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
import os
import sys
import argparse
import json
from itertools import chain
sys.path.insert(0, str(os.path.join(os.environ["ZEPHYR_BASE"], "scripts", "kconfig")))
from kconfiglib import Kconfig, _T_BOOL, _T_CHOICE
def main():
args = parse_args()
kconf = Kconfig(args.kconfig_file)
kconf.load_config(args.dotconfig)
options = {}
for sym in chain(kconf.unique_defined_syms, kconf.unique_choices):
if not sym.name:
continue
if "-" in sym.name:
# Rust does not allow hyphens in cfg options.
continue
if sym.type in [_T_BOOL, _T_CHOICE]:
options[f"CONFIG_{sym.name}"] = sym.str_value
with open(args.outfile, "w") as f:
json.dump(options, f, indent=2, sort_keys=True)
def parse_args():
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument("kconfig_file", help="Top-level Kconfig file")
parser.add_argument("dotconfig", help="Path to dotconfig file")
parser.add_argument("outfile", help="Path to output file")
return parser.parse_args()
if __name__ == "__main__":
main()