2 # SPDX-License-Identifier: GPL-2.0
4 # diffconfig - a tool to compare .config files.
6 # originally written in 2006 by Matt Mackall
7 # (at least, this was in his bloatwatch source code)
8 # last worked on 2008 by Tim Bird
14 print("""Usage: diffconfig [-h] [-m] [<config1> <config2>]
16 Diffconfig is a simple utility for comparing two .config files.
17 Using standard diff to compare .config files often includes extraneous and
18 distracting information. This utility produces sorted output with only the
19 changes in configuration values between the two files.
21 Added and removed items are shown with a leading plus or minus, respectively.
22 Changed items show the old and new values on a single line.
24 If -m is specified, then output will be in "merge" style, which has the
25 changed and new values in kernel config option format.
27 If no config files are specified, .config and .config.old are used.
30 $ diffconfig .config config-with-some-changes
34 LOG_BUF_SHIFT 14 -> 16
39 # returns a dictionary of name/value pairs for config items in the file
40 def readconfig(config_file):
42 for line in config_file:
44 if line[:7] == "CONFIG_":
45 name, val = line[7:].split("=", 1)
47 if line[-11:] == " is not set":
51 def print_config(op, config, value, new_value):
57 print("# CONFIG_%s is not set" % config)
59 print("CONFIG_%s=%s" % (config, new_value))
62 print("-%s %s" % (config, value))
64 print("+%s %s" % (config, new_value))
66 print(" %s %s -> %s" % (config, value, new_value))
71 # parse command line args
72 if ("-h" in sys.argv or "--help" in sys.argv):
81 if not (argc==1 or argc == 3):
82 print("Error: incorrect number of arguments or unrecognized option")
86 # if no filenames given, assume .config and .config.old
88 if "KBUILD_OUTPUT" in os.environ:
89 build_dir = os.environ["KBUILD_OUTPUT"]+"/"
90 configa_filename = build_dir + ".config.old"
91 configb_filename = build_dir + ".config"
93 configa_filename = sys.argv[1]
94 configb_filename = sys.argv[2]
97 a = readconfig(open(configa_filename))
98 b = readconfig(open(configb_filename))
100 e = sys.exc_info()[1]
101 print("I/O error[%s]: %s\n" % (e.args[0],e.args[1]))
104 # print items in a but not b (accumulate, sort and print)
111 print_config("-", config, a[config], None)
114 # print items that changed (accumulate, sort, and print)
117 if a[config] != b[config]:
118 changed.append(config)
122 for config in changed:
123 print_config("->", config, a[config], b[config])
126 # now print items in b but not in a
127 # (items from b that were in a were removed above)
128 new = sorted(b.keys())
130 print_config("+", config, None, b[config])