|
| 1 | +#!/bin/sh |
| 2 | +#$Id$ |
| 3 | +#Copyright (c) 2014-2025 Pierre Pronchery <[email protected]> |
| 4 | +# |
| 5 | +#Redistribution and use in source and binary forms, with or without |
| 6 | +#modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# * Redistributions of source code must retain the above copyright notice, this |
| 9 | +# list of conditions and the following disclaimer. |
| 10 | +# * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer in the documentation |
| 12 | +# and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | +#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | +#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | +#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 18 | +#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | +#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 20 | +#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 21 | +#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 22 | +#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +#variables |
| 28 | +CONFIGSH="${0%/pclint.sh}/../config.sh" |
| 29 | +PROGNAME="pclint.sh" |
| 30 | +PROJECTCONF="../project.conf" |
| 31 | +#executables |
| 32 | +DATE="date" |
| 33 | +DEBUG="_debug" |
| 34 | +ECHO="/bin/echo" |
| 35 | +FIND="find" |
| 36 | +MKDIR="mkdir -p" |
| 37 | +PCLINT="pkgconf --validate" |
| 38 | +SORT="sort -n" |
| 39 | +TR="tr" |
| 40 | + |
| 41 | +[ -f "$CONFIGSH" ] && . "$CONFIGSH" |
| 42 | + |
| 43 | + |
| 44 | +#functions |
| 45 | +#pclint |
| 46 | +_pclint() |
| 47 | +{ |
| 48 | + res=0 |
| 49 | + subdirs= |
| 50 | + |
| 51 | + $DATE |
| 52 | + while read line; do |
| 53 | + case "$line" in |
| 54 | + "["*) |
| 55 | + break |
| 56 | + ;; |
| 57 | + "subdirs="*) |
| 58 | + subdirs=${line#subdirs=} |
| 59 | + subdirs=$(echo "$subdirs" | $TR ',' ' ') |
| 60 | + ;; |
| 61 | + esac |
| 62 | + done < "$PROJECTCONF" |
| 63 | + if [ ! -n "$subdirs" ]; then |
| 64 | + _error "Could not locate directories to analyze" |
| 65 | + return $? |
| 66 | + fi |
| 67 | + for subdir in $subdirs; do |
| 68 | + [ -d "../$subdir" ] || continue |
| 69 | + while read filename; do |
| 70 | + [ -n "$filename" ] || continue |
| 71 | + echo |
| 72 | + $ECHO -n "$filename:" |
| 73 | + _pclint_file "$filename" |
| 74 | + if [ $? -eq 0 ]; then |
| 75 | + echo " OK" |
| 76 | + echo "$PROGNAME: $filename: OK" 1>&2 |
| 77 | + else |
| 78 | + echo "FAIL" |
| 79 | + echo "$PROGNAME: $filename: FAIL" 1>&2 |
| 80 | + res=2 |
| 81 | + fi |
| 82 | + done << EOF |
| 83 | +$($FIND "../$subdir" -type f -a -iname '*.pc' | $SORT) |
| 84 | +EOF |
| 85 | + done |
| 86 | + return $res |
| 87 | +} |
| 88 | + |
| 89 | +_pclint_file() |
| 90 | +{ |
| 91 | + $DEBUG $PCLINT "$filename" 2>&1 || return 2 |
| 92 | + #try to detect invalid use of return |
| 93 | + #XXX this test is not accurate (therefore a warning) |
| 94 | + warn=0 |
| 95 | + while read line; do |
| 96 | + case "$line" in |
| 97 | + *return*) |
| 98 | + warn=1 |
| 99 | + ;; |
| 100 | + *) |
| 101 | + warn=0 |
| 102 | + ;; |
| 103 | + esac |
| 104 | + done < "$filename" |
| 105 | + if [ $warn -ne 0 ]; then |
| 106 | + _error "$filename: return instead of exit in the global scope" |
| 107 | + fi |
| 108 | + return 0 |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +#debug |
| 113 | +_debug() |
| 114 | +{ |
| 115 | + echo "$@" 1>&3 |
| 116 | + "$@" |
| 117 | +} |
| 118 | + |
| 119 | + |
| 120 | +#error |
| 121 | +_error() |
| 122 | +{ |
| 123 | + echo "$PROGNAME: $@" 1>&2 |
| 124 | + return 2 |
| 125 | +} |
| 126 | + |
| 127 | + |
| 128 | +#usage |
| 129 | +_usage() |
| 130 | +{ |
| 131 | + echo "Usage: $PROGNAME [-c] target..." 1>&2 |
| 132 | + return 1 |
| 133 | +} |
| 134 | + |
| 135 | + |
| 136 | +#main |
| 137 | +clean=0 |
| 138 | +while getopts "cO:P:" name; do |
| 139 | + case "$name" in |
| 140 | + c) |
| 141 | + clean=1 |
| 142 | + ;; |
| 143 | + O) |
| 144 | + export "${OPTARG%%=*}"="${OPTARG#*=}" |
| 145 | + ;; |
| 146 | + P) |
| 147 | + #XXX ignored for compatibility |
| 148 | + ;; |
| 149 | + ?) |
| 150 | + _usage |
| 151 | + exit $? |
| 152 | + ;; |
| 153 | + esac |
| 154 | +done |
| 155 | +shift $((OPTIND - 1)) |
| 156 | +if [ $# -lt 1 ]; then |
| 157 | + _usage |
| 158 | + exit $? |
| 159 | +fi |
| 160 | + |
| 161 | +#clean |
| 162 | +[ $clean -ne 0 ] && exit 0 |
| 163 | + |
| 164 | +exec 3>&1 |
| 165 | +ret=0 |
| 166 | +while [ $# -gt 0 ]; do |
| 167 | + target="$1" |
| 168 | + dirname="${target%/*}" |
| 169 | + shift |
| 170 | + |
| 171 | + if [ -n "$dirname" -a "$dirname" != "$target" ]; then |
| 172 | + $MKDIR -- "$dirname" || ret=$? |
| 173 | + fi |
| 174 | + _pclint > "$target" || ret=$? |
| 175 | +done |
| 176 | +exit $ret |
0 commit comments