Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Angelo Compagnucci <angelo.compagnucci@gmail.com>
To: buildroot@buildroot.org
Cc: "Joseph Kogut" <joseph.kogut@gmail.com>,
	"Marcus Folkesson" <marcus.folkesson@gmail.com>,
	"Leo Yu-Chi Liang" <ycliang@andestech.com>,
	"Romain Naour" <romain.naour@gmail.com>,
	"Antoine Tenart" <atenart@kernel.org>,
	"José Luis Salvador Rufo" <salvador.joseluis@gmail.com>,
	"Ricardo Martincoski" <ricardo.martincoski@datacom.com.br>,
	"Fabrice Fontaine" <fontaine.fabrice@gmail.com>,
	"Maxim Kochetkov" <fido_max@inbox.ru>,
	"Angelo Compagnucci" <angelo.compagnucci@gmail.com>,
	"Francois Perrad" <francois.perrad.86@gmail.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"James Knight" <james.d.knight@live.com>,
	"Giulio Benetti" <giulio.benetti@benettiengineering.com>,
	"Bernd Kuhls" <bernd@kuhls.net>,
	"Ricardo Martincoski" <ricardo.martincoski@gmail.com>
Subject: [Buildroot] [PATCH v4 01/15] utils/check-package: factor-out check_disabled()
Date: Sat,  7 Nov 2026 17:34:00 +0100	[thread overview]
Message-ID: <20261107163414.560896-2-angelo.compagnucci@gmail.com> (raw)
In-Reply-To: <20261107163414.560896-1-angelo.compagnucci@gmail.com>

From: Ricardo Martincoski <ricardo.martincoski@gmail.com>

Currently source files analysed by check-package can use a special
comment to hint the script to completely ignore a CheckFunction for the
next line of the source file:

    # check-package Indent

Currently the logic that implements this is at the main check-package
script. But the main package script is not covered by unit tests.

In preparation to support not only
'ignore this CheckFunction for the next source line'
but also
'use special rules for this CheckFunction when testing this file'
move the logic that parses such special comments into the base class
_CheckFunction.

At same time, create unit tests that exercise such code.

Cc: James Knight <james.d.knight@live.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Co-authored-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
---
Changes v3 -> v4:
  - rebase on current master: check_file_using_lib() now reads the file
    in a try/except and also skips the after() check of a disabled
    function; use check_disabled() there too;
  - send together with the package infra checks of the "warn about
    symbols not recognized by a package infra" series and the fixes
    they need.

 utils/check-package                |  4 +--
 utils/checkpackagelib/base.py      |  5 +++
 utils/checkpackagelib/test_base.py | 49 ++++++++++++++++++++++++++++++
 utils/checkpackagelib/test_util.py |  5 ++-
 4 files changed, 60 insertions(+), 3 deletions(-)
 create mode 100644 utils/checkpackagelib/test_base.py

diff --git a/utils/check-package b/utils/check-package
index aa10280f4d..f9978adef4 100755
--- a/utils/check-package
+++ b/utils/check-package
@@ -262,7 +262,7 @@ def check_file_using_lib(fname):
             for lineno, text in enumerate(f):
                 nlines += 1
                 for name, cf in objects:
-                    if cf.disable.search(lastline):
+                    if cf.check_disabled(lastline):
                         continue
                     line_sts = cf.check_line(lineno + 1, text)
                     warn, fail = print_warnings(line_sts, name in xfail)
@@ -276,7 +276,7 @@ def check_file_using_lib(fname):
         return nwarnings, nlines
 
     for name, cf in objects:
-        if cf.disable.search(lastline):
+        if cf.check_disabled(lastline):
             continue
         warn, fail = print_warnings(cf.after(), name in xfail)
         if fail > 0:
diff --git a/utils/checkpackagelib/base.py b/utils/checkpackagelib/base.py
index 0ab6eba9f6..4636eca3a6 100644
--- a/utils/checkpackagelib/base.py
+++ b/utils/checkpackagelib/base.py
@@ -9,6 +9,11 @@ class _CheckFunction(object):
         self.url_to_manual = url_to_manual
         self.disable = re.compile(r"^\s*# check-package .*\b{}\b".format(self.__class__.__name__))
 
+    def check_disabled(self, line_before):
+        if self.disable.search(line_before):
+            return True
+        return False
+
     def before(self):
         pass
 
diff --git a/utils/checkpackagelib/test_base.py b/utils/checkpackagelib/test_base.py
new file mode 100644
index 0000000000..ef266d542c
--- /dev/null
+++ b/utils/checkpackagelib/test_base.py
@@ -0,0 +1,49 @@
+import pytest
+import checkpackagelib.test_util as util
+import checkpackagelib.base as m
+
+
+IgnoreNextLine = [
+    ('without comment to ignore a given CheckFunction',
+     'any',
+     'content to test\n'
+     '# commented content to test\n'
+     'content to test\n'
+     'content to test\n'
+     'content to test\n',
+     [1, 2, 3, 4, 5]),  # set of line numbers for all lines not ignored while testing
+    ('ignore next line',
+     'any',
+     'content to test\n'
+     '# check-package CheckFunctionUnderTest\n'
+     'content to ignore\n'
+     'content to test\n'
+     'content to test\n',
+     [1, 2, 4, 5]),
+    ('comment to ignore one CheckFunction does not affect another one',
+     'any',
+     'content to test\n'
+     '# check-package AnotherCheckFunction\n'
+     'content to test\n'
+     'content to test\n'
+     'content to test\n',
+     [1, 2, 3, 4, 5]),
+    ('ignore 2 CheckFunctions for next line',
+     'any',
+     '# check-package CheckFunctionUnderTest, AnotherCheckFunction\n'
+     'content to ignore\n'
+     '# check-package AnotherCheckFunction, CheckFunctionUnderTest\n'
+     'content to ignore\n'
+     'content to test\n',
+     [1, 3, 5]),
+    ]
+
+
+@pytest.mark.parametrize('testname,filename,string,expected', IgnoreNextLine)
+def test_IgnoreNextLine(testname, filename, string, expected):
+    class CheckFunctionUnderTest(m._CheckFunction):
+        def check_line(self, lineno, text):
+            return lineno
+
+    warnings = util.check_file(CheckFunctionUnderTest, filename, string)
+    assert warnings == expected
diff --git a/utils/checkpackagelib/test_util.py b/utils/checkpackagelib/test_util.py
index 23f2995e27..b06e218498 100644
--- a/utils/checkpackagelib/test_util.py
+++ b/utils/checkpackagelib/test_util.py
@@ -2,7 +2,10 @@ def check_file(check_function, filename, string):
     obj = check_function(filename, 'url')
     result = []
     result.append(obj.before())
+    lastline = ""
     for i, line in enumerate(string.splitlines(True)):
-        result.append(obj.check_line(i + 1, line))
+        if not obj.check_disabled(lastline):
+            result.append(obj.check_line(i + 1, line))
+        lastline = line
     result.append(obj.after())
     return [r for r in result if r is not None]
-- 
2.53.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2026-11-07 16:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-03 16:35 [Buildroot] [next v3 0/3] check-package: support inline flags v3 Ricardo Martincoski
2023-09-03 16:35 ` [Buildroot] [next v3 1/3] utils/check-package: factor-out check_disabled() Ricardo Martincoski
2023-09-03 16:35 ` [Buildroot] [next v3 2/3] utils/check-package: support inline flags Ricardo Martincoski
2023-09-03 16:35 ` [Buildroot] [next v3 3/3] utils/check-package: remove hard-coded list from lib_config:Indent Ricardo Martincoski
2026-11-07 16:33 ` [Buildroot] [PATCH v4 00/15] check-package: warn about symbols not recognized by a package infra, support inline flags Angelo Compagnucci
2026-11-07 16:34   ` Angelo Compagnucci [this message]
2026-11-07 16:34   ` [Buildroot] [PATCH v4 02/15] utils/check-package: " Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 03/15] utils/check-package: remove hard-coded list from lib_config:Indent Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 04/15] package/andes-spi-burn: fix the license files variable Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 05/15] package/fbv: drop the unused configure options Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 06/15] package/usbip: fix the configure options variable Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 07/15] package/postgresql: drop the unused install-world options Angelo Compagnucci
2026-11-09  7:13     ` Maxim Kochetkov via buildroot
2026-11-07 16:34   ` [Buildroot] [PATCH v4 08/15] package/libselinux: drop the unused make environment Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 09/15] package/zfs: drop the unused module subdirectories Angelo Compagnucci
2026-11-10 12:52     ` José Luis Salvador Rufo
2026-11-07 16:34   ` [Buildroot] [PATCH v4 10/15] package/mesa3d: drop the unused host Vulkan drivers Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 11/15] package/nxp-mwifiex: drop the unused make options Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 12/15] package/libglib2/libglib2-bootstrap: drop unused variables Angelo Compagnucci
2026-11-11 22:46     ` Fiona Klute via buildroot
2026-11-07 16:34   ` [Buildroot] [PATCH v4 13/15] package/linux-pam: fix linking with the NLS and atomic libraries Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 14/15] utils/check-package: warn about symbols not recognized by a package infra Angelo Compagnucci
2026-11-07 16:34   ` [Buildroot] [PATCH v4 15/15] utils/check-package: warn about disabled install Angelo Compagnucci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261107163414.560896-2-angelo.compagnucci@gmail.com \
    --to=angelo.compagnucci@gmail.com \
    --cc=atenart@kernel.org \
    --cc=bernd@kuhls.net \
    --cc=buildroot@buildroot.org \
    --cc=fido_max@inbox.ru \
    --cc=fontaine.fabrice@gmail.com \
    --cc=francois.perrad.86@gmail.com \
    --cc=giulio.benetti@benettiengineering.com \
    --cc=james.d.knight@live.com \
    --cc=joseph.kogut@gmail.com \
    --cc=marcus.folkesson@gmail.com \
    --cc=ricardo.martincoski@datacom.com.br \
    --cc=ricardo.martincoski@gmail.com \
    --cc=romain.naour@gmail.com \
    --cc=salvador.joseluis@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=ycliang@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox