git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] add coccicheck make target

From
René Scharfe <l.s.r@web.de>
Date
Sep 15, 2016, 18:30 UTC
Message-ID
<e47359bc-1bf0-e1bd-b076-6f95c3f15abd@web.de>

Provide a simple way to run Coccinelle against all source files, in the form of a Makefile target. Running "make coccicheck" applies each .cocci file in contrib/coccinelle/ on all source files. It generates a .patch file for each .cocci file, containing the actual changes for effecting the transformations described by the semantic patches.

Non-empty .patch files are reported. They can be applied to the work tree using "patch -p0", but should be checked to e.g. make sure they don't screw up formatting or create circular references.

Coccinelle's diagnostic output (stderr) is piped into .log files.

Linux has a much more elaborate make target of the same name; let's start nice and easy.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 Makefile | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/Makefile b/Makefile
index 7f18492..74b2788 100644
--- a/Makefile
+++ b/Makefile
@@ -461,6 +461,7 @@ CURL_CONFIG = curl-config
 PTHREAD_LIBS = -lpthread
 PTHREAD_CFLAGS =
 GCOV = gcov
+SPATCH = spatch
 
 export TCL_PATH TCLTK_PATH
 
@@ -2307,6 +2308,18 @@ check: common-cmds.h
 		exit 1; \
 	fi
 
+C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
+%.cocci.patch: %.cocci $(C_SOURCES)
+	@echo '    ' SPATCH $<; \
+	for f in $(C_SOURCES); do \
+		$(SPATCH) --sp-file $< $$f; \
+	done >$@ 2>$@.log; \
+	if test -s $@; \
+	then \
+		echo '    ' SPATCH result: $@; \
+	fi
+coccicheck: $(patsubst %.cocci,%.cocci.patch,$(wildcard contrib/coccinelle/*.cocci))
+
 ### Installation rules
 
 ifneq ($(filter /%,$(firstword $(template_dir))),)
@@ -2498,6 +2511,7 @@ clean: profile-clean coverage-clean
 	$(RM) -r $(GIT_TARNAME) .doc-tmp-dir
 	$(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
 	$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
+	$(RM) contrib/coccinelle/*.cocci.patch*
 	$(MAKE) -C Documentation/ clean
 ifndef NO_PERL
 	$(MAKE) -C gitweb clean
-- 
2.10.0
Message 1 of 1 in “add coccicheck make target”
  1. add coccicheck make targetRené Scharfe, Sep 15, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.