raw/cnxk_bphy: support telemetry
[dpdk.git] / devtools / check-doc-vs-code.sh
1 #! /bin/sh -e
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2021 Mellanox Technologies, Ltd
4
5 # Check whether doc & code are in sync.
6 # Optional argument: check only what changed since a commit.
7 trusted_commit=$1 # example: origin/main
8
9 selfdir=$(dirname $(readlink -f $0))
10 rootdir=$(readlink -f $selfdir/..)
11
12 # speed up by ignoring Unicode details
13 export LC_COLLATE=C
14
15 result=0
16 error() # <message>
17 {
18         echo "$*"
19         result=$(($result + 1))
20 }
21
22 changed_files()
23 {
24         [ -n "$files" ] ||
25                 files=$(git diff-tree --name-only -r $trusted_commit..)
26         echo "$files"
27 }
28
29 has_code_change() # <pattern>
30 {
31         test -n "$(git log --format='%h' -S"$1" $trusted_commit..)"
32 }
33
34 has_file_change() # <pattern>
35 {
36         changed_files | grep -q "$1"
37 }
38
39 changed_net_drivers()
40 {
41         net_paths='drivers/net/|doc/guides/nics/features/'
42         [ -n "$drivers" ] ||
43                 drivers=$(changed_files |
44                         sed -rn "s,^($net_paths)([^./]*).*,\2,p" |
45                         sort -u)
46         echo "$drivers"
47 }
48
49 all_net_drivers()
50 {
51         find $rootdir/drivers/net -mindepth 1 -maxdepth 1 -type d |
52         sed 's,.*/,,' |
53         sort
54 }
55
56 check_rte_flow() # <driver>
57 {
58         code=$rootdir/drivers/net/$1
59         doc=$rootdir/doc/guides/nics/features/$1.ini
60         [ -d $code ] || return 0
61         [ -f $doc ] || return 0
62         report=$($selfdir/parse-flow-support.sh $code $doc)
63         if [ -n "$report" ]; then
64                 error "rte_flow doc out of sync for $1"
65                 echo "$report" | sed 's,^,\t,'
66         fi
67 }
68
69 if [ -z "$trusted_commit" ]; then
70         # check all
71         for driver in $(all_net_drivers); do
72                 check_rte_flow $driver
73         done
74         exit $result
75 fi
76
77 # find what changed and check
78 if has_code_change 'RTE_FLOW_.*_TYPE_' ||
79                 has_file_change 'doc/guides/nics/features'; then
80         for driver in $(changed_net_drivers); do
81                 check_rte_flow $driver
82         done
83 fi
84 exit $result