Skip to content

Commit 09b7b0e

Browse files
committed
Consolidate duplicated patterns
This extracts shared helpers to eliminate copy-pasted logic: - kconfiglib.py: _run_cmd()/_run_cmd_in_tmpdir() replace 9 duplicated subprocess functions; merge select/imply sanity loops; flatten nested ternaries in expr_value() and _parse_block() - menuconfig.py: _draw_scrollbar(), _create_shadow_for_win(), _info_dialog_title() deduplicate rendering code; rewrite _draw_box() from O(area) to O(perimeter); remove dead _safe_hline/_safe_vline - guiconfig.py: _save_dialog(), _choice_sym_prompt() helpers; data-driven _select_imply_info() loop; delegate ThemeManager.toggle() to set_theme - lint.py: print_results() helper; list comprehensions replace loops - testsuite.py: run_conf_and_compare() helper for 5 test functions - genconfig.py: flatten nested if/else for header_path
1 parent 4cce2c7 commit 09b7b0e

16 files changed

Lines changed: 538 additions & 969 deletions

‎alldefconfig.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/alldefconfig.py
1616
"""
17+
1718
import kconfiglib
1819

1920

‎allmodconfig.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allmodconfig.py
1515
"""
16+
1617
import kconfiglib
1718

1819

‎allyesconfig.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allyesconfig.py
1515
"""
16+
1617
import kconfiglib
1718

1819

‎defconfig.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
The default output filename is '.config'. A different filename can be passed in
1313
the KCONFIG_CONFIG environment variable.
1414
"""
15+
1516
import argparse
1617

1718
import kconfiglib

‎genconfig.py‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
handy way to define multi-line variables in makefiles, for use with custom
3333
headers. Remember to export the variable to the environment.
3434
"""
35+
3536
import argparse
3637
import os
3738
import sys
3839

3940
import kconfiglib
4041

41-
4242
DEFAULT_SYNC_DEPS_PATH = "deps/"
4343

4444

@@ -79,9 +79,7 @@ def main():
7979
Enable generation of symbol dependency information for incremental builds,
8080
optionally specifying the output directory (default: {}). See the docstring of
8181
Kconfig.sync_deps() in Kconfiglib for more information.
82-
""".format(
83-
DEFAULT_SYNC_DEPS_PATH
84-
),
82+
""".format(DEFAULT_SYNC_DEPS_PATH),
8583
)
8684

8785
parser.add_argument(
@@ -119,17 +117,16 @@ def main():
119117
kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True)
120118
kconf.load_config()
121119

122-
if args.header_path is None:
123-
if "KCONFIG_AUTOHEADER" in os.environ:
124-
kconf.write_autoconf()
125-
else:
126-
# Kconfiglib defaults to include/generated/autoconf.h to be
127-
# compatible with the C tools. 'config.h' is used here instead for
128-
# backwards compatibility. It's probably a saner default for tools
129-
# as well.
130-
kconf.write_autoconf("config.h")
131-
else:
120+
if args.header_path is not None:
132121
kconf.write_autoconf(args.header_path)
122+
elif "KCONFIG_AUTOHEADER" in os.environ:
123+
kconf.write_autoconf()
124+
else:
125+
# Kconfiglib defaults to include/generated/autoconf.h to be
126+
# compatible with the C tools. 'config.h' is used here instead for
127+
# backwards compatibility. It's probably a saner default for tools
128+
# as well.
129+
kconf.write_autoconf("config.h")
133130

134131
if args.config_out is not None:
135132
kconf.write_config(args.config_out, save_old=False)

0 commit comments

Comments
 (0)