From 6b1d9ab4e721b92c08f602a8d37ca1be08f88e9f Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Wed, 12 Nov 2025 12:06:43 +0100 Subject: [PATCH] utils/check-package: add a check for 'default n' in Config.in files Boolean Config.in symbols default to 'n', so we typically do not add such redundant lines. Signed-off-by: Peter Korsgaard Signed-off-by: Julien Olivain (cherry picked from commit 279cbbdb646e7136c4d8b3b5b44d9b4e31ed31dd) Signed-off-by: Thomas Perale --- utils/checkpackagelib/lib_config.py | 11 ++++++++ utils/checkpackagelib/test_lib_config.py | 33 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/utils/checkpackagelib/lib_config.py b/utils/checkpackagelib/lib_config.py index bf975d7a3b..202baa7f1b 100644 --- a/utils/checkpackagelib/lib_config.py +++ b/utils/checkpackagelib/lib_config.py @@ -242,6 +242,17 @@ class Indent(_CheckFunction): text] +class NoDefaultN(_CheckFunction): + DEFAULTN = re.compile(r"^\tdefault n$") + + def check_line(self, lineno, text): + text_nocomments = text.split("#")[0].rstrip() + if self.DEFAULTN.match(text_nocomments): + return ["{}:{}: boolean symbols default to 'n', so 'default n' is redundant" + .format(self.filename, lineno), + text] + + class RedefinedConfig(_CheckFunction): CONFIG = re.compile(r"^\s*(menu|)config\s+(BR2_\w+)\b") IF = re.compile(r"^\s*if\s+([^#]*)\b") diff --git a/utils/checkpackagelib/test_lib_config.py b/utils/checkpackagelib/test_lib_config.py index 474d17105e..35614ef152 100644 --- a/utils/checkpackagelib/test_lib_config.py +++ b/utils/checkpackagelib/test_lib_config.py @@ -387,6 +387,39 @@ def test_Indent(testname, filename, string, expected): assert warnings == expected +NoDefaultN = [ + ('good example', + 'any', + 'config BR2_PACKAGE_FOO\n' + '\tdefault y\n', + []), + ('default n', + 'any', + 'config BR2_PACKAGE_FOO\n' + '\tdefault n\n', + [['any:2: boolean symbols default to \'n\', so \'default n\' is redundant', + '\tdefault n\n']]), + ('default n with comment', + 'any', + 'config BR2_PACKAGE_FOO\n' + '\tdefault n # this is a comment\n', + [['any:2: boolean symbols default to \'n\', so \'default n\' is redundant', + '\tdefault n # this is a comment\n']]), + ('default n with trailing whitespace', + 'any', + 'config BR2_PACKAGE_FOO\n' + '\tdefault n \t\n', + [['any:2: boolean symbols default to \'n\', so \'default n\' is redundant', + '\tdefault n \t\n']]) + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', NoDefaultN) +def test_NoDefaultN(testname, filename, string, expected): + warnings = util.check_file(m.NoDefaultN, filename, string) + assert warnings == expected + + RedefinedConfig = [ ('no redefinition', 'any',