* [U-Boot] [RFC PATCH] moveconfig: add a second pass for empty #if/#endif blocks
@ 2018-06-04 9:27 Chris Packham
2018-06-04 9:49 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Chris Packham @ 2018-06-04 9:27 UTC (permalink / raw)
To: 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 <judge.packham@gmail.com>
---
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.
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [RFC PATCH] moveconfig: add a second pass for empty #if/#endif blocks
2018-06-04 9:27 [U-Boot] [RFC PATCH] moveconfig: add a second pass for empty #if/#endif blocks Chris Packham
@ 2018-06-04 9:49 ` Andy Shevchenko
2018-06-05 0:56 ` Chris Packham
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2018-06-04 9:49 UTC (permalink / raw)
To: u-boot
On Mon, 2018-06-04 at 21:27 +1200, Chris Packham wrote:
> 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.
> + pattern = r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*'
Any reason not to use re.compile() ?
> + with open(header_path) as f:
> + data = f.read()
> +
> + new_data = re.sub(pattern, '\n', data, flags=re.M)
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [RFC PATCH] moveconfig: add a second pass for empty #if/#endif blocks
2018-06-04 9:49 ` Andy Shevchenko
@ 2018-06-05 0:56 ` Chris Packham
0 siblings, 0 replies; 3+ messages in thread
From: Chris Packham @ 2018-06-05 0:56 UTC (permalink / raw)
To: u-boot
On Mon, Jun 4, 2018 at 9:49 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Mon, 2018-06-04 at 21:27 +1200, Chris Packham wrote:
> > 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.
>
> > + pattern = r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*'
>
> Any reason not to use re.compile() ?
Laziness on my part. Will do in v2.
> > + with open(header_path) as f:
> > + data = f.read()
> > +
> > + new_data = re.sub(pattern, '\n', data, flags=re.M)
>
> --
> Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Intel Finland Oy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-05 0:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04 9:27 [U-Boot] [RFC PATCH] moveconfig: add a second pass for empty #if/#endif blocks Chris Packham
2018-06-04 9:49 ` Andy Shevchenko
2018-06-05 0:56 ` Chris Packham
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.