File: check_unused_headers

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (90 lines) | stat: -rwxr-xr-x 2,478 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#
# Name:      check_unused_headers
# Purpose:   checks all wxWidgets headers looking for headers not referenced anywhere
# Usage:     run with --verbose for verbose output
# Copyright: (c) 2007 Francesco Montorsi
# Licence:   wxWindows licence
################################################################################



if [[ "$1" = "-v" || "$1" = "--verbose" ]]; then
    verbose=yes
else
    verbose=no
fi


me=$(basename $0)
path=${0%%/$me}        # path from which the script has been launched
current=$(pwd)

# the path where this script resides:
scriptPath=$current/$path

# other interesting wx paths
headerPath="$scriptPath/../../include"
srcPath="$scriptPath/../../src"

# get list of wx source and header filenames
# NOTE: these list won't contain the .svn backup copies of the real sources/headers
# NOTE2: we keep the size of these lists small avoiding to include the prefixes 
#        like e.g. ../../include so to not incurr in OS limits when passing
#        them as arguments of commands
cd $headerPath
headerList=`find wx -name "*.h"`
cd $srcPath
srcList=`find . -name "*.cpp"`


unusedHeaders=0

function checkIfHeaderIsUsed
{
    local headerToCheck="$1"
    local found=no

    if [[ $verbose = yes ]]; then
        echo -n "checking if header: $headerToCheck is used... "
    fi

    # find the first occurrence of this header in wx sources and headers:
    cd $headerPath
    grep -m 1 "$headerToCheck" $headerList >/dev/null 2>&1
    if [[ $? = 0 ]]; then found=yes; fi

    cd $srcPath
    grep -m 1 "$headerToCheck" $srcList >/dev/null 2>&1
    if [[ $? = 0 ]]; then found=yes; fi

    if [[ $found = no ]]; then

        if [[ $verbose = yes ]]; then
            echo "no, it's not!"
        fi

        # this header is not used anywhere...
        echo "WARNING: unused header $headerToCheck"
        ((( unusedHeaders++ )))
    else
        if [[ $verbose = yes ]]; then
            echo "yes, it is"
        fi
    fi
}

echo " This script will look for unused wxWidgets headers"
echo " Note that some headers maybe not referenced by wxWidgets sources/headers but still"
echo " be useful for user applications; others instead are simply old and forgotten."
echo

for header in $headerList; do
    checkIfHeaderIsUsed $header
done

if [[ $unusedHeaders -gt 0 ]]; then
    echo " => WARNING: found $unusedHeaders unused headers!"
else
    echo " => All headers are referenced in either wxWidgets sources or in other headers"
fi