From 9ed07ada0e1476a676450056a20226b88076025e Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sun, 15 Oct 2017 11:55:53 +0200 Subject: Coccinelle: make DEBUG_FILE option more useful Make coccicheck checked for the existence of DEBUG_FILE on each semantic patch, and bailed if it already existed. This meant that DEBUG_FILE was useless for checking more than one semantic patch at a time. Now the check is moved to the start of make coccicheck, and the 2> is changed to a 2>> to append to the file on each semantic patch. Furthermore, the spatch command that is run for each semantic patch is also added to the DEBUG_FILE, to make clear what each stdout trace corresponds to. Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccicheck | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'scripts/coccicheck') diff --git a/scripts/coccicheck b/scripts/coccicheck index ec487b8e7051..864b17e05e63 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -122,15 +122,8 @@ run_cmd_parmap() { if [ $VERBOSE -ne 0 ] ; then echo "Running ($NPROC in parallel): $@" fi - if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then - if [ -f $DEBUG_FILE ]; then - echo "Debug file $DEBUG_FILE exists, bailing" - exit - fi - else - DEBUG_FILE="/dev/null" - fi - $@ 2>$DEBUG_FILE + echo $@ >>$DEBUG_FILE + $@ 2>>$DEBUG_FILE if [[ $? -ne 0 ]]; then echo "coccicheck failed" exit $? @@ -246,6 +239,15 @@ coccinelle () { } +if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then + if [ -f $DEBUG_FILE ]; then + echo "Debug file $DEBUG_FILE exists, bailing" + exit + fi +else + DEBUG_FILE="/dev/null" +fi + if [ "$COCCI" = "" ] ; then for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do coccinelle $f -- cgit v1.2.3 From e0be348e4d6ebd660c9558bcee50f648491cfef6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 26 Oct 2017 13:50:38 +0900 Subject: coccinelle: grep Options and Requires fields more precisely Currently, the required version for badzero.cocci is picked up from its "Comments:" line since it contains the word "Requires". Surprisingly, ld-version.sh can extract the version number from the string "Requires Coccinelle version 1.0.0-rc20 or later", but this expectation is fragile. Fix the .cocci file. I removed "-rc20" because ld-version.sh cannot handle it. Make the coccicheck script to see exact patterns for "Options:" and "Requires:" in order to avoid accidental matching to what just happens to appear in comment lines. Signed-off-by: Masahiro Yamada Acked-by: Julia Lawall Acked-by: Nicolas Palix --- scripts/coccicheck | 4 ++-- scripts/coccinelle/null/badzero.cocci | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/coccicheck') diff --git a/scripts/coccicheck b/scripts/coccicheck index 864b17e05e63..97f28f0f9498 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -168,8 +168,8 @@ OPTIONS="$OPTIONS $SPFLAGS" coccinelle () { COCCI="$1" - OPT=`grep "Option" $COCCI | cut -d':' -f2` - REQ=`grep "Requires" $COCCI | cut -d':' -f2 | sed "s| ||"` + OPT=`grep "Options:" $COCCI | cut -d':' -f2` + REQ=`grep "Requires:" $COCCI | cut -d':' -f2 | sed "s| ||"` REQ_NUM=$(echo $REQ | ${DIR}/scripts/ld-version.sh) if [ "$REQ_NUM" != "0" ] ; then if [ "$SPATCH_VERSION_NUM" -lt "$REQ_NUM" ] ; then diff --git a/scripts/coccinelle/null/badzero.cocci b/scripts/coccinelle/null/badzero.cocci index 5551da2b4fe3..f597c8007b76 100644 --- a/scripts/coccinelle/null/badzero.cocci +++ b/scripts/coccinelle/null/badzero.cocci @@ -10,7 +10,7 @@ // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. // URL: http://coccinelle.lip6.fr/ -// Comments: Requires Coccinelle version 1.0.0-rc20 or later +// Requires: 1.0.0 // Options: virtual patch -- cgit v1.2.3 From cd1af7cfbbdc7719b74ad9f3c88e50bb77713664 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 26 Oct 2017 13:55:51 +0900 Subject: coccinelle: fix verbose message about .cocci file being run If you run coccicheck with V=1 and COCCI=, you will see a strange path to the semantic patch file. For example, run the following: $ make V=1 COCCI=scripts/coccinelle/free/kfree.cocci coccicheck [ snip ] The semantic patch that makes this report is available in scriptcoccinelle/free/kfree.cocci. Notice "s/" was dropped from "scripts/coccinelle/free/kfree.cocci". When running coccicheck without O=, $srctree is expanded to ".", which represents one arbitrary character in the regular expression. Using sed is not a good choice here. Strip $srctree/ simply without sed. Signed-off-by: Masahiro Yamada Acked-by: Nicolas Palix --- scripts/coccicheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/coccicheck') diff --git a/scripts/coccicheck b/scripts/coccicheck index 97f28f0f9498..41a85b1ed35e 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -186,7 +186,7 @@ coccinelle () { if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then - FILE=`echo $COCCI | sed "s|$srctree/||"` + FILE=${COCCI#$srctree/} echo "Processing `basename $COCCI`" echo "with option(s) \"$OPT\"" -- cgit v1.2.3