[Linux-Biella] Aiuto script output checkpatch.pl

Paolo Ciarrocchi paolo.ciarrocchi a gmail.com
Dom 13 Gen 2008 22:12:32 CET


2008/1/13 Paolo Ciarrocchi <paolo.ciarrocchi a gmail.com>:
> Ciao a tutti,
> da qualche tempo nei sorgenti del kernel si trova:
> ./script/checkpatch.pl
> Uno script per verificare violazione del codind style di patch e file.
>
> Ho fatto una piccola modifica:
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 579f50f..5083a3e 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1580,6 +1580,7 @@ sub process {
>
>         print report_dump();
>         if ($summary) {
> +               print "filename: $filename \n";
>                 print "total: $cnt_error errors, $cnt_warn warnings, " .
>                         (($check)? "$cnt_chk checks, " : "") .
>                         "$cnt_lines lines checked\n";
>
> al fine di cercare di usarlo anche a fine statistico, ora ottengo quanto segue:
> paolo a paolo-desktop:~/linux-2.6/arch/x86$ find . -name *.c |xargs
> ../../scripts/checkpatch.pl --file |grep -B 1 total
> filename: ./mach-rdc321x/gpio.c
> total: 0 errors, 0 warnings, 91 lines checked
> --
> filename: ./mach-rdc321x/platform.c
> total: 0 errors, 0 warnings, 68 lines checked
> --
> filename: ./mach-rdc321x/wdt.c
> total: 0 errors, 3 warnings, 275 lines checked
> --
> filename: ./boot/a20.c
> total: 0 errors, 0 warnings, 161 lines checked
> --
> filename: ./boot/apm.c
> total: 0 errors, 0 warnings, 95 lines checked
> --
> filename: ./boot/cmdline.c
> total: 0 errors, 0 warnings, 97 lines checked
>
> Ora mi piacerebbe fare:
> - Visualizzare il totale (somma di tutti ) errors, warning e lines

Paolo,
puoi fare cosi:
 find . -name '*.c' |xargs ../../scripts/checkpatch.pl --file |grep -B
1 ^total | awk '/^total/{ errors+=$2; warnings+=$4; lines+=$6; } {
print } END  {print ""; print "--- Report ---";print "number of files
"(NR+1)/3; print "number of errors: "errors; print "number of
warnings: "warnings; print "number of lines: "lines; print "% errors:
"errors/lines*100;print "% warning: "warnings/lines*100;}'

E ottenere qualcosa come:

...
...
...
--
./xen/mmu.c
total: 0 errors, 0 warnings, 644 lines checked
--
./xen/multicalls.c
total: 2 errors, 2 warnings, 138 lines checked
--
./xen/setup.c
total: 0 errors, 7 warnings, 110 lines checked
--
./xen/smp.c
total: 1 errors, 1 warnings, 421 lines checked
--
./xen/time.c
total: 3 errors, 3 warnings, 599 lines checked

--- Report ---
number of files 314
number of errors: 3498
number of warnings: 2421
number of lines: 115226
% errors: 3.03577
% warning: 2.10109

> - Visualizzare i 10 file che hanno piu' errori (o ordinare tutto per errors)

Questo non riesco ancora a farlo.

Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/


Maggiori informazioni sulla lista Linux