Component Tests
[profile/ivi/smartdevicelink.git] / Lint
1 #!/usr/bin/env bash
2
3 set -e
4
5 function print_usage {
6         echo
7         echo "Usage: Lint [FILE=file|ALL] BUILD_PATH=path [-v] [w0|w1|w2|w3|w4] [MISRA=ON|MISRA=OFF]"
8         echo 
9         echo "\"FILE=file|ALL\" Sets the scope of linting"
10         echo -e '\t' "FILE sets the scope to single \"file\""
11         echo -e '\t' "ALL sets the scope to all project modules"
12         echo -e '\t' "If none is set then localy changes files will be linted"
13         echo 
14         echo "\"BUILD_PATH=path\" is the only mandatory parameter which sets"
15         echo -e '\t' "the path to the build product directory"  
16         echo
17         echo "\"-v\" Turns verbose mode on (off by default)"
18         echo
19         echo "\"w0|w1|w2|w3|w4\" sets the Warning level"
20         echo -e '\t' "w0 - No messages (except for fatal errors)"
21         echo -e '\t' "w1 - Error messages only -- no Warnings or"
22         echo -e '\t' "Informationals."
23         echo -e '\t' "w2 - Error and Warning messages only"
24         echo -e '\t' "w3 - Error, Warning and Informational messages (this"
25         echo -e '\t' "is the default)"
26         echo -e '\t' "w4 - All messages."
27         echo
28         echo "\"MISRA=ON|MISRA=OFF\" Turns custom MISRA configuration ON"
29         echo -e '\t' "and OFF respectively (OFF by defaul)"
30         echo
31         echo
32 }
33
34
35 echo
36 echo "=========== Lint SMART DEVICE LINK project ==========="
37 echo
38  
39 ########################################################################
40 ##### Process input arguments ##########################################
41 ########################################################################
42
43 MISRA_ENABLED=false
44 WARNING_LEVEL=w3
45 SCOPE=LOCAL_CHANGES
46 BUILD_PATH=""
47 VERBOSE=false
48
49 if [ $# == 0 ] || [ ${1} == '-h' ] || [ ${1} == '--help' ]; then
50         print_usage
51         exit 0
52 fi
53
54 while test $# -gt 0; do
55         case "$1" in
56         MISRA=ON)
57                         MISRA_ENABLED=true
58                         shift
59                         ;;      
60                 MISRA=OFF)
61                         MISRA_ENABLED=false
62                         shift
63                         ;;
64                 w0|w1|w2|w3|w4)
65                         WARNING_LEVEL=$1
66                         shift
67                         ;;      
68                 ALL)
69                         if [ "$SCOPE" != "LOCAL_CHANGES" ]; then
70                                 echo "Wrong input. It is not allowed to use FILE and ALL at the same time"
71                                 print_usage
72                                 exit 1;
73                         fi
74                         SCOPE=ALL
75                         shift
76                         ;;      
77                 -v|--verbose)
78                         VERBOSE=true
79                         shift
80                         ;;
81                 *)
82                         LHS=$(echo $1 | awk 'BEGIN { FS = "=" } ; { print $1 }')
83                         RHS=$(echo $1 | awk 'BEGIN { FS = "=" } ; { print $2 }')
84                         
85                         if [ ${LHS} == 'FILE' ]; then
86                                 if [ "$SCOPE" != "LOCAL_CHANGES" ]; then
87                                         echo "Wrong input. It is not allowed to use FILE and ALL at the same time"
88                                         print_usage
89                                         exit 1;
90                                 fi
91                                 
92                                 if [ "${RHS}" == "" ]; then
93                                         echo "Wrong input. Provide valid FILE value"
94                                         print_usage
95                                         exit 1;
96                                 fi
97                                 SCOPE=$LHS
98                                 FILE_PATH=$RHS
99                         elif [ ${LHS} == 'BUILD_PATH' ]; then
100                                 if [ "${RHS}" == "" ]; then
101                                         echo "Wrong input. Provide valid BUILD_PATH value"
102                                         print_usage
103                                         exit 1;
104                                 fi
105                                 BUILD_PATH=$RHS
106                         else 
107                                 echo "Wrong input"
108                                 print_usage
109                                 exit 1;
110                         fi
111                         shift
112                         ;;
113         esac
114 done
115
116 if [ "${BUILD_PATH}" == "" ]; then
117         echo "Mandatory parameter BUILD_PATH is missing"
118         print_usage
119         exit 1;
120 fi
121
122
123 if [ "$SCOPE" == "LOCAL_CHANGES" ]; then
124         echo -e '\t' "Lining scope is limitted to localy changed files"
125 elif [ "$SCOPE" == "FILE" ]; then
126         echo -e '\t' "Lining scope is limitted to file " $FILE_PATH
127 elif [ "$SCOPE" == "ALL" ]; then
128         
129 #       echo "You a going to Lint the whole project. It takes a lot of time."
130 #       echo -n "Are you sure? [Y/n] "
131
132 #       read item
133 #       case "$item" in
134 #               y|Y)
135 #                       ;;
136 #               n|N)
137 #                       exit 0
138 #                       ;;
139 #               *) 
140 #                       exit 0
141 #                       ;;
142 #       esac
143
144         echo -e '\t' "Lining scope is set to all project files"
145 fi
146
147 if $MISRA_ENABLED; then
148         echo -e '\t' "MISRA is enabled"
149 else
150         echo -e '\t' "MISRA is disabled"
151 fi
152
153 case "$WARNING_LEVEL" in
154         w0) 
155                 echo -e '\t' "Warning is set to " $WARNING_LEVEL " --- No messages (except for fatal errors)"
156                 ;;
157         w1)  
158                 echo -e '\t' "Warning is set to " $WARNING_LEVEL " --- Error messages only -- no Warnings or Informationals."
159                 ;;
160         w2)  
161                 echo -e '\t' "Warning is set to " $WARNING_LEVEL " --- Error and Warning messages only"
162                 ;;
163         w3) 
164                 echo -e '\t' "Warning is set to " $WARNING_LEVEL " --- Error, Warning and Informational messages (this is the default)"
165                 ;;
166         w4) 
167                 echo -e '\t' "Warning is set to " $WARNING_LEVEL " --- All messages."
168                 ;;
169 esac
170
171 if $VERBOSE; then 
172         echo -e '\t' "Verbose mode is on"
173 fi
174
175 ########################################################################
176 ##### Configuring ######################################################
177 ########################################################################
178
179 # +e900 Turns on Successful completion, 'Integer' messages produced, which is not by defaulf available in level w0-w3
180 # -e830 Turns off Info 831: Reference cited in prior message
181 # -e830 Turns off Info 830: Location cited in prior message
182 SUPPRESS="-e830 -e831 +e900"
183
184 OTHER_PARAMS="-dOS_POSIX"
185 MISRA_CONFIGURATION=""
186 SOURCE_CODE_PATH="./src/components/ ./src/appMain/"
187 EXLUDE_FROM_SOURCE_CODE_PATH="./src/components/qt_hmi/ ./src/components/dbus/ ./src/components/transport_manager/src/usb/qnx"
188
189 echo
190 echo Configuring ...
191 echo =====================================
192 echo
193
194 rm -Rf ./tools/FlexeLint/tmp
195 rm -Rf ./tools/FlexeLint/results
196 mkdir ./tools/FlexeLint/tmp
197 mkdir ./tools/FlexeLint/results
198
199 if $MISRA_ENABLED; then
200         MISRA_CONFIGURATION="au-misra-cpp.lnt"
201 fi
202
203 if [ "$SCOPE" == "ALL" ]; then
204   EXLUDE_FROM_SOURCE_CODE_PATH=$(echo $EXLUDE_FROM_SOURCE_CODE_PATH | awk '{gsub(/ /,"\\|")}; 1')
205   find $SOURCE_CODE_PATH \( -name "*.cc" -o -name "*.cpp" \) | awk '{print "../../../" $0}' | grep -v "./src/components/qt_hmi/" | grep -v $EXLUDE_FROM_SOURCE_CODE_PATH > ./tools/FlexeLint/tmp/sdl-modules.lnt
206 elif [ "$SCOPE" == "FILE" ]; then
207   echo "$FILE_PATH" | awk '{print "../../../" $0}' > ./tools/FlexeLint/tmp/sdl-modules.lnt
208 elif [ "$SCOPE" == "LOCAL_CHANGES" ]; then
209   (git diff --name-only HEAD ; git ls-files --other --exclude-standard) | grep '.cc\|.cpp' | grep 'src/components\|src/appMain' | awk '{print "../../../" $0}' > ./tools/FlexeLint/tmp/sdl-modules.lnt
210 fi # if [ $CHECKSCOPE == "ALL" ]
211
212 (cd tools/FlexeLint/config && make -f co-gcc.mak > /dev/null)
213
214 find ./src/ -type d -name "*include*" | awk '{print "--i../../." $0}'  > ./tools/FlexeLint/tmp/sdl-include-path.lnt
215
216 echo "--i\"/usr/include/gstreamer-1.0\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
217 echo "--i\"/usr/include/glib-2.0\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
218 echo "--i\"/usr/lib/i386-linux-gnu/glib-2.0/include\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
219 echo "--i\"/usr/lib/x86_64-linux-gnu/glib-2.0/include\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
220 echo "--i\"/usr/include/dbus-1.0\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
221 echo "--i\"/usr/include/dbus-1.0\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
222 echo "--i\"/usr/lib/i386-linux-gnu/dbus-1.0/include\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
223 echo "--i\"/usr/lib/x86_64-linux-gnu/dbus-1.0/include\"" >> ./tools/FlexeLint/config/gcc-include-path.lnt
224
225 ########################################################################
226 ##### Linting ##########################################################
227 ########################################################################
228 FLINT_BINARY="Flint"
229
230 echo
231 echo Linting ...
232 echo =====================================
233 echo
234
235 cd ./tools/FlexeLint/bin
236
237 if $VERBOSE; then 
238         ./${FLINT_BINARY} -$WARNING_LEVEL $SUPPRESS -zero -u --i../../../$BUILD_PATH/src/components/ $OTHER_PARAMS $WORDSIZE ../config/smartdevicelink.lnt | tee ../results/raw_flexelint_report.txt
239 else
240         ./${FLINT_BINARY} -$WARNING_LEVEL $SUPPRESS -zero -u --i../../../$BUILD_PATH/src/components/ -os ../results/raw_flexelint_report.txt $OTHER_PARAMS $WORDSIZE ../config/smartdevicelink.lnt
241 fi
242
243
244 ########################################################################
245 ##### Preparing detailed report ########################################
246 ########################################################################
247 if [ "$SCOPE" != "LOCAL_CHANGES" ]; then
248
249         mkdir ../results/developers
250
251         echo
252         echo Preparing detailed report. Be patient
253         echo =====================================
254         echo
255
256         ./make_detailed_report
257 else
258         echo
259         echo "Detailed report for each developer won't be generated since"
260         echo "only local changes are present in report"
261         echo =====================================
262         echo
263 fi
264
265 ########################################################################
266 ##### Cleaning-up ######################################################
267 ########################################################################
268
269 function clean-up {
270         echo
271         echo Cleaning-up ...
272         echo =====================================
273         echo
274
275         rm -R ../tmp
276         cd ../config
277         make -f co-gcc.mak clean > /dev/null
278         
279 }
280
281 clean-up
282
283
284
285
286
287
288
289