tools.linux.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Justin Stitt <justinstitt@google.com>
To: "Kernel.org Tools" <tools@linux.kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Nick Desaulniers <ndesaulniers@google.com>,
	Justin Stitt <justinstitt@google.com>
Subject: [PATCH b4] b4: add checkpatch via prep --check
Date: Thu, 03 Aug 2023 22:45:53 +0000	[thread overview]
Message-ID: <20230803-add-checkpatch-v1-1-2952aee9e2a8@google.com> (raw)

This patch adds support for the following incantation:

`$ b4 prep --check`

Which will invoke `./scripts/checkpatch.pl` on your entire series. Fails
gracefully if not in a Linux source tree.

I am using `subprocess.run` to invoke `checkpatch`. I'm letting the
stdout go straight to the user without piping or capturing.

Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
To: "Kernel.org Tools" <tools@linux.kernel.org>
To: Nick Desaulniers <ndesaulniers@google.com>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
---
 b4/command.py |  6 ++++++
 b4/ez.py      | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/b4/command.py b/b4/command.py
index 71c1abd..8aa84a2 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -283,6 +283,12 @@ def setup_parser() -> argparse.ArgumentParser:
                        help='Show series info in a format that can be passed to other commands.')
     spp_g.add_argument('--cleanup', metavar='BRANCHNAME', nargs='?', const='_show',
                        help='Archive and remove a prep-tracked branch and all its sent/ tags')
+    spp_g.add_argument(
+        "--check",
+        action="store_true",
+        default=False,
+        help="Run ./scripts/checkpatch.pl on your entire patch series",
+    )
 
     ag_prepn = sp_prep.add_argument_group('Create new branch', 'Create a new branch for working on patch series')
     ag_prepn.add_argument('-n', '--new', dest='new_series_name',
diff --git a/b4/ez.py b/b4/ez.py
index bbaa807..a9e0fc2 100644
--- a/b4/ez.py
+++ b/b4/ez.py
@@ -26,9 +26,10 @@ import gzip
 import io
 import tarfile
 
-from typing import Optional, Tuple, List, Union
 from email import utils
+from typing import Optional, Tuple, List, Union
 from string import Template
+from pathlib import Path
 
 try:
     import patatt
@@ -2157,6 +2158,30 @@ def set_prefixes(prefixes: list) -> None:
         logger.info('No changes to extra prefixes.')
 
 
+def checkpatch() -> int:
+    """
+    Invoke ./scripts/checkpatch.pl if it is available.
+    Only consider the current working directory.
+    Return True if patch is all good, False otherwise.
+    """
+    from subprocess import run
+
+    checkpath_pl_path = Path("./scripts/checkpatch.pl")
+    if not checkpath_pl_path.exists():
+        logger.critical(f'CRITICAL: no {checkpath_pl_path} found.')
+        logger.critical(f'          Navigate to Linux source tree.')
+        sys.exit(1)
+
+    start = get_series_start()
+    end = 'HEAD'
+    cover_commit = find_cover_commit()
+    patches = b4.git_range_to_patches(None, start, end, ignore_commits={cover_commit})
+    command = ['./scripts/checkpatch.pl', '--git'] + [x[0] for x in patches]
+
+    result = run(command)
+
+    return result.returncode
+
 def cmd_prep(cmdargs: argparse.Namespace) -> None:
     check_can_gfr()
     status = b4.git_get_repo_status()
@@ -2165,6 +2190,11 @@ def cmd_prep(cmdargs: argparse.Namespace) -> None:
         logger.critical('          Stash or commit them first.')
         sys.exit(1)
 
+    if cmdargs.check:
+        checkpatch_return_code = checkpatch()
+        logger.info(f"checkpatch return code: {checkpatch_return_code}")
+        return # nothing else needs to happen after a checkpatch call
+
     if cmdargs.reroll:
         msgid = cmdargs.reroll
         msgs = b4.get_pi_thread_by_msgid(msgid, onlymsgids={msgid}, nocache=True)

---
base-commit: 8382882b9fb6c50737b6e19198a259850527d2a6
change-id: 20230803-add-checkpatch-1bc3a54f3bb1

Best regards,
--
Justin Stitt <justinstitt@google.com>


             reply	other threads:[~2023-08-03 22:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 22:45 Justin Stitt [this message]
2023-08-08 16:18 ` [PATCH b4] b4: add checkpatch via prep --check Konstantin Ryabitsev

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=20230803-add-checkpatch-v1-1-2952aee9e2a8@google.com \
    --to=justinstitt@google.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=ndesaulniers@google.com \
    --cc=tools@linux.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).