From patchwork Mon Jun 4 09:27:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 924901 X-Patchwork-Delegate: yamada.m@jp.panasonic.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="P/NAMwD0"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40zqNs18j2z9s0x for ; Mon, 4 Jun 2018 19:28:13 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A7A37C21F2A; Mon, 4 Jun 2018 09:28:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2F613C21EFD; Mon, 4 Jun 2018 09:28:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6A5D8C21F21; Mon, 4 Jun 2018 09:27:57 +0000 (UTC) Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) by lists.denx.de (Postfix) with ESMTPS id 4F853C21F22 for ; Mon, 4 Jun 2018 09:27:57 +0000 (UTC) Received: by mail-pg0-f68.google.com with SMTP id 15-v6so13893508pge.2 for ; Mon, 04 Jun 2018 02:27:57 -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=3Bkp1zavQ93Ef2TVrolQ1z3Q7MZBBVuKCSlkxczFEpQ=; b=P/NAMwD0pz8w3PzGICD9zlblxytDywGs0CjoNIWvBnJp7f1NUXOBvtNPBFZSV2cQSg m446fu0YCOT/HpYCCjq6k+eCQNR3HVRYik7+eYMDmN2/cYKDx9QUXhUzc6D19mdjWslE W92oHjQJhQ9ajhB5tb8zRaJFi8AFC0EI/RyzzSZhdmP0+OOtsev1mXY2/CkZoQBRw8A4 Vx38CD0+RzOP0tzWMHCMYZYxp2RKRSJMWHNlR649+1sWDhU9FS45VlfsZc82phmBcli7 +lVXXJaRxLf/0X5dRi7ETUviNiTbmieozp9ofKD9GneLNlURgNww/SY7PsLiV18OFj7n TMFg== 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=3Bkp1zavQ93Ef2TVrolQ1z3Q7MZBBVuKCSlkxczFEpQ=; b=WYubS1+E3fd3SSIw+GDoVJIktst44tIim+E/yRXo3GFfGNIVS0ydGl3mRAttIsKsb5 TW9vgXrTZ3/I8PCoolRYxJGGLmnz+wIIw5sW6begGrIF5hcHEEHRSY7zj/5QIlMf52FE gVUywBCtCh/UiFmTIZaX8hTwZzFHeYtsXaLFRK9bINKYGcMJOitDG3UsGex+IvZgA7DH wCMVBPAht+9ojt27ehDZPvGhAM7NKa7FBGJL7baj7A4iZCGmqkFln8s8SBFIsARiSogv olAGhO3ZqA7aek2+Xsy911puyyKcIuoTamryuJbHgv9O+iCrcQUo2Gg4YBTa2Mr61FeV vhqA== X-Gm-Message-State: ALKqPwf3ii6sFKxOpvKxm4UgPhpyBsDK22/+2GQ8Q0a8nwmU3wJbrPxD YDFfwCJUwA9LjlVjCyX2/2w2nLcAmAw= X-Google-Smtp-Source: ADUXVKKuiM0yc5xVoqIaa2XMkYPcIbVH1cH3Ja5TKdsih8O0wgnO/meve4svSJ7rDKfco6YccGFThA== X-Received: by 2002:a63:ab05:: with SMTP id p5-v6mr16594974pgf.280.1528104475293; Mon, 04 Jun 2018 02:27:55 -0700 (PDT) Received: from chrisp-dl.ws.atlnz.lc ([2001:df5:b000:22:3a2c:4aff:fe70:2b02]) by smtp.gmail.com with ESMTPSA id 84-v6sm18644834pfl.186.2018.06.04.02.27.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Jun 2018 02:27:54 -0700 (PDT) From: Chris Packham To: u-boot@lists.denx.de Date: Mon, 4 Jun 2018 21:27:45 +1200 Message-Id: <20180604092745.22468-1-judge.packham@gmail.com> X-Mailer: git-send-email 2.17.0 Cc: Andy Shevchenko , Chris Packham Subject: [U-Boot] [RFC PATCH] moveconfig: add a second pass for empty #if/#endif blocks X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Moveconfig already attempts to remove empty #if/#endif blocks when there is a matching CONFIG_ being moved. Add a second pass which covers files without a match. Signed-off-by: Chris Packham --- I've plumbed this in as a second pass because ultimately we may want to make this a separate option. Also I couldn't figure out how to implement this without using re.M so I couldn't make it work in with the line by line parsing of cleanup_one_header(). tools/moveconfig.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/moveconfig.py b/tools/moveconfig.py index caa81ac2ed77..ff70925f9ee4 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -545,6 +545,28 @@ def confirm(options, prompt): return True +def cleanup_empty_blocks(header_path, options): + """Clean up empty conditional blocks + + Arguments: + header_path: path to the cleaned file. + options: option flags. + """ + pattern = r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*' + with open(header_path) as f: + data = f.read() + + new_data = re.sub(pattern, '\n', data, flags=re.M) + + show_diff(data.splitlines(True), new_data.splitlines(True), header_path, + options.color) + + if options.dry_run: + return + + with open(header_path, 'w') as f: + f.write(new_data) + def cleanup_one_header(header_path, patterns, options): """Clean regex-matched lines away from a file. @@ -626,8 +648,9 @@ def cleanup_headers(configs, options): continue for filename in filenames: if not fnmatch.fnmatch(filename, '*~'): - cleanup_one_header(os.path.join(dirpath, filename), - patterns, options) + header_path = os.path.join(dirpath, filename) + cleanup_one_header(header_path, patterns, options) + cleanup_empty_blocks(header_path, options) def cleanup_one_extra_option(defconfig_path, configs, options): """Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in one defconfig file.