summaryrefslogtreecommitdiff
path: root/bin/kconfig-expand-includes
blob: 058cfd27bac3e9b9fff2fd29801fb2922943782a (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
#!/usr/bin/env python3

import re
import sys


def main(filename):
    root = "/".join(filename.split("/")[:-1])
    with open(filename, "r") as f:
        lines = f.readlines()
    i = 0
    while i < len(lines):
        line = lines[i]
        if line.lower().startswith("source"):
            included_file = re.sub(r"\s+", " ", line).strip().split("source ")[1]
            included_file = re.sub(r"""['"]""", "", included_file.strip())
            with open(f"{root}/{included_file}", "r") as f:
                lines = lines[:i] + f.readlines() + lines[i + 1 :]
        i += 1

    print("".join(lines))


if __name__ == "__main__":
    main(sys.argv[1])