scripts: Add a script to find unused documentation
authorsayli karnik <karniksayli1995@gmail.com>
Sat, 9 Sep 2017 16:56:18 +0000 (22:26 +0530)
committerJonathan Corbet <corbet@lwn.net>
Mon, 23 Oct 2017 14:01:37 +0000 (08:01 -0600)
Add a script that finds files with kernel-doc comments for imported functions
that are not included anywhere in documentation.

Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
scripts/find-unused-docs.sh [new file with mode: 0755]

diff --git a/scripts/find-unused-docs.sh b/scripts/find-unused-docs.sh
new file mode 100755 (executable)
index 0000000..3f46f89
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+# (c) 2017, Jonathan Corbet <corbet@lwn.net>
+#           sayli karnik <karniksayli1995@gmail.com>
+#
+# This script detects files with kernel-doc comments for exported functions
+# that are not included in documentation.
+#
+# usage: Run 'scripts/find-unused-docs.sh directory' from top level of kernel
+#       tree.
+#
+# example: $scripts/find-unused-docs.sh drivers/scsi
+#
+# Licensed under the terms of the GNU GPL License
+
+if ! [ -d "Documentation" ]; then
+       echo "Run from top level of kernel tree"
+       exit 1
+fi
+
+if [ "$#" -ne 1 ]; then
+       echo "Usage: scripts/find-unused-docs.sh directory"
+       exit 1
+fi
+
+if ! [ -d "$1" ]; then
+       echo "Directory $1 doesn't exist"
+       exit 1
+fi
+
+cd "$( dirname "${BASH_SOURCE[0]}" )"
+cd ..
+
+cd Documentation/
+
+echo "The following files contain kerneldoc comments for exported functions \
+that are not used in the formatted documentation"
+
+# FILES INCLUDED
+
+files_included=($(grep -rHR ".. kernel-doc" --include \*.rst | cut -d " " -f 3))
+
+declare -A FILES_INCLUDED
+
+for each in "${files_included[@]}"; do
+       FILES_INCLUDED[$each]="$each"
+       done
+
+cd ..
+
+# FILES NOT INCLUDED
+
+for file in `find $1 -name '*.c'`; do
+
+       if [[ ${FILES_INCLUDED[$file]+_} ]]; then
+       continue;
+       fi
+       str=$(scripts/kernel-doc -text -export "$file" 2>/dev/null)
+       if [[ -n "$str" ]]; then
+       echo "$file"
+       fi
+       done
+