1#!/usr/bin/env python3
2
3# This scripts check that all lines present in the defconfig are
4# still present in the .config
5
6import sys
7
8
9def main():
10    if not (len(sys.argv) == 3):
11        print("Error: incorrect number of arguments")
12        print("""Usage: check-dotconfig <configfile> <defconfig>""")
13        sys.exit(1)
14
15    configfile = sys.argv[1]
16    defconfig = sys.argv[2]
17
18    # strip() to get rid of trailing \n
19    with open(configfile) as configf:
20        configlines = [line.strip() for line in configf.readlines()]
21
22    defconfiglines = []
23    with open(defconfig) as defconfigf:
24        # strip() to get rid of trailing \n
25        for line in (line.strip() for line in defconfigf.readlines()):
26            if line.startswith("BR2_"):
27                defconfiglines.append(line)
28            elif line.startswith('# BR2_') and line.endswith(' is not set'):
29                defconfiglines.append(line)
30
31    # Check that all the defconfig lines are still present
32    missing = [line for line in defconfiglines if line not in configlines]
33
34    if missing:
35        print("WARN: defconfig {} can't be used:".format(defconfig))
36        for m in missing:
37            print("      Missing: {}".format(m))
38        sys.exit(1)
39
40
41if __name__ == "__main__":
42    main()
43