travis-ci: fail if Coccinelle static analysis found something to transform
authorSZEDER Gábor <szeder.dev@gmail.com>
Mon, 23 Jul 2018 13:02:30 +0000 (15:02 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Jul 2018 19:08:38 +0000 (12:08 -0700)
Coccinelle's and in turn 'make coccicheck's exit code only indicates
that Coccinelle managed to finish its analysis without any errors
(e.g. no unknown --options, no missing files, no syntax errors in the
semantic patches, etc.), but it doesn't indicate whether it found any
undesired code patterns to transform or not. To find out the latter,
one has to look closer at 'make coccicheck's standard output and look
for lines like:

SPATCH result: contrib/coccinelle/<something>.cocci.patch

And this only indicates that there is something to transform, but to
see what the suggested transformations are one has to actually look
into those '*.cocci.patch' files.

This makes the automated static analysis build job on Travis CI not
particularly useful, because it neither draws our attention to
Coccinelle's findings, nor shows the actual findings. Consequently,
new topics introducing undesired code patterns graduated to master
on several occasions without anyone noticing.

The only way to draw attention in such an automated setting is to fail
the build job. Therefore, modify the 'ci/run-static-analysis.sh'
build script to check all the resulting '*.cocci.patch' files, and
fail the build job if any of them turns out to be not empty. Include
those files' contents, i.e. Coccinelle's suggested transformations, in
the build job's trace log, so we'll know why it failed.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ci/run-static-analysis.sh
index fa719c9ef94c205ec51eff9fc9c8a1c73a1f2378..5688f261d0813d4b2b55baeb5e404fcfef80b5d7 100755 (executable)
@@ -7,4 +7,23 @@
 
 make --jobs=2 coccicheck
 
+set +x
+
+fail=
+for cocci_patch in contrib/coccinelle/*.patch
+do
+       if test -s "$cocci_patch"
+       then
+               echo "$(tput setaf 1)Coccinelle suggests the following changes in '$cocci_patch':$(tput sgr0)"
+               cat "$cocci_patch"
+               fail=UnfortunatelyYes
+       fi
+done
+
+if test -n "$fail"
+then
+       echo "$(tput setaf 1)error: Coccinelle suggested some changes$(tput sgr0)"
+       exit 1
+fi
+
 save_good_tree