diff options
author | Tim Bird <tim.bird@am.sony.com> | 2008-06-24 13:56:06 -0400 |
---|---|---|
committer | Sam Ravnborg <sam@ravnborg.org> | 2008-07-25 16:12:41 -0400 |
commit | a717417e7f96ad2c6c3d80cdd0836e49597399a3 (patch) | |
tree | 4bd3ae1990f1d6646b8c8f02832c33fa2206b9f2 | |
parent | c28ca3aaa1f08877ac0da7efcfead71a08490d65 (diff) |
kconfig: add diffconfig utility
Diffconfig is a simple utility for comparing two kernel configuration files.
See usage in the script for more info.
Signed-off-by: Tim Bird <tim.bird@am.sony.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
-rwxr-xr-x | scripts/diffconfig | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/scripts/diffconfig b/scripts/diffconfig new file mode 100755 index 000000000000..b91f3e34d44d --- /dev/null +++ b/scripts/diffconfig | |||
@@ -0,0 +1,129 @@ | |||
1 | #!/usr/bin/python | ||
2 | # | ||
3 | # diffconfig - a tool to compare .config files. | ||
4 | # | ||
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 | ||
8 | # | ||
9 | |||
10 | import sys, os | ||
11 | |||
12 | def usage(): | ||
13 | print """Usage: diffconfig [-h] [-m] [<config1> <config2>] | ||
14 | |||
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. | ||
19 | |||
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. | ||
22 | |||
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. | ||
25 | |||
26 | If no config files are specified, .config and .config.old are used. | ||
27 | |||
28 | Example usage: | ||
29 | $ diffconfig .config config-with-some-changes | ||
30 | -EXT2_FS_XATTR n | ||
31 | -EXT2_FS_XIP n | ||
32 | CRAMFS n -> y | ||
33 | EXT2_FS y -> n | ||
34 | LOG_BUF_SHIFT 14 -> 16 | ||
35 | PRINTK_TIME n -> y | ||
36 | """ | ||
37 | sys.exit(0) | ||
38 | |||
39 | # returns a dictionary of name/value pairs for config items in the file | ||
40 | def readconfig(config_file): | ||
41 | d = {} | ||
42 | for line in config_file: | ||
43 | line = line[:-1] | ||
44 | if line[:7] == "CONFIG_": | ||
45 | name, val = line[7:].split("=", 1) | ||
46 | d[name] = val | ||
47 | if line[-11:] == " is not set": | ||
48 | d[line[9:-11]] = "n" | ||
49 | return d | ||
50 | |||
51 | def print_config(op, config, value, new_value): | ||
52 | global merge_style | ||
53 | |||
54 | if merge_style: | ||
55 | if new_value: | ||
56 | if new_value=="n": | ||
57 | print "# CONFIG_%s is not set" % config | ||
58 | else: | ||
59 | print "CONFIG_%s=%s" % (config, new_value) | ||
60 | else: | ||
61 | if op=="-": | ||
62 | print "-%s %s" % (config, value) | ||
63 | elif op=="+": | ||
64 | print "+%s %s" % (config, new_value) | ||
65 | else: | ||
66 | print " %s %s -> %s" % (config, value, new_value) | ||
67 | |||
68 | def main(): | ||
69 | global merge_style | ||
70 | |||
71 | # parse command line args | ||
72 | if ("-h" in sys.argv or "--help" in sys.argv): | ||
73 | usage() | ||
74 | |||
75 | merge_style = 0 | ||
76 | if "-m" in sys.argv: | ||
77 | merge_style = 1 | ||
78 | sys.argv.remove("-m") | ||
79 | |||
80 | argc = len(sys.argv) | ||
81 | if not (argc==1 or argc == 3): | ||
82 | print "Error: incorrect number of arguments or unrecognized option" | ||
83 | usage() | ||
84 | |||
85 | if argc == 1: | ||
86 | # if no filenames given, assume .config and .config.old | ||
87 | build_dir="" | ||
88 | if os.environ.has_key("KBUILD_OUTPUT"): | ||
89 | build_dir = os.environ["KBUILD_OUTPUT"]+"/" | ||
90 | |||
91 | configa_filename = build_dir + ".config.old" | ||
92 | configb_filename = build_dir + ".config" | ||
93 | else: | ||
94 | configa_filename = sys.argv[1] | ||
95 | configb_filename = sys.argv[2] | ||
96 | |||
97 | a = readconfig(file(configa_filename)) | ||
98 | b = readconfig(file(configb_filename)) | ||
99 | |||
100 | # print items in a but not b (accumulate, sort and print) | ||
101 | old = [] | ||
102 | for config in a: | ||
103 | if config not in b: | ||
104 | old.append(config) | ||
105 | old.sort() | ||
106 | for config in old: | ||
107 | print_config("-", config, a[config], None) | ||
108 | del a[config] | ||
109 | |||
110 | # print items that changed (accumulate, sort, and print) | ||
111 | changed = [] | ||
112 | for config in a: | ||
113 | if a[config] != b[config]: | ||
114 | changed.append(config) | ||
115 | else: | ||
116 | del b[config] | ||
117 | changed.sort() | ||
118 | for config in changed: | ||
119 | print_config("->", config, a[config], b[config]) | ||
120 | del b[config] | ||
121 | |||
122 | # now print items in b but not in a | ||
123 | # (items from b that were in a were removed above) | ||
124 | new = b.keys() | ||
125 | new.sort() | ||
126 | for config in new: | ||
127 | print_config("+", config, None, b[config]) | ||
128 | |||
129 | main() | ||