mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 08:42:12 +02:00
moveconfig: add a second pass for empty #if/#endif blocks
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 commit is contained in:
@@ -545,6 +545,28 @@ def confirm(options, prompt):
|
|||||||
|
|
||||||
return True
|
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):
|
def cleanup_one_header(header_path, patterns, options):
|
||||||
"""Clean regex-matched lines away from a file.
|
"""Clean regex-matched lines away from a file.
|
||||||
|
|
||||||
@@ -626,8 +648,9 @@ def cleanup_headers(configs, options):
|
|||||||
continue
|
continue
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not fnmatch.fnmatch(filename, '*~'):
|
if not fnmatch.fnmatch(filename, '*~'):
|
||||||
cleanup_one_header(os.path.join(dirpath, filename),
|
header_path = os.path.join(dirpath, filename)
|
||||||
patterns, options)
|
cleanup_one_header(header_path, patterns, options)
|
||||||
|
cleanup_empty_blocks(header_path, options)
|
||||||
|
|
||||||
def cleanup_one_extra_option(defconfig_path, configs, options):
|
def cleanup_one_extra_option(defconfig_path, configs, options):
|
||||||
"""Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in one defconfig file.
|
"""Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in one defconfig file.
|
||||||
|
Reference in New Issue
Block a user