[v2] devtools: check wrong svg include in guides

Message ID 20181031162842.19431-1-thomas@monjalon.net (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] devtools: check wrong svg include in guides |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Thomas Monjalon Oct. 31, 2018, 4:28 p.m. UTC
  Including svg files with the svg extension is a common mistake:
	.. figure:: example.svg
must be
	.. figure:: example.*
So it will work also when building pdf doc with figures converted
to png files.

A check is added in checkpatches.sh.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: Arnon Warshavsky <arnon@qwilt.com>

PS: the warning contains the regex. May it be improved?

Warning in /doc/guides/nics/mvpp2.rst:
are you sure you want to add the following:
::[[:space:]]*[^[:space:]]*\.svg

Cc: Arnon Warshavsky <arnon@qwilt.com>
---
 devtools/checkpatches.sh | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
  

Comments

Arnon Warshavsky Nov. 1, 2018, 6:45 a.m. UTC | #1
Hi

>PS: the warning contains the regex. May it be improved?

How about passing an explicit warning message to the awk instead of the
regex?

+++ b/devtools/check-forbidden-tokens.awk
 END {
        if (count > 0) {
                print "Warning in " substr(last_file,6) ":"
-               print "are you sure you want to add the following:"
-               for (key in expressions) {
-                       if (expressions[key] > 0) {
-                               print key
-                       }
-               }
+               print MESSAGE
                exit RET_ON_FAIL
        }
 }

+++ b/devtools/checkpatches.sh
-check_forbidden_additions() {
+check_forbidden_additions() { # <patch>
+       local ret=0
        # refrain from new additions of rte_panic() and rte_exit()
        # multiple folders and expressions are separated by spaces
        awk -v FOLDERS="lib drivers" \
                -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
                -v RET_ON_FAIL=1 \
-               -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk -
+               -v MESSAGE='Usage of rte_panic/rte_exit' \
+               -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk \
+               "$1"
+       if [ $? -ne 0 ] ; then
+                ret=1
+       fi
+       # svg figures must be included with wildcard extension
+       # because of png conversion for pdf docs
+       awk -v FOLDERS='doc' \
+               -v EXPRESSIONS='::[[:space:]]*[^[:space:]]*\\.svg' \
+               -v RET_ON_FAIL=1 \
+               -v MESSAGE='Using explicit .svg extention in figures
instead of .*' \
+               -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk \
+               "$1"
+       if [ $? -ne 0 ] ; then
+                ret=1
+       fi
+
+       return $ret
 }


I also noticed that there is a need to keep the return value from each
check in case the first fails and the latter succeeds


thanks
/Arnon

On Wed, Oct 31, 2018 at 6:28 PM, Thomas Monjalon <thomas@monjalon.net>
wrote:

> Including svg files with the svg extension is a common mistake:
>         .. figure:: example.svg
> must be
>         .. figure:: example.*
> So it will work also when building pdf doc with figures converted
> to png files.
>
> A check is added in checkpatches.sh.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Signed-off-by: Arnon Warshavsky <arnon@qwilt.com>
>
> PS: the warning contains the regex. May it be improved?
>
> Warning in /doc/guides/nics/mvpp2.rst:
> are you sure you want to add the following:
> ::[[:space:]]*[^[:space:]]*\.svg
>
> Cc: Arnon Warshavsky <arnon@qwilt.com>
> ---
>  devtools/checkpatches.sh | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
> index bf3114f95..fb9e9f76d 100755
> --- a/devtools/checkpatches.sh
> +++ b/devtools/checkpatches.sh
> @@ -43,13 +43,21 @@ print_usage () {
>         END_OF_HELP
>  }
>
> -check_forbidden_additions() {
> +check_forbidden_additions() { # <patch>
>         # refrain from new additions of rte_panic() and rte_exit()
>         # multiple folders and expressions are separated by spaces
>         awk -v FOLDERS="lib drivers" \
>                 -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
>                 -v RET_ON_FAIL=1 \
> -               -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk
> -
> +               -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk
> \
> +               "$1"
> +       # svg figures must be included with wildcard extension
> +       # because of png conversion for pdf docs
> +       awk -v FOLDERS='doc' \
> +               -v EXPRESSIONS='::[[:space:]]*[^[:space:]]*\\.svg' \
> +               -v RET_ON_FAIL=1 \
> +               -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk
> \
> +               "$1"
>  }
>
>  number=0
> @@ -115,7 +123,7 @@ check () { # <patch> <commit> <title>
>         fi
>
>         ! $verbose || printf '\nChecking forbidden tokens additions:\n'
> -       report=$(check_forbidden_additions <"$tmpinput")
> +       report=$(check_forbidden_additions "$tmpinput")
>         if [ $? -ne 0 ] ; then
>                 $headline_printed || print_headline "$3"
>                 printf '%s\n' "$report"
> --
> 2.19.0
>
>
  
Thomas Monjalon Nov. 1, 2018, 9:27 a.m. UTC | #2
01/11/2018 07:45, Arnon Warshavsky:
> Hi
> 
> >PS: the warning contains the regex. May it be improved?
> 
> How about passing an explicit warning message to the awk instead of the
> regex?

Yes it is a good idea.
I think it can be a separate patch. Would you like to send it please?

[..]
> +       if [ $? -ne 0 ] ; then
> +                ret=1
> +       fi
> +
> +       return $ret
>  }
> 
> I also noticed that there is a need to keep the return value from each
> check in case the first fails and the latter succeeds

No need of return code.
The error is detected if there is something printed to stdout.
  
Arnon Warshavsky Nov. 1, 2018, 9:29 a.m. UTC | #3
>
>
> Yes it is a good idea.
> I think it can be a separate patch. Would you like to send it please?
>
> Sure. Will do
  
Arnon Warshavsky Nov. 1, 2018, 1:59 p.m. UTC | #4
>
>> Yes it is a good idea.
>> I think it can be a separate patch. Would you like to send it please?
>>
>> Sure. Will do
>
> Just to make sure - I am waiting for your patch to get in, so that I apply
the warning patch for both checks
  
Thomas Monjalon Nov. 1, 2018, 2:10 p.m. UTC | #5
01/11/2018 14:59, Arnon Warshavsky:
> >
> >> Yes it is a good idea.
> >> I think it can be a separate patch. Would you like to send it please?
> >>
> >> Sure. Will do
> >
> > Just to make sure - I am waiting for your patch to get in, so that I apply
> the warning patch for both checks

OK
  
Thomas Monjalon Nov. 1, 2018, 9:25 p.m. UTC | #6
31/10/2018 17:28, Thomas Monjalon:
> Including svg files with the svg extension is a common mistake:
> 	.. figure:: example.svg
> must be
> 	.. figure:: example.*
> So it will work also when building pdf doc with figures converted
> to png files.
> 
> A check is added in checkpatches.sh.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Signed-off-by: Arnon Warshavsky <arnon@qwilt.com>

Applied
  

Patch

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index bf3114f95..fb9e9f76d 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -43,13 +43,21 @@  print_usage () {
 	END_OF_HELP
 }
 
-check_forbidden_additions() {
+check_forbidden_additions() { # <patch>
 	# refrain from new additions of rte_panic() and rte_exit()
 	# multiple folders and expressions are separated by spaces
 	awk -v FOLDERS="lib drivers" \
 		-v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
 		-v RET_ON_FAIL=1 \
-		-f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk -
+		-f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk \
+		"$1"
+	# svg figures must be included with wildcard extension
+	# because of png conversion for pdf docs
+	awk -v FOLDERS='doc' \
+		-v EXPRESSIONS='::[[:space:]]*[^[:space:]]*\\.svg' \
+		-v RET_ON_FAIL=1 \
+		-f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk \
+		"$1"
 }
 
 number=0
@@ -115,7 +123,7 @@  check () { # <patch> <commit> <title>
 	fi
 
 	! $verbose || printf '\nChecking forbidden tokens additions:\n'
-	report=$(check_forbidden_additions <"$tmpinput")
+	report=$(check_forbidden_additions "$tmpinput")
 	if [ $? -ne 0 ] ; then
 		$headline_printed || print_headline "$3"
 		printf '%s\n' "$report"