Skip to contentSkip to conversation

coccicheck: improve pattern for getting relative path

PATCH In review Cihangir Akturk 3 participants 4 messages Aug 10, 2017 – Sep 23, 2017 Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coccicheck: improve pattern for getting relative path

When invoked with V=1, coccicheck script prints the information about which semantic patch (*.cocci file) used for this operation. Actually, it prints out the relative path of the related semantic patch. The script uses sed to remove the source tree part from cocci file path like so:

FILE=echo $COCCI | sed "s|$srctree/||"

This pattern works well most of the time. But in cases where $COCCI doesn't start with "./" characters, it doesn't remove the right part.

Consider the following scenario:

$ make coccicheck COCCI=scripts/coccinelle/api/drm-get-put.cocci \
                        MODE=patch M=drivers/staging V=1

where

COCCI=scripts/coccinelle/api/drm-get-put.cocci and srctree=.

In this case, out pattern matches the first "s/", and we end up assigning "scriptcoccinelle/api/drm-get-put.cocci" to $FILE.

Fix this by adding a caret ^ at the beginning of regex pattern, so that it matches only start of the path.

---
 scripts/coccicheck | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccicheck +1 -1
index ec487b8..8de4245 100755
@@ -193,7 +193,7 @@ coccinelle () {
 
     if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
 
-	FILE=`echo $COCCI | sed "s|$srctree/||"`
+	FILE=`echo $COCCI | sed "s|^$srctree/||"`
 
 	echo "Processing `basename $COCCI`"
 	echo "with option(s) \"$OPT\""
Signature · 1 line
2.7.4
#1 lore raw
Quoted 18 lines · Cihangir Akturk

When invoked with V=1, coccicheck script prints the information about which semantic patch (*.cocci file) used for this operation. Actually, it prints out the relative path of the related semantic patch. The script uses sed to remove the source tree part from cocci file path like so:

FILE=echo $COCCI | sed "s|$srctree/||"

This pattern works well most of the time. But in cases where $COCCI doesn't start with "./" characters, it doesn't remove the right part.

Consider the following scenario:

$ make coccicheck COCCI=scripts/coccinelle/api/drm-get-put.cocci \
                        MODE=patch M=drivers/staging V=1

where

Quoted 7 lines

COCCI=scripts/coccinelle/api/drm-get-put.cocci and srctree=.

In this case, out pattern matches the first "s/", and we end up assigning "scriptcoccinelle/api/drm-get-put.cocci" to $FILE.

Fix this by adding a caret ^ at the beginning of regex pattern, so that it matches only start of the path.

Nicolas, is this ok?

julia

Quoted 23 lines
---
 scripts/coccicheck | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccicheck +1 -2
index ec487b8..8de4245 100755
@@ -193,7 +193,7 @@ coccinelle () {
 
     if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
 
-	FILE=`echo $COCCI | sed "s|$srctree/||"`
+	FILE=`echo $COCCI | sed "s|^$srctree/||"`
 
 	echo "Processing `basename $COCCI`"
 	echo "with option(s) \"$OPT\""
--

2.7.4

#2 lore raw
Quoted 24 lines · Julia Lawall
Quoted 20 lines · Cihangir Akturk

When invoked with V=1, coccicheck script prints the information about which semantic patch (*.cocci file) used for this operation. Actually, it prints out the relative path of the related semantic patch. The script uses sed to remove the source tree part from cocci file path like so:

FILE=echo $COCCI | sed "s|$srctree/||"

This pattern works well most of the time. But in cases where $COCCI doesn't start with "./" characters, it doesn't remove the right part.

Consider the following scenario:

$ make coccicheck COCCI=scripts/coccinelle/api/drm-get-put.cocci \
                        MODE=patch M=drivers/staging V=1

where

COCCI=scripts/coccinelle/api/drm-get-put.cocci and srctree=.

Quoted 7 lines
Quoted 5 lines

In this case, out pattern matches the first "s/", and we end up assigning "scriptcoccinelle/api/drm-get-put.cocci" to $FILE.

Fix this by adding a caret ^ at the beginning of regex pattern, so that it matches only start of the path.

Nicolas, is this ok?

Any comments on this patch? No one has commented yet. But I still get the same results on current linux-next.

Quoted 26 lines

julia

Quoted 23 lines
---
 scripts/coccicheck | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccicheck +1 -2
index ec487b8..8de4245 100755
@@ -193,7 +193,7 @@ coccinelle () {
 
     if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
 
-	FILE=`echo $COCCI | sed "s|$srctree/||"`
+	FILE=`echo $COCCI | sed "s|^$srctree/||"`
 
 	echo "Processing `basename $COCCI`"
 	echo "with option(s) \"$OPT\""
--

2.7.4

maintainer Acked-by [email protected] on v1 1/1
#3 lore raw
In reply to Cihangir Akturk

Le 10/08/17 ? 19:40, Cihangir Akturk a ?crit?:

Quoted 20 lines

When invoked with V=1, coccicheck script prints the information about which semantic patch (*.cocci file) used for this operation. Actually, it prints out the relative path of the related semantic patch. The script uses sed to remove the source tree part from cocci file path like so:

FILE=echo $COCCI | sed "s|$srctree/||"

This pattern works well most of the time. But in cases where $COCCI doesn't start with "./" characters, it doesn't remove the right part.

Consider the following scenario:

$ make coccicheck COCCI=scripts/coccinelle/api/drm-get-put.cocci \
                         MODE=patch M=drivers/staging V=1

where

COCCI=scripts/coccinelle/api/drm-get-put.cocci and srctree=.

Quoted 7 lines

In this case, out pattern matches the first "s/", and we end up assigning "scriptcoccinelle/api/drm-get-put.cocci" to $FILE.

Fix this by adding a caret ^ at the beginning of regex pattern, so that it matches only start of the path.

Acked-by nicolas.palix at univ-grenoble-alpes.fr
Quoted 17 lines

--- > scripts/coccicheck | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccicheck +1 -1
index ec487b8..8de4245 100755
@@ -193,7 +193,7 @@ coccinelle () {
 
      if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
 
-	FILE=`echo $COCCI | sed "s|$srctree/||"`
+	FILE=`echo $COCCI | sed "s|^$srctree/||"`
 
  	echo "Processing `basename $COCCI`"
  	echo "with option(s) \"$OPT\""
Signature · 10 lines
Nicolas Palix
http://lig-membres.imag.fr/palix/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2959 bytes
Desc: Signature cryptographique S/MIME
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20170923/0c55ba04/attachment.p7s>