Coccinelle Archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] [PATCH v2] scripts: coccicheck: Fix chain mode in coccicheck
@ 2021-03-06 20:05 Davidson Francis
  2021-04-27  7:14 ` Davidson Francis
  0 siblings, 1 reply; 2+ messages in thread
From: Davidson Francis @ 2021-03-06 20:05 UTC (permalink / raw)
  To: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek
  Cc: Davidson Francis, cocci, linux-kernel

As described in the Coccinelle documentation (Documentation/dev-tools/
coccinelle.rst), chain mode should try patch, report, context, and org
modes until one of them succeed.

It turns out that currently, the 'run_cmd_parmap' function, by failing
to run $SPATCH, rather than returning an error code, kills the execution
of the script by executing the exit command, rather than returning the
error code.

This way, when running coccicheck in chain mode, as in:
    $ make coccicheck MODE=chain

the first .cocci file that does not support one of the virtual rules
stops the execution of the makefile, rather than trying the remaining
rules as specified in the documentation.

Therefore, modify the coccicheck script to return the error code,
rather than terminating the script. When returning the error code,
it returns the same value obtained in run_cmd, instead of the
generic value '1'.

Signed-off-by: Davidson Francis <davidsondfgl@gmail.com>
---
Changes in v2:
* Use the same return value from run_cmd as the exit value

 scripts/coccicheck | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/coccicheck b/scripts/coccicheck
index 65fee63aeadb..165701657c5a 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -153,7 +153,7 @@ run_cmd_parmap() {
 	err=$?
 	if [[ $err -ne 0 ]]; then
 		echo "coccicheck failed"
-		exit $err
+		return $err
 	fi
 }
 
@@ -251,14 +251,14 @@ coccinelle () {
 	run_cmd $SPATCH -D context \
 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS               || \
 	run_cmd $SPATCH -D org     \
-		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit 1
+		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit $?
     elif [ "$MODE" = "rep+ctxt" ] ; then
 	run_cmd $SPATCH -D report  \
 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
 	run_cmd $SPATCH -D context \
-		$FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
+		$FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit $?
     else
-	run_cmd $SPATCH -D $MODE   $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
+	run_cmd $SPATCH -D $MODE   $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit $?
     fi
 
 }
-- 
2.29.1

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Cocci] [PATCH v2] scripts: coccicheck: Fix chain mode in coccicheck
  2021-03-06 20:05 [Cocci] [PATCH v2] scripts: coccicheck: Fix chain mode in coccicheck Davidson Francis
@ 2021-04-27  7:14 ` Davidson Francis
  0 siblings, 0 replies; 2+ messages in thread
From: Davidson Francis @ 2021-04-27  7:14 UTC (permalink / raw)
  To: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek
  Cc: cocci, linux-kernel

On Sat, Mar 06, 2021 at 05:05:41PM -0300, Davidson Francis wrote:
> As described in the Coccinelle documentation (Documentation/dev-tools/
> coccinelle.rst), chain mode should try patch, report, context, and org
> modes until one of them succeed.
> 
> It turns out that currently, the 'run_cmd_parmap' function, by failing
> to run $SPATCH, rather than returning an error code, kills the execution
> of the script by executing the exit command, rather than returning the
> error code.
> 
> This way, when running coccicheck in chain mode, as in:
>     $ make coccicheck MODE=chain
> 
> the first .cocci file that does not support one of the virtual rules
> stops the execution of the makefile, rather than trying the remaining
> rules as specified in the documentation.
> 
> Therefore, modify the coccicheck script to return the error code,
> rather than terminating the script. When returning the error code,
> it returns the same value obtained in run_cmd, instead of the
> generic value '1'.
> 
> Signed-off-by: Davidson Francis <davidsondfgl@gmail.com>
> ---
> Changes in v2:
> * Use the same return value from run_cmd as the exit value
> 
>  scripts/coccicheck | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/coccicheck b/scripts/coccicheck
> index 65fee63aeadb..165701657c5a 100755
> --- a/scripts/coccicheck
> +++ b/scripts/coccicheck
> @@ -153,7 +153,7 @@ run_cmd_parmap() {
>  	err=$?
>  	if [[ $err -ne 0 ]]; then
>  		echo "coccicheck failed"
> -		exit $err
> +		return $err
>  	fi
>  }
>  
> @@ -251,14 +251,14 @@ coccinelle () {
>  	run_cmd $SPATCH -D context \
>  		$FLAGS --cocci-file $COCCI $OPT $OPTIONS               || \
>  	run_cmd $SPATCH -D org     \
> -		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit 1
> +		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit $?
>      elif [ "$MODE" = "rep+ctxt" ] ; then
>  	run_cmd $SPATCH -D report  \
>  		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
>  	run_cmd $SPATCH -D context \
> -		$FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
> +		$FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit $?
>      else
> -	run_cmd $SPATCH -D $MODE   $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
> +	run_cmd $SPATCH -D $MODE   $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit $?
>      fi
>  
>  }
> -- 
> 2.29.1
> 

Ping for review.

Regards,
Davidson Francis.

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-06 20:05 [Cocci] [PATCH v2] scripts: coccicheck: Fix chain mode in coccicheck Davidson Francis
2021-04-27  7:14 ` Davidson Francis

Coccinelle Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git