diff mbox series

[b4,2/3] ez: verify default checkpatch.pl args before running them

Message ID 20240815-extend-checkpatch-v1-2-ab7f654be699@linaro.org (mailing list archive)
State Changes Requested
Headers show
Series Extend checkpatch.pl compatibilities | expand

Commit Message

Manos Pitsidianakis Aug. 15, 2024, 1:36 p.m. UTC
For projects which use a scripts/checkpatch.pl workflow like the kernel
but do not sync its source [ever/frequently], like QEMU, some arguments
might not be available. This leads to checkpatch not working if it is
automagically detected without the user's knowledge leading to hard to
diagnose errors.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
 src/b4/ez.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/b4/ez.py b/src/b4/ez.py
index 20fbd76..013a63c 100644
--- a/src/b4/ez.py
+++ b/src/b4/ez.py
@@ -1674,7 +1674,17 @@  def get_check_cmds() -> Tuple[List[str], List[str]]:
         if topdir:
             checkpatch = os.path.join(topdir, 'scripts', 'checkpatch.pl')
             if os.access(checkpatch, os.X_OK):
-                ppcmds = [f'{checkpatch} -q --terse --no-summary --mailback --showfile']
+                ecode, help_out, err = b4._run_command([checkpatch, "-h"], stdin=None, rundir=topdir)
+                help_out = help_out.decode(errors='replace').strip() if help_out else ""
+                if ecode == 0:
+                    ppcmds = f'{checkpatch}'
+                    for arg in ["q", "-terse", "-no-summary", "-mailback", "-showfile"]:
+                        if ("-" + arg + " ") in help_out:
+                            ppcmds += " " + "-" + arg
+                    ppcmds += " -"
+                    ppcmds = [ppcmds]
+                else:
+                    ppcmds = [f'{checkpatch} -q --terse --no-summary --mailback --showfile -']
 
     # TODO: support for a whole-series check command, (pytest, etc)
     return ppcmds, scmds