Skip to contentSkip to conversation

Exit with non-zero status

Cocci Paul Chaignon 2 participants 4 messages Apr 29, 2020

lore
Share & tools
lore
#0 lore raw

Hi everyone,

I am trying to exit spatch with a non-zero exit status when required changes have been found. I have tried to add a rule with finalize:python and the following code:

@finalize:python@
@@
exit(cnt)

where cnt is incremented by another Python rule everytime a required change is found. This works as expected except for the --in-place option which becomes ineffective.

Is this a bug, or is finalize:python not intended to be used in that manner? Is it possible to overwrite spatch's exit status?

Thanks,
Paul
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 10 lines · Paul Chaignon

Hi everyone,

I am trying to exit spatch with a non-zero exit status when required changes have been found. I have tried to add a rule with finalize:python and the following code:

@finalize:python@
@@
exit(cnt)

Quoted 6 lines

where cnt is incremented by another Python rule everytime a required change is found. This works as expected except for the --in-place option which becomes ineffective.

Is this a bug, or is finalize:python not intended to be used in that manner? Is it possible to overwrite spatch's exit status?

I'm actually surprised that this would ever work...

Finalize was intended for processing information in general, eg printing some statistics about what was matched.

Would it be feasible to print cnt instead?

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 21 lines · Julia Lawall
Quoted 10 lines · Paul Chaignon

Hi everyone,

I am trying to exit spatch with a non-zero exit status when required changes have been found. I have tried to add a rule with finalize:python and the following code:

@finalize:python@
@@
exit(cnt)

Quoted 6 lines

where cnt is incremented by another Python rule everytime a required change is found. This works as expected except for the --in-place option which becomes ineffective.

Is this a bug, or is finalize:python not intended to be used in that manner? Is it possible to overwrite spatch's exit status?

Quoted 6 lines

I'm actually surprised that this would ever work...

Finalize was intended for processing information in general, eg printing some statistics about what was matched.

Would it be feasible to print cnt instead?

Sure. I can easily get around this issue by e.g. grepping for spatch's messages in a wrapper script. Getting spatch to return a non-zero exit status is just a convenience. I thought that would be a fairly common use case.

Thanks for the quick answer as always :)
Paul

Quoted 2 lines

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw
Quoted 27 lines · Paul Chaignon
Quoted 26 lines · Julia Lawall
Quoted 10 lines · Paul Chaignon

Hi everyone,

I am trying to exit spatch with a non-zero exit status when required changes have been found. I have tried to add a rule with finalize:python and the following code:

@finalize:python@
@@
exit(cnt)

Quoted 6 lines

where cnt is incremented by another Python rule everytime a required change is found. This works as expected except for the --in-place option which becomes ineffective.

Is this a bug, or is finalize:python not intended to be used in that manner? Is it possible to overwrite spatch's exit status?

I'm actually surprised that this would ever work...

Finalize was intended for processing information in general, eg printing some statistics about what was matched.

Quoted 6 lines
Quoted 1 line

Would it be feasible to print cnt instead?

Sure. I can easily get around this issue by e.g. grepping for spatch's messages in a wrapper script. Getting spatch to return a non-zero exit status is just a convenience. I thought that would be a fairly common use case.

I'll add it to the "list of features someone has asked for and might get implemented some day in the future"...

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci