Skip to contentSkip to conversation

coccicheck: fail "make" when it fails

RFC PATCH Superseded Junio C Hamano 4 participants 6 messages Jun 19, 2025 – Jun 23, 2025 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 coccicheck: fail "make" when it fails

With "make coccicheck", we generate contrib/coccinelle/*.cocci.patch files that contain changes suggested by semantic patches, but "make" succeeds. Admittedly, not many developers may run "make coccicheck" in the first place, but it makes it harder to notice when they do run it after they introduced an iffy piece of code.

Check that the resulting cocci.patch files are all empty.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index 70d1543b6b..2c17868a24 100644
@@ -3475,8 +3475,10 @@ coccicheck-test: $(COCCI_TEST_RES_GEN)
 coccicheck: coccicheck-test
 ifdef SPATCH_CONCAT_COCCI
 coccicheck: contrib/coccinelle/ALL.cocci.patch
+	! test -s contrib/coccinelle/ALL.cocci.patch
 else
 coccicheck: $(COCCICHECK_PATCHES_INTREE)
+	test $$(cat $(COCCICHECK_PATCHES_INTREE) | wc -c) = 0
 endif
 
 # See contrib/coccinelle/README
#1 lore raw
Quoted 5 lines · Junio C Hamano

With "make coccicheck", we generate contrib/coccinelle/*.cocci.patch files that contain changes suggested by semantic patches, but "make" succeeds. Admittedly, not many developers may run "make coccicheck" in the first place, but it makes it harder to notice when they do run it after they introduced an iffy piece of code.

I admit that I do not run coccicheck very often. But I have definitely been surprised by it not triggering a make failure when there are changes to be made. So I'd be in favor of this patch.

-Peff

#2 lore raw
In reply to Junio C Hamano

Makefile coccicheck-test: $(COCCI_TEST_RES_GEN) · line 3481

Quoted 13 lines · Junio C Hamano
Makefile +2 -0
index 70d1543b6b..2c17868a24 100644
@@ -3475,8 +3475,10 @@ coccicheck-test: $(COCCI_TEST_RES_GEN)
 coccicheck: coccicheck-test
 ifdef SPATCH_CONCAT_COCCI
 coccicheck: contrib/coccinelle/ALL.cocci.patch
+	! test -s contrib/coccinelle/ALL.cocci.patch
 else
 coccicheck: $(COCCICHECK_PATCHES_INTREE)
+	test $$(cat $(COCCICHECK_PATCHES_INTREE) | wc -c) = 0

Definitely a nitpick, but I think using -eq instead of = and might even come handy from a portability point of view.

Just like Peff, agree would be a big improvement to have this changed for usability.

Carlo

#3 lore raw
Quoted 6 lines · Carlo Marcelo Arenas Belón
Quoted 2 lines · Junio C Hamano

coccicheck: $(COCCICHECK_PATCHES_INTREE)
+ test $$(cat $(COCCICHECK_PATCHES_INTREE) | wc -c) = 0

Definitely a nitpick, but I think using -eq instead of = and might even come handy from a portability point of view.

Junio has previously expressed[*] a preference for = over -eq in this sort of situation.

[*]: https://lore.kernel.org/git/[email protected]/

#4 lore raw
Quoted 6 lines · Eric Sunshine
Quoted 4 lines · Carlo Marcelo Arenas Belón
Quoted 2 lines · Junio C Hamano

coccicheck: $(COCCICHECK_PATCHES_INTREE)
+ test $$(cat $(COCCICHECK_PATCHES_INTREE) | wc -c) = 0

Quoted 7 lines
Quoted 2 lines

Definitely a nitpick, but I think using -eq instead of = and might even come handy from a portability point of view.

Junio has previously expressed[*] a preference for = over -eq in this sort of situation.

[*]: https://lore.kernel.org/git/[email protected]/

Heh, you have an infinite more memory than I have ;-)

That one is 12 years ago or so, isn't it? Not that I changed my stance.

Having said that, I suspect

    ! grep -q ^ $(COCCICHECK_PATCHES_INTREE)

might have been easier to understand. We do not want any file with even a single line in it, and "grep -q" knows to short-circuit (i.e. if the first file in the COCCICHECK_PATCHES_INTREE list is not empty, it does not even bother to open the rest of the files).

#5 lore raw

PATCH v2 1/1 coccicheck: fail "make" when it fails

In reply to Junio C Hamano

With "make coccicheck", we generate contrib/coccinelle/*.cocci.patch files that contain changes suggested by semantic patches, but "make" succeeds. Admittedly, not many developers may run "make coccicheck" in the first place, but it makes it harder to notice when they do run it after they introduced an iffy piece of code.

Check that the resulting cocci.patch files are all empty.

---
 Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Makefile +5 -2
index 97e8385b66..8f1e9424a7 100644
@@ -3422,11 +3422,14 @@ endif
 coccicheck-test: $(COCCI_TEST_RES_GEN)
 
 coccicheck: coccicheck-test
+
 ifdef SPATCH_CONCAT_COCCI
-coccicheck: contrib/coccinelle/ALL.cocci.patch
+COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = contrib/coccinelle/ALL.cocci.patch
 else
-coccicheck: $(COCCICHECK_PATCHES_INTREE)
+COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = $(COCCICHECK_PATCHES_INTREE)
 endif
+coccicheck: $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES)
+	! grep -q ^ $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES) /dev/null
 
 # See contrib/coccinelle/README
 coccicheck-pending: coccicheck-test

Range-diff against v1:
1: 163a63f2cf ! 1: dee873e931 coccicheck: fail "make" when it fails
@@ Commit message

## Makefile ##
-@@ Makefile: coccicheck-test: $(COCCI_TEST_RES_GEN)
+@@ Makefile: endif
+ coccicheck-test: $(COCCI_TEST_RES_GEN)
+
coccicheck: coccicheck-test
++
ifdef SPATCH_CONCAT_COCCI
- coccicheck: contrib/coccinelle/ALL.cocci.patch
-+ ! test -s contrib/coccinelle/ALL.cocci.patch
+-coccicheck: contrib/coccinelle/ALL.cocci.patch ++COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = contrib/coccinelle/ALL.cocci.patch
else
- coccicheck: $(COCCICHECK_PATCHES_INTREE)
-+ test $$(cat $(COCCICHECK_PATCHES_INTREE) | wc -c) = 0
+-coccicheck: $(COCCICHECK_PATCHES_INTREE) ++COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = $(COCCICHECK_PATCHES_INTREE)
endif
++coccicheck: $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES)
++ ! grep -q ^ $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES) /dev/null

# See contrib/coccinelle/README
+ coccicheck-pending: coccicheck-test

Signature · 1 line
2.50.0-243-g67b26bc0ed