public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chris Packham <judge.packham@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3] moveconfig: add a second pass for empty #if/#endif blocks
Date: Wed, 30 Jan 2019 20:23:16 +1300	[thread overview]
Message-ID: <20190130072316.20837-1-judge.packham@gmail.com> (raw)

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 <judge.packham@gmail.com>
---
This was previously submitted as
http://patchwork.ozlabs.org/patch/924901/ there still seems to be cases
of #if/#endif left over from Kconfig migrations so perhaps this is still
needed/wanted.

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().

Changes in v3:
- drop rfc

Changes in v2:
- use re.compile

 tools/moveconfig.py | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index caa81ac2ed77..1a214c560546 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 = re.compile(r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*', flags=re.M)
+    with open(header_path) as f:
+        data = f.read()
+
+    new_data = pattern.sub('\n', data)
+
+    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.
-- 
2.20.1

             reply	other threads:[~2019-01-30  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-30  7:23 Chris Packham [this message]
2019-01-30  8:55 ` [U-Boot] [PATCH v3] moveconfig: add a second pass for empty #if/#endif blocks Masahiro Yamada
2019-01-31  6:25   ` Masahiro Yamada
2019-01-31  9:05     ` Chris Packham
2019-02-10 13:08 ` [U-Boot] [U-Boot, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190130072316.20837-1-judge.packham@gmail.com \
    --to=judge.packham@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox