[PATCH v2 00/26] qconfig: Tidy up main() and add a small feature

This series improves the code a little by reducing the size of the main() function. It also allows searching for CONFIG values.
Changes in v2: - Drop debugging - Add a new patch to sort the boards by name when finding - Add new patch to support a 'list' format
Simon Glass (26): qconfig: Fix pylint error in read_database() qconfig: Drop the try_expand() function qconfig: Make KconfigScanner a function qconfig: Tidy up some pylint warnings qconfig: Correct format string in do_imply_config() qconfig: Rename the doc link qconfig: Move arg parsing into a separate function qconfig: Move arg checking a little higher qconfig: Move arg checking to the top of main() qconfig: Move getting the colour to where it is needed qconfig: Move checking directory to the top qconfig: Move converting config args to the top qconfig: Move testing into a separate function qconfig: Add a return value to do_scan_source() qconfig: Move imply into a separate function qconfig: Add a return value to do_find_config() qconfig: Move all move_config code into move_config() qconfig: Move commit code into a separate function qconfig: Move progress output into the class qconfig: Move the last two operations into their own functions qconfig: Use the Color object in Progress qconfig: Drop col argument from Slots() qconfig: Move operation check into parse_args() qconfig: Allow searching for CONFIG values qconfig: Sort the boards by name when finding qconfig: Support a 'list' format
doc/develop/qconfig.rst | 14 ++ tools/qconfig.py | 414 ++++++++++++++++++++++++---------------- 2 files changed, 264 insertions(+), 164 deletions(-)

Add basic support for searching for matching of non-matching values.
Signed-off-by: Simon Glass sjg@chromium.org Fixes: https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/20
---
Changes in v2: - Drop debugging
doc/develop/qconfig.rst | 14 ++++++++++++++ tools/qconfig.py | 15 +++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/doc/develop/qconfig.rst b/doc/develop/qconfig.rst index 8efb1eb2685..123779eab17 100644 --- a/doc/develop/qconfig.rst +++ b/doc/develop/qconfig.rst @@ -85,6 +85,20 @@ example, to find boards which enabled CONFIG_SCSI but not CONFIG_BLK:: 3 matches pg_wcom_seli8_defconfig highbank_defconfig pg_wcom_expu1_defconfig
+It is also possible to search for particular values. For example, this finds all +boards with an empty string for `CONFIG_DEFAULT_FDT_FILE`:: + + ./tools/qconfig.py -f DEFAULT_FDT_FILE="" + 1092 matches + ... + +This finds boards which have a value for SYS_MAXARGS other than 64:: + + ./tools/qconfig.py -f ~SYS_MAXARGS=64 + cfg CONFIG_SYS_MAXARGS + 281 matches + ... +
Finding implied CONFIGs ----------------------- diff --git a/tools/qconfig.py b/tools/qconfig.py index 408807931ff..71fe6fff29c 100755 --- a/tools/qconfig.py +++ b/tools/qconfig.py @@ -1079,7 +1079,7 @@ def do_imply_config(config_list, add_imply, imply_flags, skip_added, for linenum in sorted(linenums, reverse=True): add_imply_rule(config[CONFIG_LEN:], fname, linenum)
-def defconfig_matches(configs, re_match): +def defconfig_matches(configs, re_match, re_val): """Check if any CONFIG option matches a regex
The match must be complete, i.e. from the start to end of the CONFIG option. @@ -1089,13 +1089,15 @@ def defconfig_matches(configs, re_match): key: CONFIG option value: Value of option re_match (re.Pattern): Match to check + re_val (re.Pattern): Regular expression to check against value (or None)
Returns: bool: True if any CONFIG matches the regex """ - for cfg in configs: + for cfg, val in configs.items(): if re_match.fullmatch(cfg): - return True + if not re_val or re_val.fullmatch(val): + return True return False
def do_find_config(config_list): @@ -1123,6 +1125,11 @@ def do_find_config(config_list): if cfg[0] == '~': want = False cfg = cfg[1:] + val = None + re_val = None + if '=' in cfg: + cfg, val = cfg.split('=', maxsplit=1) + re_val = re.compile(val)
# Search everything that is still in the running. If it has a config # that we want, or doesn't have one that we don't, add it into the @@ -1131,7 +1138,7 @@ def do_find_config(config_list): out = set() re_match = re.compile(cfg) for defc in in_list: - has_cfg = defconfig_matches(config_db[defc], re_match) + has_cfg = defconfig_matches(config_db[defc], re_match, re_val) if has_cfg == want: out.add(defc) print(f'{len(out)} matches')

Add basic support for searching for matching of non-matching values.
Signed-off-by: Simon Glass sjg@chromium.org Fixes: https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/20
---
Changes in v2: - Drop debugging
doc/develop/qconfig.rst | 14 ++++++++++++++ tools/qconfig.py | 15 +++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-)
Applied to u-boot-dm, thanks!

There is no particular ordering of the board list at present, since it is generated by a multi-threaded process. Sort them by name to make it easier to see if a particular board is present.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Add a new patch to sort the boards by name when finding
tools/qconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/qconfig.py b/tools/qconfig.py index 71fe6fff29c..241bd9efe33 100755 --- a/tools/qconfig.py +++ b/tools/qconfig.py @@ -1142,7 +1142,7 @@ def do_find_config(config_list): if has_cfg == want: out.add(defc) print(f'{len(out)} matches') - print(' '.join(item.split('_defconfig')[0] for item in out)) + print(' '.join(item.split('_defconfig')[0] for item in sorted(list(out)))) return 0

There is no particular ordering of the board list at present, since it is generated by a multi-threaded process. Sort them by name to make it easier to see if a particular board is present.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Add a new patch to sort the boards by name when finding
tools/qconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm, thanks!

Add a flag to output the found list in a more user-friendly format, with one board per line. Omit the board count.
This can be useful with grep, for example.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Add new patch to support a 'list' format
tools/qconfig.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/tools/qconfig.py b/tools/qconfig.py index 241bd9efe33..7b868c7d72c 100755 --- a/tools/qconfig.py +++ b/tools/qconfig.py @@ -1100,7 +1100,7 @@ def defconfig_matches(configs, re_match, re_val): return True return False
-def do_find_config(config_list): +def do_find_config(config_list, list_format): """Find boards with a given combination of CONFIGs
Args: @@ -1108,6 +1108,8 @@ def do_find_config(config_list): consisting of a config option, with or without a CONFIG_ prefix. If an option is preceded by a tilde (~) then it must be false, otherwise it must be true) + list_format (bool): True to write in 'list' format, one board name per + line
Returns: int: exit code (0 for success) @@ -1141,8 +1143,10 @@ def do_find_config(config_list): has_cfg = defconfig_matches(config_db[defc], re_match, re_val) if has_cfg == want: out.add(defc) - print(f'{len(out)} matches') - print(' '.join(item.split('_defconfig')[0] for item in sorted(list(out)))) + if not list_format: + print(f'{len(out)} matches') + sep = '\n' if list_format else ' ' + print(sep.join(item.split('_defconfig')[0] for item in sorted(list(out)))) return 0
@@ -1535,6 +1539,8 @@ doc/develop/moveconfig.rst for documentation.''' help='Find boards with a given config combination') parser.add_argument('-i', '--imply', action='store_true', default=False, help='find options which imply others') + parser.add_argument('-l', '--list', action='store_true', default=False, + help='Show a sorted list of board names, one per line') parser.add_argument('-I', '--imply-flags', type=str, default='', help="control the -i option ('help' for help") parser.add_argument('-j', '--jobs', type=int, default=cpu_count, @@ -1688,7 +1694,7 @@ def main(): sys.exit(1) return 0 if args.find: - return do_find_config(args.configs) + return do_find_config(args.configs, args.list)
config_db, progress = move_config(args)

Add a flag to output the found list in a more user-friendly format, with one board per line. Omit the board count.
This can be useful with grep, for example.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Add new patch to support a 'list' format
tools/qconfig.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Applied to u-boot-dm, thanks!
participants (1)
-
Simon Glass