Skip to content

Commit

Permalink
make: add checkpatch to Makefile
Browse files Browse the repository at this point in the history
This automatically retrieves the checkpatch.pl script from the
Linux kernel repo and runs it to check the modified or untracked
source files in the current repo.

The command can be invoke with:
$ make checkpatch

Signed-off-by: Martin Belanger <[email protected]>
  • Loading branch information
Martin Belanger committed Oct 12, 2023
1 parent ff742e7 commit e468aca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ rpm: ${BUILD-DIR}
tar rf libnvme.tar ${BUILD-DIR}/libnvme.spec
gzip -f -9 libnvme.tar
rpmbuild -ta libnvme.tar.gz -v

# Retrieve and Invoke Linux kernel's checkpatch script on modified source files
ifeq (checkpatch,$(strip $(filter $(MAKECMDGOALS),checkpatch)))
MODIFIED-FILES := $(strip $(shell ./scripts/get-modified-src-files.py))
endif

${BUILD-DIR}/checkpatch.pl: ${BUILD-DIR}
wget "https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl" -O $@
chmod +x $@

.PHONY: checkpatch
checkpatch: ${BUILD-DIR}/checkpatch.pl
ifneq (,${MODIFIED-FILES})
${BUILD-DIR}/checkpatch.pl -no-tree ${MODIFIED-FILES}
endif

25 changes: 25 additions & 0 deletions scripts/get-modified-src-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of libnvme.
# Copyright (c) 2023 Dell Inc.
#
# Authors: Martin Belanger <[email protected]>

"""List source files in current git repo that have been modified or are new (untracked)"""

import shutil
import subprocess

GIT = shutil.which("git")
SRC_FILES = (".c", ".h", ".cpp", ".cc")

cmd = f"{GIT} ls-files --modified --others --exclude-standard"
p = subprocess.run(
cmd, stdout=subprocess.PIPE, check=True, universal_newlines=True, shell=True
)

modified_files = p.stdout.splitlines()
modified_src_files = [fname for fname in modified_files if fname.endswith(SRC_FILES)]

print(" ".join(modified_src_files))

0 comments on commit e468aca

Please sign in to comment.