Catalli's threaded switch
[sliver-openvswitch.git] / build-aux / check-vlog-modules
1 #! /bin/sh
2
3 if test "$1" = --help; then
4     cat <<EOF
5 $0: cross-check declared and defined vlog modules
6 usage: $0 [--help]
7
8 Must be run from the top-level source directory.
9
10 On systems that don't support user-defined section names, the 'vlog'
11 logging subsystem requires the list of modules in lib/vlog-modules.def
12 to match the set of vlog modules actually used by the source files.
13 However, most Open vSwitch development happens on systems that do
14 support user-defined section names and don't have this requirement.
15 This utility runs automatically at build time to check this
16 requirement "by hand", so that Open vSwitch developers don't
17 accidentally break the build for others.
18 EOF
19     exit 0
20 elif test "$#" != 0; then
21     echo "no arguments accepted (use --help for help)"
22     exit 1
23 elif test ! -e lib/vlog-modules.def; then
24     echo "must run from the top-level source directory (use --help for help)"
25     exit 1
26 fi
27
28 # We can only get a list of source files if this is a Git checkout.
29 if test -e .git && (git --version) >/dev/null 2>&1; then
30     :
31 else
32     exit 0
33 fi
34
35 # Get the list of modules declared in lib/vlog-modules.def.
36 vlog_modules=`
37     sed -n 's/^VLOG_MODULE(\([_a-zA-Z0-9]\{1,\}\)).*$/\1/p' \
38     lib/vlog-modules.def \
39     | LC_ALL=C sort -u | xargs echo`
40
41 # Get the list of modules defined in some source file.
42 src_modules=`
43     git grep -h -E '^[  ]*VLOG_DEFINE(_THIS)?_MODULE\([_a-zA-Z0-9]+\)[  ]*$' \
44     | sed 's/.*(\([_a-zA-Z0-9]\{1,\}\)).*/\1/' \
45     | LC_ALL=C sort -u \
46     | xargs echo`
47
48 rc=0
49
50 for module in $vlog_modules; do
51     case " $src_modules " in
52         *" $module "*) ;;
53         *) echo "vlog module $module is declared in lib/vlog-modules.def but not defined by any source file";
54             rc=1 ;;
55     esac
56 done
57
58 for module in $src_modules; do
59     case " $vlog_modules " in
60         *" $module "*) ;;
61         *) echo "vlog module $module is defined in a source file but not declared in lib/vlog-modules.def";
62             rc=1 ;;
63     esac
64 done
65
66 exit $rc