3 # diffconfig - a tool to compare .config files.
5 # originally written in 2006 by Matt Mackall
6 # (at least, this was in his bloatwatch source code)
7 # last worked on 2008 by Tim Bird
13 print("""Usage: diffconfig [-h] [-m] [<config1> <config2>]
15 Diffconfig is a simple utility for comparing two .config files.
16 Using standard diff to compare .config files often includes extraneous and
17 distracting information. This utility produces sorted output with only the
18 changes in configuration values between the two files.
20 Added and removed items are shown with a leading plus or minus, respectively.
21 Changed items show the old and new values on a single line.
23 If -m is specified, then output will be in "merge" style, which has the
24 changed and new values in kernel config option format.
26 If no config files are specified, .config and .config.old are used.
29 $ diffconfig .config config-with-some-changes
33 LOG_BUF_SHIFT 14 -> 16
38 # returns a dictionary of name/value pairs for config items in the file
39 def readconfig(config_file):
41 for line in config_file:
43 if line[:7] == "CONFIG_":
44 name, val = line[7:].split("=", 1)
46 if line[-11:] == " is not set":
50 def print_config(op, config, value, new_value):
56 print("# CONFIG_%s is not set" % config)
58 print("CONFIG_%s=%s" % (config, new_value))
61 print("-%s %s" % (config, value))
63 print("+%s %s" % (config, new_value))
65 print(" %s %s -> %s" % (config, value, new_value))
70 # parse command line args
71 if ("-h" in sys.argv or "--help" in sys.argv):
80 if not (argc==1 or argc == 3):
81 print("Error: incorrect number of arguments or unrecognized option")
85 # if no filenames given, assume .config and .config.old
87 if "KBUILD_OUTPUT" in os.environ:
88 build_dir = os.environ["KBUILD_OUTPUT"]+"/"
89 configa_filename = build_dir + ".config.old"
90 configb_filename = build_dir + ".config"
92 configa_filename = sys.argv[1]
93 configb_filename = sys.argv[2]
96 a = readconfig(open(configa_filename))
97 b = readconfig(open(configb_filename))
100 print("I/O error[%s]: %s\n" % (e.args[0],e.args[1]))
103 # print items in a but not b (accumulate, sort and print)
110 print_config("-", config, a[config], None)
113 # print items that changed (accumulate, sort, and print)
116 if a[config] != b[config]:
117 changed.append(config)
121 for config in changed:
122 print_config("->", config, a[config], b[config])
125 # now print items in b but not in a
126 # (items from b that were in a were removed above)
127 new = sorted(b.keys())
129 print_config("+", config, None, b[config])