11#! /bin/bash
22#
33# maintainer script
4+ # essential for travis builder
45#
56
67# path to this script file
@@ -9,7 +10,10 @@ SCRIPT_DIR_RELATIVE=$0
910
1011# global vars
1112FORCE_CONTINUE=0
12- FULL_REPORT=0
13+ FULL_REPORT=1
14+
15+ RETVAL_FILE=.retVal.tmp # file contains return value of script, useful for travis
16+ rm -f $RETVAL_FILE # rm retval file first
1317
1418# print colored title
1519print_title ()
@@ -37,21 +41,48 @@ print_warning()
3741 echo -e " |==============================================${NC} "
3842}
3943
44+ updateRetval ()
45+ {
46+ # add $1 to retVal file
47+ local retVal=0
48+ local incVal=$1
49+
50+ if [ -f $RETVAL_FILE ]; then
51+ # get content of retvalfile to retVal
52+ retVal=$( cat $RETVAL_FILE )
53+ fi
54+
55+ (( retVal = retVal + incVal))
56+ echo $retVal > $RETVAL_FILE
57+ }
58+
4059# run all make check in directory recursively
4160function checkFolder()
4261{
43- local retVal=0
4462 find " $1 " -name Makefile | while read line; do
4563 local TEST_DIR=$( dirname $line ) /test/
4664 if [ -d " $TEST_DIR " ] ; then
4765 print_title " Checking in $( dirname ${line} ) "
48- make -C $( dirname $line ) check BRIEF=1 -j4
49-
50- (( retVal = retVal + $? ))
66+ make -C $( dirname $line ) check BRIEF=1 -j4
67+ updateRetval $?
5168 fi
5269 done
53-
54- return $retVal
70+ }
71+
72+ # run checkFolder on multiple folders
73+ function checkMultipleFolders()
74+ {
75+ # $* - list of folders
76+ dirList=(" $* " )
77+
78+ for D in $dirList ; do
79+ if [ -d $D ]; then
80+ checkFolder $D
81+ else
82+ print_warning " $D doesn't exist"
83+ updateRetval 1
84+ fi
85+ done
5586}
5687
5788# run make clean in dir recursively
@@ -65,19 +96,17 @@ function cleanFolder()
6596# run make all in dir recursively
6697function makeFolder()
6798{
68- local retVal=0
69-
7099 find " $1 " -name Makefile | while read line; do
71100 print_title " Compile in $( dirname ${line} ) ..." ;
72101
73102 if (( $FULL_REPORT == 0 )) ; then
74- make -C $( dirname $line ) all -j4 > /dev/null
103+ make -C $( dirname $line ) all -j4 > /dev/null
75104 else
76- make -C $( dirname $line ) all -j4
105+ make -C $( dirname $line ) all -j4
77106 fi
78107
79108 local MK_RESULT=$?
80- (( retVal = retVal + MK_RESULT))
109+ updateRetval $ MK_RESULT
81110
82111 if (( $MK_RESULT != 0 )) ; then
83112 print_warning " Error code $MK_RESULT on compiling $( dirname $line ) "
@@ -86,14 +115,26 @@ function makeFolder()
86115 fi
87116 fi
88117 done
89-
90- return $retVal
91118}
92119
93- function checkDependency()
120+ # run makeFolder on multiple folders
121+ function makeMultipleFolders()
94122{
95- local retVal=0
123+ # $* - list of folders
124+ dirList=(" $* " )
96125
126+ for D in $dirList ; do
127+ if [ -d $D ]; then
128+ makeFolder $D
129+ else
130+ print_warning " $D doesn't exist"
131+ updateRetval 1
132+ fi
133+ done
134+ }
135+
136+ function checkDependency()
137+ {
97138 # check submodules
98139 # for each dir in submodules
99140 local TOP=$( dirname $( readlink -f $0 ) )
@@ -115,40 +156,49 @@ function checkDependency()
115156 if [ -z " $( which avr-gcc 2> /dev/null) " ] || [ -z " $( which avrdude 2> /dev/null) " ]; then
116157 (( retVal= retVal+ 1 ))
117158 print_warning " Missing avr package, please install gcc-avr binutils-avr gdb-avr avr-libc avrdude"
118- fi
119-
120- return $retVal
159+ fi
121160}
122161
123162function showHelp()
124163{
125164cat << EOF
126- usage: $SCRIPT_DIR_RELATIVE option [ value]
165+ usage: $SCRIPT_DIR_RELATIVE [ option] { value} DIR1 DIR2 ...
127166
128167 OPTION DECRIPTION
129168 -c dir search in dir recursively and run make clean
130- -k dir search in dir recursively and run make check
131- -m dir search in dir recursively and run make all
169+ -k search in DIR1 DIR2 ... recursively and run make check
170+ -m search in DIR1 DIR2 ... recursively and run make all
132171
133172 -T check dependency
134173 -f force continue on make error, default: $FORCE_CONTINUE
135- -l full report , default: $FULL_REPORT
174+ -l set FULL_REPORT=0 , default: $FULL_REPORT
136175 -h this menu
137176EOF
138177}
139178
179+ function detectBuildFailure()
180+ {
181+ # check if there is .hex and .elf file generated from make
182+ # if not, return number of failures
183+ echo " "
184+ }
185+
140186# main ##############################################################
187+ CHECK_DIR=0
188+ COMPILE_DIR=0
189+
141190# getopt
142- while getopts " :c:k:m:t :flT" o; do
191+ while getopts " :c:kmt :flT" o; do
143192 case " ${o} " in
144193 c)
145194 cleanFolder ${OPTARG}
195+ exit $?
146196 ;;
147197 k)
148- checkFolder ${OPTARG}
198+ CHECK_DIR=1
149199 ;;
150200 m)
151- makeFolder ${OPTARG}
201+ COMPILE_DIR=1
152202 ;;
153203 t)
154204 print_title ${OPTARG}
@@ -157,7 +207,7 @@ while getopts ":c:k:m:t:flT" o; do
157207 FORCE_CONTINUE=1
158208 ;;
159209 l)
160- FULL_REPORT=1
210+ FULL_REPORT=0
161211 ;;
162212 T)
163213 checkDependency
@@ -169,3 +219,23 @@ while getopts ":c:k:m:t:flT" o; do
169219done
170220shift $(( OPTIND- 1 ))
171221
222+ # make check on a list of dirs recursively
223+ if [ " $CHECK_DIR " -ne " 0" ]; then
224+ checkMultipleFolders " $* "
225+ fi
226+
227+ # make all on a list of dirs recursively
228+ if [ " $COMPILE_DIR " -ne " 0" ]; then
229+ makeMultipleFolders " $* "
230+ fi
231+
232+ # make all on a list of dirs recursively
233+
234+ # find return value
235+ if [ -f $RETVAL_FILE ]; then
236+ retVal=$( cat $RETVAL_FILE )
237+ rm -f $RETVAL_FILE
238+ exit $retVal
239+ else
240+ exit -1
241+ fi
0 commit comments