2011-06-08 03:30:00

by Greg Dietsche

[permalink] [raw]
Subject: coccicheck: Add M= option

This patch set adds support for M= to coccicheck. This makes
using Coccinelle easier for those wishing to check specific
drivers or sub systems with Coccinelle.

Thanks!
Greg

[PATCH 1/2] coccinelle.txt update documentation to include M= option
[PATCH 2/2] coccicheck: add M option to control which dir is processed


2011-06-08 03:29:59

by Greg Dietsche

[permalink] [raw]
Subject: [PATCH 1/2] coccicheck: add M= option to control which dir is processed

Examples:
make coccicheck M=drivers/net/wireless/
make coccicheck SUBDIRS=drivers/net/wireless/

Signed-off-by: Greg Dietsche <[email protected]>
---
scripts/coccicheck | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/coccicheck b/scripts/coccicheck
index 1bb1a1b..6f08efa 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -10,13 +10,22 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
# OPTIONS=$*

# Workaround for Coccinelle < 0.2.3
- FLAGS="-I $srctree/include -very_quiet"
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
+ FLAGS="-I $srctree/include -very_quiet"
+ else
+ echo 'M= is only supported for Coccinelle >= 0.2.3'
+ exit 1
+ fi
shift $(( $# - 1 ))
OPTIONS=$1
else
ONLINE=0
FLAGS="-very_quiet"
- OPTIONS="-dir $srctree"
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
+ OPTIONS="-dir $srctree"
+ else
+ OPTIONS="-dir $KBUILD_EXTMOD"
+ fi
fi

if [ ! -x "$SPATCH" ]; then
--
1.7.2.5

2011-06-08 03:30:03

by Greg Dietsche

[permalink] [raw]
Subject: [PATCH 2/2] coccinelle.txt: update documentation to include M= option

Adding documentation for the new M= option which limits Coccinelle
to a specific set of directories.

Signed-off-by: Greg Dietsche <[email protected]>
---
Documentation/coccinelle.txt | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/coccinelle.txt b/Documentation/coccinelle.txt
index 96b6903..cf44eb6 100644
--- a/Documentation/coccinelle.txt
+++ b/Documentation/coccinelle.txt
@@ -102,9 +102,15 @@ or
make coccicheck COCCI=<my_SP.cocci> MODE=report


- Using Coccinelle on (modified) files
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ Controlling Which Files are Processed by Coccinelle
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+By default the entire kernel source tree is checked.
+
+To apply Coccinelle to a specific directory, M= can be used.
+For example, to check drivers/net/wireless/ one may write:

+ make coccicheck M=drivers/net/wireless/
+
To apply Coccinelle on a file basis, instead of a directory basis, the
following command may be used:

--
1.7.2.5

2011-06-08 19:00:45

by Greg Dietsche

[permalink] [raw]
Subject: Re: [PATCH 1/2] coccicheck: add M= option to control which dir is processed



On 06/07/2011 10:29 PM, Greg Dietsche wrote:
> Examples:
> make coccicheck M=drivers/net/wireless/
> make coccicheck SUBDIRS=drivers/net/wireless/
>
> Signed-off-by: Greg Dietsche<[email protected]>
> ---
> scripts/coccicheck | 13 +++++++++++--
> 1 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/coccicheck b/scripts/coccicheck
> index 1bb1a1b..6f08efa 100755
> --- a/scripts/coccicheck
> +++ b/scripts/coccicheck
> @@ -10,13 +10,22 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
> # OPTIONS=$*
>
> # Workaround for Coccinelle< 0.2.3
> - FLAGS="-I $srctree/include -very_quiet"
> + if [ "$KBUILD_EXTMOD" = "" ] ; then
> + FLAGS="-I $srctree/include -very_quiet"
> + else
> + echo 'M= is only supported for Coccinelle>= 0.2.3'
> + exit 1
> + fi
> shift $(( $# - 1 ))
> OPTIONS=$1
> else
> ONLINE=0
> FLAGS="-very_quiet"
> - OPTIONS="-dir $srctree"
> + if [ "$KBUILD_EXTMOD" = "" ] ; then
> + OPTIONS="-dir $srctree"
> + else
> + OPTIONS="-dir $KBUILD_EXTMOD"
>
So far I've found one bug after reading Nicolas's comments on the other
thread. In order to have the diffs print file names correctly, I
definitely need to update my patch to do this:

+ OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree"

Also, do I need to tell cocci where the includes are? Based on my somewhat limited knowledge and testing, I'm not sure... but so far the tests seem to work without it. If we really do need to tell it about the includes, then the line should read:

+ OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include"



> + fi
> fi
>
> if [ ! -x "$SPATCH" ]; then
>

Greg

2011-06-08 19:10:05

by Nicolas Palix

[permalink] [raw]
Subject: Re: [PATCH 1/2] coccicheck: add M= option to control which dir is processed

Hi,

On Wed, Jun 8, 2011 at 9:00 PM, Greg Dietsche <[email protected]> wrote:
>
>
> On 06/07/2011 10:29 PM, Greg Dietsche wrote:
>>
>> Examples:
>>        make coccicheck M=drivers/net/wireless/
>>        make coccicheck SUBDIRS=drivers/net/wireless/
>>
>> Signed-off-by: Greg Dietsche<[email protected]>
>> ---
>>  scripts/coccicheck |   13 +++++++++++--
>>  1 files changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/coccicheck b/scripts/coccicheck
>> index 1bb1a1b..6f08efa 100755
>> --- a/scripts/coccicheck
>> +++ b/scripts/coccicheck
>> @@ -10,13 +10,22 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
>>  #    OPTIONS=$*
>>
>>  # Workaround for Coccinelle<  0.2.3
>> -    FLAGS="-I $srctree/include -very_quiet"
>> +    if [ "$KBUILD_EXTMOD" = "" ] ; then
>> +        FLAGS="-I $srctree/include -very_quiet"
>> +    else
>> +           echo 'M= is only supported for Coccinelle>= 0.2.3'
>> +           exit 1
>> +    fi
>>      shift $(( $# - 1 ))
>>      OPTIONS=$1
>>  else
>>      ONLINE=0
>>      FLAGS="-very_quiet"
>> -    OPTIONS="-dir $srctree"
>> +    if [ "$KBUILD_EXTMOD" = "" ] ; then
>> +        OPTIONS="-dir $srctree"
>> +    else
>> +        OPTIONS="-dir $KBUILD_EXTMOD"
>>
>
> So far I've found one bug after reading Nicolas's comments on the other
> thread. In order to have the diffs print file names correctly, I definitely
> need to update my patch to do this:
>
> +        OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree"
>
> Also, do I need to tell cocci where the includes are? Based on my somewhat
> limited knowledge and testing, I'm not sure... but so far the tests seem to
> work without it. If we really do need to tell it about the includes, then
> the line should read:
>
> +        OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include"

I am not familiar with out-of-tree development but I guess that in
that case we should
also add a "-I $KBUILD_EXTMOD/include" ?

The use of -I by Coccinelle depends on the other options (like
-include_headers or -all_includes).
Such options are retrieved from the comments in the cocci files.
So the need for -I depends on the semantic patch you consider. I think
it is thus better
to be "exhaustive" in that case.

Julia, is there any performance problem in doing so ?


>
>
>
>> +    fi
>>  fi
>>
>>  if [ ! -x "$SPATCH" ]; then
>>
>
> Greg
>
>



--
Nicolas Palix
http://sardes.inrialpes.fr/~npalix/

2011-06-11 15:29:51

by Greg Dietsche

[permalink] [raw]
Subject: [PATCH 1/2 V2] coccicheck: add M= option to control which dir is processed

Examples:
make coccicheck M=drivers/net/wireless/
make coccicheck SUBDIRS=drivers/net/wireless/

Version 2:
fix patch file names when using M=
tell coccinelle where the include files are

Signed-off-by: Greg Dietsche <[email protected]>
---
scripts/coccicheck | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/coccicheck b/scripts/coccicheck
index 1bb1a1b..1ceecdf 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -10,13 +10,22 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
# OPTIONS=$*

# Workaround for Coccinelle < 0.2.3
- FLAGS="-I $srctree/include -very_quiet"
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
+ FLAGS="-I $srctree/include -very_quiet"
+ else
+ echo 'M= is only supported for Coccinelle >= 0.2.3'
+ exit 1
+ fi
shift $(( $# - 1 ))
OPTIONS=$1
else
ONLINE=0
FLAGS="-very_quiet"
- OPTIONS="-dir $srctree"
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
+ OPTIONS="-dir $srctree"
+ else
+ OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include"
+ fi
fi

if [ ! -x "$SPATCH" ]; then
--
1.7.2.5

2011-06-11 15:33:14

by Greg Dietsche

[permalink] [raw]
Subject: Re: [PATCH 1/2] coccicheck: add M= option to control which dir is processed

On 06/08/2011 02:10 PM, Nicolas Palix wrote:
> I am not familiar with out-of-tree development but I guess that in
> that case we should
> also add a "-I $KBUILD_EXTMOD/include" ?
>
>
I decided to skip doing this in V2 of the patch. I did a very quick test
and cocci didn't seem to like two -I flags on one command line.
> The use of -I by Coccinelle depends on the other options (like
> -include_headers or -all_includes).
> Such options are retrieved from the comments in the cocci files.
> So the need for -I depends on the semantic patch you consider. I think
> it is thus better
> to be "exhaustive" in that case.
>
> Julia, is there any performance problem in doing so ?
>

Greg

2011-06-11 15:41:06

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 1/2] coccicheck: add M= option to control which dir is processed

On Sat, 11 Jun 2011, Greg Dietsche wrote:

> On 06/08/2011 02:10 PM, Nicolas Palix wrote:
> > I am not familiar with out-of-tree development but I guess that in
> > that case we should
> > also add a "-I $KBUILD_EXTMOD/include" ?
> >
> >
> I decided to skip doing this in V2 of the patch. I did a very quick test and
> cocci didn't seem to like two -I flags on one command line.

What was the problem and what version of coccinelle do you have? To my
recollection, the ability to have multiple -I options was added sometime
not so long ago.

julia

> > The use of -I by Coccinelle depends on the other options (like
> > -include_headers or -all_includes).
> > Such options are retrieved from the comments in the cocci files.
> > So the need for -I depends on the semantic patch you consider. I think
> > it is thus better
> > to be "exhaustive" in that case.
> >
> > Julia, is there any performance problem in doing so ?
> >
>
> Greg
>
>
>

2011-06-11 17:22:20

by Greg Dietsche

[permalink] [raw]
Subject: Re: [PATCH 1/2] coccicheck: add M= option to control which dir is processed



On 06/11/2011 10:40 AM, Julia Lawall wrote:
> On Sat, 11 Jun 2011, Greg Dietsche wrote:
>
>
>> On 06/08/2011 02:10 PM, Nicolas Palix wrote:
>>
>>> I am not familiar with out-of-tree development but I guess that in
>>> that case we should
>>> also add a "-I $KBUILD_EXTMOD/include" ?
>>>
>>>
>>>
>> I decided to skip doing this in V2 of the patch. I did a very quick test and
>> cocci didn't seem to like two -I flags on one command line.
>>
> What was the problem and what version of coccinelle do you have? To my
> recollection, the ability to have multiple -I options was added sometime
> not so long ago.
>
>
Hmm... my 'quick' test must have been bad. I just tested again with
0.2.3 (debian squeeze) and 1.0.0-rc3 and both seem to work just with
multiple -I options. As I recall, originally, the script just exited
with a code of 1 in my original test...

so the updated line really should read:
OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I
$KBUILD_EXTMOD/include"

I'll send an updated patch in a day or two. I've got some other stuff to
do today. Also, I noticed another bug that I'll need to fix too. The
lines in my patch that read:
echo 'M= is only supported for Coccinelle >= 0.2.3'
exit 1
are flat out wrong... :(

Greg

> julia
>
>
>>> The use of -I by Coccinelle depends on the other options (like
>>> -include_headers or -all_includes).
>>> Such options are retrieved from the comments in the cocci files.
>>> So the need for -I depends on the semantic patch you consider. I think
>>> it is thus better
>>> to be "exhaustive" in that case.
>>>
>>> Julia, is there any performance problem in doing so ?
>>>
>>>
>> Greg
>>

2011-06-11 17:53:14

by Greg Dietsche

[permalink] [raw]
Subject: [PATCH 1/2 v3] coccicheck: add M= option to control which dir is processed

Examples:
make coccicheck M=drivers/net/wireless/
make coccicheck SUBDIRS=drivers/net/wireless/

Version 2:
fix patch file names when using M=
tell coccinelle where the include files are

Version 3:
Add second include option to support out of tree development
Fix error message

Signed-off-by: Greg Dietsche <[email protected]>
---
scripts/coccicheck | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/scripts/coccicheck b/scripts/coccicheck
index 1bb1a1b..3c27764 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -9,14 +9,23 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
# FLAGS="-ignore_unknown_options -very_quiet"
# OPTIONS=$*

-# Workaround for Coccinelle < 0.2.3
- FLAGS="-I $srctree/include -very_quiet"
- shift $(( $# - 1 ))
- OPTIONS=$1
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
+ # Workaround for Coccinelle < 0.2.3
+ FLAGS="-I $srctree/include -very_quiet"
+ shift $(( $# - 1 ))
+ OPTIONS=$1
+ else
+ echo M= is not currently supported when C=1 or C=2
+ exit 1
+ fi
else
ONLINE=0
FLAGS="-very_quiet"
- OPTIONS="-dir $srctree"
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
+ OPTIONS="-dir $srctree"
+ else
+ OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I $KBUILD_EXTMOD/include"
+ fi
fi

if [ ! -x "$SPATCH" ]; then
--
1.7.2.5