moveconfig: Convert to ArgumentParser
This is a newer library and is now preferred for Python scripts. Update the code to use it instead of optparse Use 'args' instead of 'options' throughout, since this is the term used in that module. Also it helps to avoid confusion with CONFIG options, a term that is used in this file. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -10,6 +10,7 @@ Move config options from headers to defconfig files.
|
|||||||
See doc/develop/moveconfig.rst for documentation.
|
See doc/develop/moveconfig.rst for documentation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
import asteval
|
import asteval
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
@@ -19,7 +20,6 @@ import filecmp
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import glob
|
import glob
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import optparse
|
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import re
|
import re
|
||||||
@@ -267,8 +267,8 @@ def extend_matched_lines(lines, matched, pre_patterns, post_patterns, extend_pre
|
|||||||
matched += extended_matched
|
matched += extended_matched
|
||||||
matched.sort()
|
matched.sort()
|
||||||
|
|
||||||
def confirm(options, prompt):
|
def confirm(args, prompt):
|
||||||
if not options.yes:
|
if not args.yes:
|
||||||
while True:
|
while True:
|
||||||
choice = input('{} [y/n]: '.format(prompt))
|
choice = input('{} [y/n]: '.format(prompt))
|
||||||
choice = choice.lower()
|
choice = choice.lower()
|
||||||
@@ -281,12 +281,12 @@ def confirm(options, prompt):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def cleanup_empty_blocks(header_path, options):
|
def cleanup_empty_blocks(header_path, args):
|
||||||
"""Clean up empty conditional blocks
|
"""Clean up empty conditional blocks
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
header_path: path to the cleaned file.
|
header_path: path to the cleaned file.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
pattern = re.compile(r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*', flags=re.M)
|
pattern = re.compile(r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*', flags=re.M)
|
||||||
with open(header_path) as f:
|
with open(header_path) as f:
|
||||||
@@ -299,22 +299,22 @@ def cleanup_empty_blocks(header_path, options):
|
|||||||
new_data = pattern.sub('\n', data)
|
new_data = pattern.sub('\n', data)
|
||||||
|
|
||||||
show_diff(data.splitlines(True), new_data.splitlines(True), header_path,
|
show_diff(data.splitlines(True), new_data.splitlines(True), header_path,
|
||||||
options.color)
|
args.color)
|
||||||
|
|
||||||
if options.dry_run:
|
if args.dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(header_path, 'w') as f:
|
with open(header_path, 'w') as f:
|
||||||
f.write(new_data)
|
f.write(new_data)
|
||||||
|
|
||||||
def cleanup_one_header(header_path, patterns, options):
|
def cleanup_one_header(header_path, patterns, args):
|
||||||
"""Clean regex-matched lines away from a file.
|
"""Clean regex-matched lines away from a file.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
header_path: path to the cleaned file.
|
header_path: path to the cleaned file.
|
||||||
patterns: list of regex patterns. Any lines matching to these
|
patterns: list of regex patterns. Any lines matching to these
|
||||||
patterns are deleted.
|
patterns are deleted.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
with open(header_path) as f:
|
with open(header_path) as f:
|
||||||
try:
|
try:
|
||||||
@@ -362,23 +362,23 @@ def cleanup_one_header(header_path, patterns, options):
|
|||||||
for i in reversed(matched):
|
for i in reversed(matched):
|
||||||
tolines.pop(i)
|
tolines.pop(i)
|
||||||
|
|
||||||
show_diff(lines, tolines, header_path, options.color)
|
show_diff(lines, tolines, header_path, args.color)
|
||||||
|
|
||||||
if options.dry_run:
|
if args.dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(header_path, 'w') as f:
|
with open(header_path, 'w') as f:
|
||||||
for line in tolines:
|
for line in tolines:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
def cleanup_headers(configs, options):
|
def cleanup_headers(configs, args):
|
||||||
"""Delete config defines from board headers.
|
"""Delete config defines from board headers.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to remove.
|
configs: A list of CONFIGs to remove.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
if not confirm(options, 'Clean up headers?'):
|
if not confirm(args, 'Clean up headers?'):
|
||||||
return
|
return
|
||||||
|
|
||||||
patterns = []
|
patterns = []
|
||||||
@@ -397,16 +397,16 @@ def cleanup_headers(configs, options):
|
|||||||
# This file contains UTF-16 data and no CONFIG symbols
|
# This file contains UTF-16 data and no CONFIG symbols
|
||||||
if header_path == 'include/video_font_data.h':
|
if header_path == 'include/video_font_data.h':
|
||||||
continue
|
continue
|
||||||
cleanup_one_header(header_path, patterns, options)
|
cleanup_one_header(header_path, patterns, args)
|
||||||
cleanup_empty_blocks(header_path, options)
|
cleanup_empty_blocks(header_path, args)
|
||||||
|
|
||||||
def cleanup_one_extra_option(defconfig_path, configs, options):
|
def cleanup_one_extra_option(defconfig_path, configs, args):
|
||||||
"""Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in one defconfig file.
|
"""Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in one defconfig file.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
defconfig_path: path to the cleaned defconfig file.
|
defconfig_path: path to the cleaned defconfig file.
|
||||||
configs: A list of CONFIGs to remove.
|
configs: A list of CONFIGs to remove.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
|
|
||||||
start = 'CONFIG_SYS_EXTRA_OPTIONS="'
|
start = 'CONFIG_SYS_EXTRA_OPTIONS="'
|
||||||
@@ -440,23 +440,23 @@ def cleanup_one_extra_option(defconfig_path, configs, options):
|
|||||||
else:
|
else:
|
||||||
tolines.pop(i)
|
tolines.pop(i)
|
||||||
|
|
||||||
show_diff(lines, tolines, defconfig_path, options.color)
|
show_diff(lines, tolines, defconfig_path, args.color)
|
||||||
|
|
||||||
if options.dry_run:
|
if args.dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(defconfig_path, 'w') as f:
|
with open(defconfig_path, 'w') as f:
|
||||||
for line in tolines:
|
for line in tolines:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
def cleanup_extra_options(configs, options):
|
def cleanup_extra_options(configs, args):
|
||||||
"""Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in defconfig files.
|
"""Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in defconfig files.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to remove.
|
configs: A list of CONFIGs to remove.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
if not confirm(options, 'Clean up CONFIG_SYS_EXTRA_OPTIONS?'):
|
if not confirm(args, 'Clean up CONFIG_SYS_EXTRA_OPTIONS?'):
|
||||||
return
|
return
|
||||||
|
|
||||||
configs = [ config[len('CONFIG_'):] for config in configs ]
|
configs = [ config[len('CONFIG_'):] for config in configs ]
|
||||||
@@ -465,16 +465,16 @@ def cleanup_extra_options(configs, options):
|
|||||||
|
|
||||||
for defconfig in defconfigs:
|
for defconfig in defconfigs:
|
||||||
cleanup_one_extra_option(os.path.join('configs', defconfig), configs,
|
cleanup_one_extra_option(os.path.join('configs', defconfig), configs,
|
||||||
options)
|
args)
|
||||||
|
|
||||||
def cleanup_whitelist(configs, options):
|
def cleanup_whitelist(configs, args):
|
||||||
"""Delete config whitelist entries
|
"""Delete config whitelist entries
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to remove.
|
configs: A list of CONFIGs to remove.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
if not confirm(options, 'Clean up whitelist entries?'):
|
if not confirm(args, 'Clean up whitelist entries?'):
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(os.path.join('scripts', 'config_whitelist.txt')) as f:
|
with open(os.path.join('scripts', 'config_whitelist.txt')) as f:
|
||||||
@@ -491,14 +491,14 @@ def find_matching(patterns, line):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def cleanup_readme(configs, options):
|
def cleanup_readme(configs, args):
|
||||||
"""Delete config description in README
|
"""Delete config description in README
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to remove.
|
configs: A list of CONFIGs to remove.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
"""
|
"""
|
||||||
if not confirm(options, 'Clean up README?'):
|
if not confirm(args, 'Clean up README?'):
|
||||||
return
|
return
|
||||||
|
|
||||||
patterns = []
|
patterns = []
|
||||||
@@ -590,16 +590,16 @@ class KconfigParser:
|
|||||||
re_arch = re.compile(r'CONFIG_SYS_ARCH="(.*)"')
|
re_arch = re.compile(r'CONFIG_SYS_ARCH="(.*)"')
|
||||||
re_cpu = re.compile(r'CONFIG_SYS_CPU="(.*)"')
|
re_cpu = re.compile(r'CONFIG_SYS_CPU="(.*)"')
|
||||||
|
|
||||||
def __init__(self, configs, options, build_dir):
|
def __init__(self, configs, args, build_dir):
|
||||||
"""Create a new parser.
|
"""Create a new parser.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to move.
|
configs: A list of CONFIGs to move.
|
||||||
options: option flags.
|
args: program arguments
|
||||||
build_dir: Build directory.
|
build_dir: Build directory.
|
||||||
"""
|
"""
|
||||||
self.configs = configs
|
self.configs = configs
|
||||||
self.options = options
|
self.args = args
|
||||||
self.dotconfig = os.path.join(build_dir, '.config')
|
self.dotconfig = os.path.join(build_dir, '.config')
|
||||||
self.autoconf = os.path.join(build_dir, 'include', 'autoconf.mk')
|
self.autoconf = os.path.join(build_dir, 'include', 'autoconf.mk')
|
||||||
self.spl_autoconf = os.path.join(build_dir, 'spl', 'include',
|
self.spl_autoconf = os.path.join(build_dir, 'spl', 'include',
|
||||||
@@ -704,7 +704,7 @@ class KconfigParser:
|
|||||||
suspicious = False
|
suspicious = False
|
||||||
rm_files = [self.config_autoconf, self.autoconf]
|
rm_files = [self.config_autoconf, self.autoconf]
|
||||||
|
|
||||||
if self.options.spl:
|
if self.args.spl:
|
||||||
if os.path.exists(self.spl_autoconf):
|
if os.path.exists(self.spl_autoconf):
|
||||||
autoconf_path = self.spl_autoconf
|
autoconf_path = self.spl_autoconf
|
||||||
rm_files.append(self.spl_autoconf)
|
rm_files.append(self.spl_autoconf)
|
||||||
@@ -712,7 +712,7 @@ class KconfigParser:
|
|||||||
for f in rm_files:
|
for f in rm_files:
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
return (updated, suspicious,
|
return (updated, suspicious,
|
||||||
color_text(self.options.color, COLOR_BROWN,
|
color_text(self.args.color, COLOR_BROWN,
|
||||||
"SPL is not enabled. Skipped.") + '\n')
|
"SPL is not enabled. Skipped.") + '\n')
|
||||||
else:
|
else:
|
||||||
autoconf_path = self.autoconf
|
autoconf_path = self.autoconf
|
||||||
@@ -751,7 +751,7 @@ class KconfigParser:
|
|||||||
else:
|
else:
|
||||||
sys.exit('Internal Error. This should not happen.')
|
sys.exit('Internal Error. This should not happen.')
|
||||||
|
|
||||||
log += color_text(self.options.color, log_color, actlog) + '\n'
|
log += color_text(self.args.color, log_color, actlog) + '\n'
|
||||||
|
|
||||||
with open(self.dotconfig, 'a') as f:
|
with open(self.dotconfig, 'a') as f:
|
||||||
for (action, value) in results:
|
for (action, value) in results:
|
||||||
@@ -782,7 +782,7 @@ class KconfigParser:
|
|||||||
if action != ACTION_MOVE:
|
if action != ACTION_MOVE:
|
||||||
continue
|
continue
|
||||||
if not value + '\n' in defconfig_lines:
|
if not value + '\n' in defconfig_lines:
|
||||||
log += color_text(self.options.color, COLOR_YELLOW,
|
log += color_text(self.args.color, COLOR_YELLOW,
|
||||||
"'%s' was removed by savedefconfig.\n" %
|
"'%s' was removed by savedefconfig.\n" %
|
||||||
value)
|
value)
|
||||||
|
|
||||||
@@ -825,14 +825,14 @@ class Slot:
|
|||||||
for faster processing.
|
for faster processing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, toolchains, configs, options, progress, devnull,
|
def __init__(self, toolchains, configs, args, progress, devnull,
|
||||||
make_cmd, reference_src_dir, db_queue):
|
make_cmd, reference_src_dir, db_queue):
|
||||||
"""Create a new process slot.
|
"""Create a new process slot.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
toolchains: Toolchains object containing toolchains.
|
toolchains: Toolchains object containing toolchains.
|
||||||
configs: A list of CONFIGs to move.
|
configs: A list of CONFIGs to move.
|
||||||
options: option flags.
|
args: Program arguments
|
||||||
progress: A progress indicator.
|
progress: A progress indicator.
|
||||||
devnull: A file object of '/dev/null'.
|
devnull: A file object of '/dev/null'.
|
||||||
make_cmd: command name of GNU Make.
|
make_cmd: command name of GNU Make.
|
||||||
@@ -841,14 +841,14 @@ class Slot:
|
|||||||
db_queue: output queue to write config info for the database
|
db_queue: output queue to write config info for the database
|
||||||
"""
|
"""
|
||||||
self.toolchains = toolchains
|
self.toolchains = toolchains
|
||||||
self.options = options
|
self.args = args
|
||||||
self.progress = progress
|
self.progress = progress
|
||||||
self.build_dir = tempfile.mkdtemp()
|
self.build_dir = tempfile.mkdtemp()
|
||||||
self.devnull = devnull
|
self.devnull = devnull
|
||||||
self.make_cmd = (make_cmd, 'O=' + self.build_dir)
|
self.make_cmd = (make_cmd, 'O=' + self.build_dir)
|
||||||
self.reference_src_dir = reference_src_dir
|
self.reference_src_dir = reference_src_dir
|
||||||
self.db_queue = db_queue
|
self.db_queue = db_queue
|
||||||
self.parser = KconfigParser(configs, options, self.build_dir)
|
self.parser = KconfigParser(configs, args, self.build_dir)
|
||||||
self.state = STATE_IDLE
|
self.state = STATE_IDLE
|
||||||
self.failed_boards = set()
|
self.failed_boards = set()
|
||||||
self.suspicious_boards = set()
|
self.suspicious_boards = set()
|
||||||
@@ -923,7 +923,7 @@ class Slot:
|
|||||||
if self.current_src_dir:
|
if self.current_src_dir:
|
||||||
self.current_src_dir = None
|
self.current_src_dir = None
|
||||||
self.do_defconfig()
|
self.do_defconfig()
|
||||||
elif self.options.build_db:
|
elif self.args.build_db:
|
||||||
self.do_build_db()
|
self.do_build_db()
|
||||||
else:
|
else:
|
||||||
self.do_savedefconfig()
|
self.do_savedefconfig()
|
||||||
@@ -937,10 +937,10 @@ class Slot:
|
|||||||
def handle_error(self):
|
def handle_error(self):
|
||||||
"""Handle error cases."""
|
"""Handle error cases."""
|
||||||
|
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_RED,
|
self.log += color_text(self.args.color, COLOR_LIGHT_RED,
|
||||||
'Failed to process.\n')
|
'Failed to process.\n')
|
||||||
if self.options.verbose:
|
if self.args.verbose:
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_CYAN,
|
self.log += color_text(self.args.color, COLOR_LIGHT_CYAN,
|
||||||
self.ps.stderr.read().decode())
|
self.ps.stderr.read().decode())
|
||||||
self.finish(False)
|
self.finish(False)
|
||||||
|
|
||||||
@@ -961,7 +961,7 @@ class Slot:
|
|||||||
try:
|
try:
|
||||||
toolchain = self.toolchains.Select(arch)
|
toolchain = self.toolchains.Select(arch)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.log += color_text(self.options.color, COLOR_YELLOW,
|
self.log += color_text(self.args.color, COLOR_YELLOW,
|
||||||
"Tool chain for '%s' is missing. Do nothing.\n" % arch)
|
"Tool chain for '%s' is missing. Do nothing.\n" % arch)
|
||||||
self.finish(False)
|
self.finish(False)
|
||||||
return
|
return
|
||||||
@@ -994,11 +994,11 @@ class Slot:
|
|||||||
self.suspicious_boards.add(self.defconfig)
|
self.suspicious_boards.add(self.defconfig)
|
||||||
self.log += log
|
self.log += log
|
||||||
|
|
||||||
if not self.options.force_sync and not updated:
|
if not self.args.force_sync and not updated:
|
||||||
self.finish(True)
|
self.finish(True)
|
||||||
return
|
return
|
||||||
if updated:
|
if updated:
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_GREEN,
|
self.log += color_text(self.args.color, COLOR_LIGHT_GREEN,
|
||||||
'Syncing by savedefconfig...\n')
|
'Syncing by savedefconfig...\n')
|
||||||
else:
|
else:
|
||||||
self.log += 'Syncing by savedefconfig (forced by option)...\n'
|
self.log += 'Syncing by savedefconfig (forced by option)...\n'
|
||||||
@@ -1021,10 +1021,10 @@ class Slot:
|
|||||||
updated = not filecmp.cmp(orig_defconfig, new_defconfig)
|
updated = not filecmp.cmp(orig_defconfig, new_defconfig)
|
||||||
|
|
||||||
if updated:
|
if updated:
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_BLUE,
|
self.log += color_text(self.args.color, COLOR_LIGHT_BLUE,
|
||||||
'defconfig was updated.\n')
|
'defconfig was updated.\n')
|
||||||
|
|
||||||
if not self.options.dry_run and updated:
|
if not self.args.dry_run and updated:
|
||||||
shutil.move(new_defconfig, orig_defconfig)
|
shutil.move(new_defconfig, orig_defconfig)
|
||||||
self.finish(True)
|
self.finish(True)
|
||||||
|
|
||||||
@@ -1044,7 +1044,7 @@ class Slot:
|
|||||||
print(log, file=(sys.stdout if success else sys.stderr))
|
print(log, file=(sys.stdout if success else sys.stderr))
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
if self.options.exit_on_error:
|
if self.args.exit_on_error:
|
||||||
sys.exit('Exit on error.')
|
sys.exit('Exit on error.')
|
||||||
# If --exit-on-error flag is not set, skip this board and continue.
|
# If --exit-on-error flag is not set, skip this board and continue.
|
||||||
# Record the failed board.
|
# Record the failed board.
|
||||||
@@ -1068,25 +1068,25 @@ class Slots:
|
|||||||
|
|
||||||
"""Controller of the array of subprocess slots."""
|
"""Controller of the array of subprocess slots."""
|
||||||
|
|
||||||
def __init__(self, toolchains, configs, options, progress,
|
def __init__(self, toolchains, configs, args, progress,
|
||||||
reference_src_dir, db_queue):
|
reference_src_dir, db_queue):
|
||||||
"""Create a new slots controller.
|
"""Create a new slots controller.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
toolchains: Toolchains object containing toolchains.
|
toolchains: Toolchains object containing toolchains.
|
||||||
configs: A list of CONFIGs to move.
|
configs: A list of CONFIGs to move.
|
||||||
options: option flags.
|
args: Program arguments
|
||||||
progress: A progress indicator.
|
progress: A progress indicator.
|
||||||
reference_src_dir: Determine the true starting config state from this
|
reference_src_dir: Determine the true starting config state from this
|
||||||
source tree.
|
source tree.
|
||||||
db_queue: output queue to write config info for the database
|
db_queue: output queue to write config info for the database
|
||||||
"""
|
"""
|
||||||
self.options = options
|
self.args = args
|
||||||
self.slots = []
|
self.slots = []
|
||||||
devnull = get_devnull()
|
devnull = get_devnull()
|
||||||
make_cmd = get_make_cmd()
|
make_cmd = get_make_cmd()
|
||||||
for i in range(options.jobs):
|
for i in range(args.jobs):
|
||||||
self.slots.append(Slot(toolchains, configs, options, progress,
|
self.slots.append(Slot(toolchains, configs, args, progress,
|
||||||
devnull, make_cmd, reference_src_dir,
|
devnull, make_cmd, reference_src_dir,
|
||||||
db_queue))
|
db_queue))
|
||||||
|
|
||||||
@@ -1140,7 +1140,7 @@ class Slots:
|
|||||||
msg = 'The following boards were not processed due to error:\n'
|
msg = 'The following boards were not processed due to error:\n'
|
||||||
msg += boards
|
msg += boards
|
||||||
msg += '(the list has been saved in %s)\n' % output_file
|
msg += '(the list has been saved in %s)\n' % output_file
|
||||||
print(color_text(self.options.color, COLOR_LIGHT_RED,
|
print(color_text(self.args.color, COLOR_LIGHT_RED,
|
||||||
msg), file=sys.stderr)
|
msg), file=sys.stderr)
|
||||||
|
|
||||||
with open(output_file, 'w') as f:
|
with open(output_file, 'w') as f:
|
||||||
@@ -1160,7 +1160,7 @@ class Slots:
|
|||||||
msg += 'It is highly recommended to check them manually:\n'
|
msg += 'It is highly recommended to check them manually:\n'
|
||||||
msg += boards
|
msg += boards
|
||||||
msg += '(the list has been saved in %s)\n' % output_file
|
msg += '(the list has been saved in %s)\n' % output_file
|
||||||
print(color_text(self.options.color, COLOR_YELLOW,
|
print(color_text(self.args.color, COLOR_YELLOW,
|
||||||
msg), file=sys.stderr)
|
msg), file=sys.stderr)
|
||||||
|
|
||||||
with open(output_file, 'w') as f:
|
with open(output_file, 'w') as f:
|
||||||
@@ -1200,37 +1200,37 @@ class ReferenceSource:
|
|||||||
|
|
||||||
return self.src_dir
|
return self.src_dir
|
||||||
|
|
||||||
def move_config(toolchains, configs, options, db_queue):
|
def move_config(toolchains, configs, args, db_queue):
|
||||||
"""Move config options to defconfig files.
|
"""Move config options to defconfig files.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to move.
|
configs: A list of CONFIGs to move.
|
||||||
options: option flags
|
args: Program arguments
|
||||||
"""
|
"""
|
||||||
if len(configs) == 0:
|
if len(configs) == 0:
|
||||||
if options.force_sync:
|
if args.force_sync:
|
||||||
print('No CONFIG is specified. You are probably syncing defconfigs.', end=' ')
|
print('No CONFIG is specified. You are probably syncing defconfigs.', end=' ')
|
||||||
elif options.build_db:
|
elif args.build_db:
|
||||||
print('Building %s database' % CONFIG_DATABASE)
|
print('Building %s database' % CONFIG_DATABASE)
|
||||||
else:
|
else:
|
||||||
print('Neither CONFIG nor --force-sync is specified. Nothing will happen.', end=' ')
|
print('Neither CONFIG nor --force-sync is specified. Nothing will happen.', end=' ')
|
||||||
else:
|
else:
|
||||||
print('Move ' + ', '.join(configs), end=' ')
|
print('Move ' + ', '.join(configs), end=' ')
|
||||||
print('(jobs: %d)\n' % options.jobs)
|
print('(jobs: %d)\n' % args.jobs)
|
||||||
|
|
||||||
if options.git_ref:
|
if args.git_ref:
|
||||||
reference_src = ReferenceSource(options.git_ref)
|
reference_src = ReferenceSource(args.git_ref)
|
||||||
reference_src_dir = reference_src.get_dir()
|
reference_src_dir = reference_src.get_dir()
|
||||||
else:
|
else:
|
||||||
reference_src_dir = None
|
reference_src_dir = None
|
||||||
|
|
||||||
if options.defconfigs:
|
if args.defconfigs:
|
||||||
defconfigs = get_matched_defconfigs(options.defconfigs)
|
defconfigs = get_matched_defconfigs(args.defconfigs)
|
||||||
else:
|
else:
|
||||||
defconfigs = get_all_defconfigs()
|
defconfigs = get_all_defconfigs()
|
||||||
|
|
||||||
progress = Progress(len(defconfigs))
|
progress = Progress(len(defconfigs))
|
||||||
slots = Slots(toolchains, configs, options, progress, reference_src_dir,
|
slots = Slots(toolchains, configs, args, progress, reference_src_dir,
|
||||||
db_queue)
|
db_queue)
|
||||||
|
|
||||||
# Main loop to process defconfig files:
|
# Main loop to process defconfig files:
|
||||||
@@ -1648,65 +1648,69 @@ def main():
|
|||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
cpu_count = 1
|
cpu_count = 1
|
||||||
|
|
||||||
parser = optparse.OptionParser()
|
epilog = '''Move config options from headers to defconfig files. See
|
||||||
# Add options here
|
doc/develop/moveconfig.rst for documentation.'''
|
||||||
parser.add_option('-a', '--add-imply', type='string', default='',
|
|
||||||
|
parser = ArgumentParser(epilog=epilog)
|
||||||
|
# Add arguments here
|
||||||
|
parser.add_argument('-a', '--add-imply', type=str, default='',
|
||||||
help='comma-separated list of CONFIG options to add '
|
help='comma-separated list of CONFIG options to add '
|
||||||
"an 'imply' statement to for the CONFIG in -i")
|
"an 'imply' statement to for the CONFIG in -i")
|
||||||
parser.add_option('-A', '--skip-added', action='store_true', default=False,
|
parser.add_argument('-A', '--skip-added', action='store_true', default=False,
|
||||||
help="don't show options which are already marked as "
|
help="don't show options which are already marked as "
|
||||||
'implying others')
|
'implying others')
|
||||||
parser.add_option('-b', '--build-db', action='store_true', default=False,
|
parser.add_argument('-b', '--build-db', action='store_true', default=False,
|
||||||
help='build a CONFIG database')
|
help='build a CONFIG database')
|
||||||
parser.add_option('-c', '--color', action='store_true', default=False,
|
parser.add_argument('-c', '--color', action='store_true', default=False,
|
||||||
help='display the log in color')
|
help='display the log in color')
|
||||||
parser.add_option('-C', '--commit', action='store_true', default=False,
|
parser.add_argument('-C', '--commit', action='store_true', default=False,
|
||||||
help='Create a git commit for the operation')
|
help='Create a git commit for the operation')
|
||||||
parser.add_option('-d', '--defconfigs', type='string',
|
parser.add_argument('-d', '--defconfigs', type=str,
|
||||||
help='a file containing a list of defconfigs to move, '
|
help='a file containing a list of defconfigs to move, '
|
||||||
"one per line (for example 'snow_defconfig') "
|
"one per line (for example 'snow_defconfig') "
|
||||||
"or '-' to read from stdin")
|
"or '-' to read from stdin")
|
||||||
parser.add_option('-e', '--exit-on-error', action='store_true',
|
parser.add_argument('-e', '--exit-on-error', action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='exit immediately on any error')
|
help='exit immediately on any error')
|
||||||
parser.add_option('-f', '--find', action='store_true', default=False,
|
parser.add_argument('-f', '--find', action='store_true', default=False,
|
||||||
help='Find boards with a given config combination')
|
help='Find boards with a given config combination')
|
||||||
parser.add_option('-H', '--headers-only', dest='cleanup_headers_only',
|
parser.add_argument('-H', '--headers-only', dest='cleanup_headers_only',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='only cleanup the headers')
|
help='only cleanup the headers')
|
||||||
parser.add_option('-i', '--imply', action='store_true', default=False,
|
parser.add_argument('-i', '--imply', action='store_true', default=False,
|
||||||
help='find options which imply others')
|
help='find options which imply others')
|
||||||
parser.add_option('-I', '--imply-flags', type='string', default='',
|
parser.add_argument('-I', '--imply-flags', type=str, default='',
|
||||||
help="control the -i option ('help' for help")
|
help="control the -i option ('help' for help")
|
||||||
parser.add_option('-j', '--jobs', type='int', default=cpu_count,
|
parser.add_argument('-j', '--jobs', type=int, default=cpu_count,
|
||||||
help='the number of jobs to run simultaneously')
|
help='the number of jobs to run simultaneously')
|
||||||
parser.add_option('-n', '--dry-run', action='store_true', default=False,
|
parser.add_argument('-n', '--dry-run', action='store_true', default=False,
|
||||||
help='perform a trial run (show log with no changes)')
|
help='perform a trial run (show log with no changes)')
|
||||||
parser.add_option('-r', '--git-ref', type='string',
|
parser.add_argument('-r', '--git-ref', type=str,
|
||||||
help='the git ref to clone for building the autoconf.mk')
|
help='the git ref to clone for building the autoconf.mk')
|
||||||
parser.add_option('-s', '--force-sync', action='store_true', default=False,
|
parser.add_argument('-s', '--force-sync', action='store_true', default=False,
|
||||||
help='force sync by savedefconfig')
|
help='force sync by savedefconfig')
|
||||||
parser.add_option('-S', '--spl', action='store_true', default=False,
|
parser.add_argument('-S', '--spl', action='store_true', default=False,
|
||||||
help='parse config options defined for SPL build')
|
help='parse config options defined for SPL build')
|
||||||
parser.add_option('-t', '--test', action='store_true', default=False,
|
parser.add_argument('-t', '--test', action='store_true', default=False,
|
||||||
help='run unit tests')
|
help='run unit tests')
|
||||||
parser.add_option('-y', '--yes', action='store_true', default=False,
|
parser.add_argument('-y', '--yes', action='store_true', default=False,
|
||||||
help="respond 'yes' to any prompts")
|
help="respond 'yes' to any prompts")
|
||||||
parser.add_option('-v', '--verbose', action='store_true', default=False,
|
parser.add_argument('-v', '--verbose', action='store_true', default=False,
|
||||||
help='show any build errors as boards are built')
|
help='show any build errors as boards are built')
|
||||||
parser.usage += ' CONFIG ...'
|
parser.add_argument('configs', nargs='*')
|
||||||
|
|
||||||
(options, configs) = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
configs = args.configs
|
||||||
|
|
||||||
if options.test:
|
if args.test:
|
||||||
sys.argv = [sys.argv[0]]
|
sys.argv = [sys.argv[0]]
|
||||||
fail, count = doctest.testmod()
|
fail, count = doctest.testmod()
|
||||||
if fail:
|
if fail:
|
||||||
return 1
|
return 1
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
if len(configs) == 0 and not any((options.force_sync, options.build_db,
|
if not any((len(configs), args.force_sync, args.build_db, args.imply,
|
||||||
options.imply, options.find)):
|
args.find)):
|
||||||
parser.print_usage()
|
parser.print_usage()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@@ -1715,13 +1719,13 @@ def main():
|
|||||||
|
|
||||||
check_top_directory()
|
check_top_directory()
|
||||||
|
|
||||||
if options.imply:
|
if args.imply:
|
||||||
imply_flags = 0
|
imply_flags = 0
|
||||||
if options.imply_flags == 'all':
|
if args.imply_flags == 'all':
|
||||||
imply_flags = -1
|
imply_flags = -1
|
||||||
|
|
||||||
elif options.imply_flags:
|
elif args.imply_flags:
|
||||||
for flag in options.imply_flags.split(','):
|
for flag in args.imply_flags.split(','):
|
||||||
bad = flag not in IMPLY_FLAGS
|
bad = flag not in IMPLY_FLAGS
|
||||||
if bad:
|
if bad:
|
||||||
print("Invalid flag '%s'" % flag)
|
print("Invalid flag '%s'" % flag)
|
||||||
@@ -1733,11 +1737,10 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
imply_flags |= IMPLY_FLAGS[flag][0]
|
imply_flags |= IMPLY_FLAGS[flag][0]
|
||||||
|
|
||||||
do_imply_config(configs, options.add_imply, imply_flags,
|
do_imply_config(configs, args.add_imply, imply_flags, args.skip_added)
|
||||||
options.skip_added)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if options.find:
|
if args.find:
|
||||||
do_find_config(configs)
|
do_find_config(configs)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1747,22 +1750,22 @@ def main():
|
|||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
if not options.cleanup_headers_only:
|
if not args.cleanup_headers_only:
|
||||||
check_clean_directory()
|
check_clean_directory()
|
||||||
bsettings.Setup('')
|
bsettings.Setup('')
|
||||||
toolchains = toolchain.Toolchains()
|
toolchains = toolchain.Toolchains()
|
||||||
toolchains.GetSettings()
|
toolchains.GetSettings()
|
||||||
toolchains.Scan(verbose=False)
|
toolchains.Scan(verbose=False)
|
||||||
move_config(toolchains, configs, options, db_queue)
|
move_config(toolchains, configs, args, db_queue)
|
||||||
db_queue.join()
|
db_queue.join()
|
||||||
|
|
||||||
if configs:
|
if configs:
|
||||||
cleanup_headers(configs, options)
|
cleanup_headers(configs, args)
|
||||||
cleanup_extra_options(configs, options)
|
cleanup_extra_options(configs, args)
|
||||||
cleanup_whitelist(configs, options)
|
cleanup_whitelist(configs, args)
|
||||||
cleanup_readme(configs, options)
|
cleanup_readme(configs, args)
|
||||||
|
|
||||||
if options.commit:
|
if args.commit:
|
||||||
subprocess.call(['git', 'add', '-u'])
|
subprocess.call(['git', 'add', '-u'])
|
||||||
if configs:
|
if configs:
|
||||||
msg = 'Convert %s %sto Kconfig' % (configs[0],
|
msg = 'Convert %s %sto Kconfig' % (configs[0],
|
||||||
@@ -1774,7 +1777,7 @@ def main():
|
|||||||
msg += '\n\nRsync all defconfig files using moveconfig.py'
|
msg += '\n\nRsync all defconfig files using moveconfig.py'
|
||||||
subprocess.call(['git', 'commit', '-s', '-m', msg])
|
subprocess.call(['git', 'commit', '-s', '-m', msg])
|
||||||
|
|
||||||
if options.build_db:
|
if args.build_db:
|
||||||
with open(CONFIG_DATABASE, 'w') as fd:
|
with open(CONFIG_DATABASE, 'w') as fd:
|
||||||
for defconfig, configs in config_db.items():
|
for defconfig, configs in config_db.items():
|
||||||
fd.write('%s\n' % defconfig)
|
fd.write('%s\n' % defconfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user