From patchwork Sat Nov 4 20:36:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 834231 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="enockQPn"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yTrGN6C1nz9t2Q for ; Sun, 5 Nov 2017 07:37:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 2D20989C9D; Sat, 4 Nov 2017 20:36:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c08hcovlct8o; Sat, 4 Nov 2017 20:36:54 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 7075789C64; Sat, 4 Nov 2017 20:36:54 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 893641C1111 for ; Sat, 4 Nov 2017 20:36:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 83F7B89C64 for ; Sat, 4 Nov 2017 20:36:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nrk2NcMkzZWj for ; Sat, 4 Nov 2017 20:36:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by hemlock.osuosl.org (Postfix) with ESMTPS id 695FD89C62 for ; Sat, 4 Nov 2017 20:36:52 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id a2so6608411lfh.11 for ; Sat, 04 Nov 2017 13:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6E1rya5OQXQBtY/CuvEJxz7ZlrSJcrlh5m4cAKWV16g=; b=enockQPnk4f6K0vfptkE03yCjuSNnXGyDApBl72MhOrYuj63ifrVL55/DtObZrj2OO khwPmWZ2ZogfTrj5y3d3ulD/Syt9h5zzbyqAPbcEEIl4nCSq9Cjucn1ZEBBrp7kKsrjc LdUyMUvFF0SxM51uo0NHOcDd/6t/SbxqgLIU69rlGjkkl7KIQtDmR3mdtapcPAbu35WC vGdjWtGDCChTZ/O3j/5YtOTuDS5TV7Wcnxi4rnTCGt31DIcUg8qhAOzLyObvj/EeEq4d r/JDyss95GPIYxW7NrGaGIDF0k/uH65h0qFhLSiSIDwILlfhnwDHb09wA/ZylV/Je77d QG8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6E1rya5OQXQBtY/CuvEJxz7ZlrSJcrlh5m4cAKWV16g=; b=qxiJFWwdIG6pcmabZsNAJcV8x2c//kwFEsNcXjCWZu7qNiWsf+lnt3u+ujfI8k/jqn Ra81VocY/cvig4qRnc24zCHt0oRvhWBJTldBj9VpymRBGnOliBr6znR3dNkrmWDH14z4 lhfdOPwvJjqI+dTvWFTJEPJXm8WmtSw387q2/BqgOwe59U911q46L559LqF75/hCF75t +mH4CtLT62RbrAYCujIk1VaV8S/7P8v9LzoX0qKAnZpCK1FS+W43bC+yi2oc6WlTtTbR f7uH4pHjvzqHG8Y//MwcWyQyw9U8DIqH6JMWPxmQhH8UteGvqlD6zO23tpHwvyjv4glU hc/w== X-Gm-Message-State: AMCzsaWPTJ9kRyV441wAihG725DAgW6CeMOG8dGAyJHYrFaQucntHR3B q3j0NjHUgENYY1p4VAr6hISQrw== X-Google-Smtp-Source: ABhQp+SfCd1ZoJNeli9ZBqK7fp5v8EFIV5r/V7jF11wF3Q5bgpiOLHQRqFLrVoLPmO5sTK5Qo7rXwQ== X-Received: by 10.46.34.66 with SMTP id i63mr4309825lji.45.1509827810342; Sat, 04 Nov 2017 13:36:50 -0700 (PDT) Received: from localhost.localdomain (c-2ec2d47d-74736162.cust.telenor.se. [46.194.212.125]) by smtp.gmail.com with ESMTPSA id 97sm1609925lft.74.2017.11.04.13.36.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Nov 2017 13:36:49 -0700 (PDT) From: Marcus Folkesson To: buildroot@buildroot.org Date: Sat, 4 Nov 2017 21:36:44 +0100 Message-Id: <20171104203644.4045-1-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.13.1 Subject: [Buildroot] [PATCH] utils/diffconfig: add diffconfig utility X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcus Folkesson MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "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 --- 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 F: package/libkcapi/ +N: Marcus Folkesson +F: utils/diffconfig + N: Marek Belisko 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] [ ] + +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()