45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 1) #!/bin/bash
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 2) # (c) 2017, Jonathan Corbet <corbet@lwn.net>
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 3) # sayli karnik <karniksayli1995@gmail.com>
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 4) #
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 5) # This script detects files with kernel-doc comments for exported functions
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 6) # that are not included in documentation.
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 7) #
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 8) # usage: Run 'scripts/find-unused-docs.sh directory' from top level of kernel
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 9) # tree.
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 10) #
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 11) # example: $scripts/find-unused-docs.sh drivers/scsi
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 12) #
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 13) # Licensed under the terms of the GNU GPL License
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 14)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 15) if ! [ -d "Documentation" ]; then
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 16) echo "Run from top level of kernel tree"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 17) exit 1
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 18) fi
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 19)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 20) if [ "$#" -ne 1 ]; then
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 21) echo "Usage: scripts/find-unused-docs.sh directory"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 22) exit 1
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 23) fi
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 24)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 25) if ! [ -d "$1" ]; then
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 26) echo "Directory $1 doesn't exist"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 27) exit 1
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 28) fi
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 29)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 30) cd "$( dirname "${BASH_SOURCE[0]}" )"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 31) cd ..
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 32)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 33) cd Documentation/
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 34)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 35) echo "The following files contain kerneldoc comments for exported functions \
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 36) that are not used in the formatted documentation"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 37)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 38) # FILES INCLUDED
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 39)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 40) files_included=($(grep -rHR ".. kernel-doc" --include \*.rst | cut -d " " -f 3))
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 41)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 42) declare -A FILES_INCLUDED
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 43)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 44) for each in "${files_included[@]}"; do
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 45) FILES_INCLUDED[$each]="$each"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 46) done
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 47)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 48) cd ..
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 49)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 50) # FILES NOT INCLUDED
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 51)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 52) for file in `find $1 -name '*.c'`; do
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 53)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 54) if [[ ${FILES_INCLUDED[$file]+_} ]]; then
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 55) continue;
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 56) fi
1630146db2111 (Geert Uytterhoeven 2020-01-27 10:31:07 +0100 57) str=$(scripts/kernel-doc -export "$file" 2>/dev/null)
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 58) if [[ -n "$str" ]]; then
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 59) echo "$file"
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 60) fi
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 61) done
45653c845b0c6 (sayli karnik 2017-09-09 22:26:18 +0530 62)