All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] utils/diffconfig: add diffconfig utility
@ 2017-11-04 20:36 Marcus Folkesson
  2017-11-25 12:50 ` Thomas Petazzoni
  0 siblings, 1 reply; 3+ messages in thread
From: Marcus Folkesson @ 2017-11-04 20:36 UTC (permalink / raw)
  To: buildroot

Diffconfig is a simple utility for comparing two configuration files.
See usage in the script for more info.

Borrowed from the Linux kernel source code and adapted to Buildroot.

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
 DEVELOPERS       |   3 ++
 utils/diffconfig | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100755 utils/diffconfig

diff --git a/DEVELOPERS b/DEVELOPERS
index c651bf26fa..ccc626df7e 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -996,6 +996,9 @@ F:	package/turbolua/
 N:	Marcin Nowakowski <marcin.nowakowski@imgtec.com>
 F:	package/libkcapi/
 
+N:	Marcus Folkesson <marcus.folkesson@gmail.com>
+F:	utils/diffconfig
+
 N:	Marek Belisko <marek.belisko@open-nandra.com>
 F:	package/libatasmart/
 F:	package/polkit/
diff --git a/utils/diffconfig b/utils/diffconfig
new file mode 100755
index 0000000000..5862a62f25
--- /dev/null
+++ b/utils/diffconfig
@@ -0,0 +1,136 @@
+#!/usr/bin/python
+#
+# diffconfig - a tool to compare .config files.
+#
+# originally written in 2006 by Matt Mackall
+#  (at least, this was in his bloatwatch source code)
+# last worked on 2008 by Tim Bird for the Linux kernel
+# Adapted to Buildroot 2017 by Marcus Folkesson
+#
+
+import sys, os
+
+def usage():
+    print("""Usage: diffconfig [-h] [-m] [<config1> <config2>]
+
+Diffconfig is a simple utility for comparing two .config files.
+Using standard diff to compare .config files often includes extraneous and
+distracting information.  This utility produces sorted output with only the
+changes in configuration values between the two files.
+
+Added and removed items are shown with a leading plus or minus, respectively.
+Changed items show the old and new values on a single line.
+
+If -m is specified, then output will be in "merge" style, which has the
+changed and new values in kernel config option format.
+
+If no config files are specified, .config and .config.old are used.
+
+Example usage:
+ $ diffconfig .config config-with-some-changes
+-LINUX_KERNEL_INTREE_DTS_NAME "vexpress-v2p-ca9"
+ LINUX_KERNEL_DTS_SUPPORT y -> n
+ LINUX_KERNEL_USE_INTREE_DTS y -> n
+ PACKAGE_DFU_UTIL n -> y
+ PACKAGE_LIBUSB n -> y
+ TARGET_GENERIC_HOSTNAME "buildroot" -> "Tuxie"
+ TARGET_GENERIC_ISSUE "Welcome to Buildroot" -> "Welcome to CustomBoard"
++PACKAGE_LIBUSB_COMPAT n
+
+""")
+    sys.exit(0)
+
+# returns a dictionary of name/value pairs for config items in the file
+def readconfig(config_file):
+    d = {}
+    for line in config_file:
+        line = line[:-1]
+        if line[:4] == "BR2_":
+            name, val = line[4:].split("=", 1)
+            d[name] = val
+        if line[-11:] == " is not set":
+            d[line[6:-11]] = "n"
+    return d
+
+def print_config(op, config, value, new_value):
+    global merge_style
+
+    if merge_style:
+        if new_value:
+            if new_value=="n":
+                print("# BR2_%s is not set" % config)
+            else:
+                print("BR2_%s=%s" % (config, new_value))
+    else:
+        if op=="-":
+            print("-%s %s" % (config, value))
+        elif op=="+":
+            print("+%s %s" % (config, new_value))
+        else:
+            print(" %s %s -> %s" % (config, value, new_value))
+
+def main():
+    global merge_style
+
+    # parse command line args
+    if ("-h" in sys.argv or "--help" in sys.argv):
+        usage()
+
+    merge_style = 0
+    if "-m" in sys.argv:
+        merge_style = 1
+        sys.argv.remove("-m")
+
+    argc = len(sys.argv)
+    if not (argc==1 or argc == 3):
+        print("Error: incorrect number of arguments or unrecognized option")
+        usage()
+
+    if argc == 1:
+        # if no filenames given, assume .config and .config.old
+        build_dir=""
+        if "KBUILD_OUTPUT" in os.environ:
+            build_dir = os.environ["KBUILD_OUTPUT"]+"/"
+        configa_filename = build_dir + ".config.old"
+        configb_filename = build_dir + ".config"
+    else:
+        configa_filename = sys.argv[1]
+        configb_filename = sys.argv[2]
+
+    try:
+        a = readconfig(open(configa_filename))
+        b = readconfig(open(configb_filename))
+    except (IOError):
+        e = sys.exc_info()[1]
+        print("I/O error[%s]: %s\n" % (e.args[0],e.args[1]))
+        usage()
+
+    # print items in a but not b (accumulate, sort and print)
+    old = []
+    for config in a:
+        if config not in b:
+            old.append(config)
+    old.sort()
+    for config in old:
+        print_config("-", config, a[config], None)
+        del a[config]
+
+    # print items that changed (accumulate, sort, and print)
+    changed = []
+    for config in a:
+        if a[config] != b[config]:
+            changed.append(config)
+        else:
+            del b[config]
+    changed.sort()
+    for config in changed:
+        print_config("->", config, a[config], b[config])
+        del b[config]
+
+    # now print items in b but not in a
+    # (items from b that were in a were removed above)
+    new = sorted(b.keys())
+    for config in new:
+        print_config("+", config, None, b[config])
+
+main()
-- 
2.13.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH] utils/diffconfig: add diffconfig utility
  2017-11-04 20:36 [Buildroot] [PATCH] utils/diffconfig: add diffconfig utility Marcus Folkesson
@ 2017-11-25 12:50 ` Thomas Petazzoni
  2017-11-25 16:45   ` Arnout Vandecappelle
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni @ 2017-11-25 12:50 UTC (permalink / raw)
  To: buildroot

Hello,

On Sat,  4 Nov 2017 21:36:44 +0100, Marcus Folkesson wrote:
> Diffconfig is a simple utility for comparing two configuration files.
> See usage in the script for more info.
> 
> Borrowed from the Linux kernel source code and adapted to Buildroot.
> 
> Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
> ---
>  DEVELOPERS       |   3 ++
>  utils/diffconfig | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 139 insertions(+)
>  create mode 100755 utils/diffconfig

I've applied to next. However, I must say I've personally not be very
convinced by the output of this tool. If you generate the .config
corresponding to an empty defconfig on one side, and the following
defconfig on the other side:

BR2_arm=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-2017.11-rc1.tar.bz2"
BR2_TOOLCHAIN_EXTERNAL_GCC_4_9=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y
BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
# BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_INIT_NONE=y
BR2_SYSTEM_BIN_SH_NONE=y
# BR2_PACKAGE_BUSYBOX is not set
BR2_PACKAGE_BELLAGIO=y
BR2_PACKAGE_FFMPEG=y
# BR2_TARGET_ROOTFS_TAR is not set

You will get a very, very, very noisy output with "diffconfig". And
comparately, the diff between the defconfigs is a lot more readable.

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH] utils/diffconfig: add diffconfig utility
  2017-11-25 12:50 ` Thomas Petazzoni
@ 2017-11-25 16:45   ` Arnout Vandecappelle
  0 siblings, 0 replies; 3+ messages in thread
From: Arnout Vandecappelle @ 2017-11-25 16:45 UTC (permalink / raw)
  To: buildroot



On 25-11-17 13:50, Thomas Petazzoni wrote:
> Hello,
> 
> On Sat,  4 Nov 2017 21:36:44 +0100, Marcus Folkesson wrote:
>> Diffconfig is a simple utility for comparing two configuration files.
>> See usage in the script for more info.
>>
>> Borrowed from the Linux kernel source code and adapted to Buildroot.
>>
>> Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
>> ---
>>  DEVELOPERS       |   3 ++
>>  utils/diffconfig | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 139 insertions(+)
>>  create mode 100755 utils/diffconfig
> 
> I've applied to next. However, I must say I've personally not be very
> convinced by the output of this tool. If you generate the .config
> corresponding to an empty defconfig on one side, and the following
> defconfig on the other side:
> 
> BR2_arm=y
> BR2_TOOLCHAIN_EXTERNAL=y
> BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
> BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
> BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-2017.11-rc1.tar.bz2"
> BR2_TOOLCHAIN_EXTERNAL_GCC_4_9=y
> BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y
> BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
> # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
> BR2_TOOLCHAIN_EXTERNAL_CXX=y
> BR2_INIT_NONE=y
> BR2_SYSTEM_BIN_SH_NONE=y
> # BR2_PACKAGE_BUSYBOX is not set
> BR2_PACKAGE_BELLAGIO=y
> BR2_PACKAGE_FFMPEG=y
> # BR2_TARGET_ROOTFS_TAR is not set
> 
> You will get a very, very, very noisy output with "diffconfig". And
> comparately, the diff between the defconfigs is a lot more readable.

 Well, it's not really meant for that kind of situation. It's meant for a
situation where you would normally diff the full configs because you want to see
which packages have been implicitly added or removed (due to select or depends).
You'd normally do a diff .config.old .config, but then you get a lot of changes
that are due to packages that have become available but are not selected - not
very interesting. So in this case, diffconfig gives more compact and readable
results.

 Regards,
 Arnout

-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-25 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-04 20:36 [Buildroot] [PATCH] utils/diffconfig: add diffconfig utility Marcus Folkesson
2017-11-25 12:50 ` Thomas Petazzoni
2017-11-25 16:45   ` Arnout Vandecappelle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.