A tool to compare kernel config files.
[linux-2.6.git] / configs / compare
1 #!/bin/env python
2 #
3 # compare: a tool to compare kernel config files
4 #
5 # Marc E. Fiuczynski <mef@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
7 #
8 # $Id:$
9 #
10
11 import sys, re, os
12
13 def process(file):
14     ORDER = []
15     CONFIGS = {}
16     for line in file.readlines():
17         iline = line.lower()
18
19         offset=iline.find(" is not set")
20         if offset <> -1:
21             config = line[line.find("CONFIG"):offset].strip()
22             if CONFIGS.has_key(config): print "duplicate entry %s" % config
23             CONFIGS[config]=0
24             ORDER.append(config)
25             continue
26
27         offset = iline.find("=y")
28         if offset  <> -1:
29             config = line[line.find("CONFIG"):offset].strip()
30             if CONFIGS.has_key(config): print "duplicate entry %s" % config
31             CONFIGS[config]=1
32             ORDER.append(config)
33             continue
34
35         offset = iline.find("=m")
36         if iline.find("=m") <> -1:
37             config = line[line.find("CONFIG"):offset].strip()
38             if CONFIGS.has_key(config): print "duplicate entry %s" % config
39             CONFIGS[config]=2
40             ORDER.append(config)
41             continue
42
43     return (CONFIGS,ORDER)
44
45
46 showall=False
47 args = sys.argv[1:]
48
49 if len(args) <=1:
50     name = os.path.basename(sys.argv[0])
51     print "USAGE: %s [options] from.config to.config" % name
52     print """
53 Options
54     -a    Show all differences
55
56 State Legend
57     A     Added config (exists in to.config, but not in from.config)
58     R     Removed config (exists in from.config, but not in to.config)
59     B     Builtin
60     M     Module
61     D     Disabled
62     """
63     sys.exit(0)
64
65 if args[0] == "-a":
66     showall = True
67     args = args[1:]
68
69 (old,oldorder)= process(open(args[0]))
70 (new,neworder)= process(open(args[1]))
71
72 oldstate = {-1:'A',0:'D',1:'B',2:'M'}
73 newstate = {-1:'R',0:'D',1:'B',2:'M'}
74
75 keys = neworder
76 for key in keys:
77     o = old.get(key,-1)
78     n = new[key]
79     if n==o and not showall: continue
80     print "%c -> %c : %s" % (newstate[o],newstate[n],key)
81
82 # not sure we care about what options have been removed
83 # from from.config file
84 sys.exit(0)
85 keys = oldorder
86 for key in keys:
87     n = new.get(key,-1)
88     o = old[key]
89     if n == -1 and not showall:
90         print "%c -> %c : %s" % (oldstate[o],oldstate[n],key)
91