Skip to content

Commit f5c2bc2

Browse files
peffgitster
authored andcommitted
Makefile: detect errors in running spatch
The "make coccicheck" target runs spatch against each source file. But it does so in a for loop, so "make" never sees the exit code of spatch. Worse, it redirects stderr to a log file, so the user has no indication of any failure. And then to top it all off, because we touched the patch file's mtime, make will refuse to repeat the command because it think the target is up-to-date. So for example: $ make coccicheck SPATCH=does-not-exist SPATCH contrib/coccinelle/free.cocci SPATCH contrib/coccinelle/qsort.cocci SPATCH contrib/coccinelle/xstrdup_or_null.cocci SPATCH contrib/coccinelle/swap.cocci SPATCH contrib/coccinelle/strbuf.cocci SPATCH contrib/coccinelle/object_id.cocci SPATCH contrib/coccinelle/array.cocci $ make coccicheck SPATCH=does-not-exist make: Nothing to be done for 'coccicheck'. With this patch, you get: $ make coccicheck SPATCH=does-not-exist SPATCH contrib/coccinelle/free.cocci /bin/sh: 4: does-not-exist: not found Makefile:2338: recipe for target 'contrib/coccinelle/free.cocci.patch' failed make: *** [contrib/coccinelle/free.cocci.patch] Error 1 It also dumps the log on failure, so any errors from spatch itself (like syntax errors in our .cocci files) will be seen by the user. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit f5c2bc2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,9 +2329,17 @@ check: common-cmds.h
23292329
C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
23302330
%.cocci.patch: %.cocci $(C_SOURCES)
23312331
@echo ' ' SPATCH $<; \
2332+
ret=0; \
23322333
for f in $(C_SOURCES); do \
2333-
$(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS); \
2334-
done >$@ 2>$@.log; \
2334+
$(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
2335+
{ ret=$$?; break; }; \
2336+
done >$@+ 2>$@.log; \
2337+
if test $$ret != 0; \
2338+
then \
2339+
cat $@.log; \
2340+
exit 1; \
2341+
fi; \
2342+
mv $@+ $@; \
23352343
if test -s $@; \
23362344
then \
23372345
echo ' ' SPATCH result: $@; \

0 commit comments

Comments
 (0)