-
Notifications
You must be signed in to change notification settings - Fork 1
/
project_manager.sh
executable file
·248 lines (214 loc) · 5.69 KB
/
project_manager.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
#
# maintainer script
# essential for travis builder
#
# path to this script file
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT_DIR_RELATIVE=$0
# global vars
FORCE_CONTINUE=0
BRIEF_REPORT=0
RETVAL_FILE=.retVal.tmp # file contains return value of script, useful for travis
echo "0">$RETVAL_FILE # rm retval file first
# print colored title
print_title()
{
local RED='\033[0;31m'
local GREEN='\033[0;32m'
local NC='\033[0m' # No Color
local txt=$@
echo -e "\n${GREEN}|=============================================="
echo "| $txt"
echo -e "|==============================================${NC}"
}
# print colored warning
print_warning()
{
local RED='\033[0;31m'
local GREEN='\033[0;32m'
local NC='\033[0m' # No Color
local txt=$@
echo -e "\n${RED}|=============================================="
echo "| $txt"
echo -e "|==============================================${NC}"
}
updateRetval()
{
# add $1 to retVal file
local retVal=0
local incVal=$1
if [ -f $RETVAL_FILE ]; then
# get content of retvalfile to retVal
retVal=$(cat $RETVAL_FILE)
fi
((retVal = retVal + incVal))
echo $retVal > $RETVAL_FILE
}
# run all make check in directory recursively
function checkFolder()
{
find "$1" -name Makefile | while read line; do
local TEST_DIR=$(dirname $line)/test/
if [ -d "$TEST_DIR" ] ; then
print_title "Checking in $(dirname ${line})"
if [ $BRIEF_REPORT != 0 ]; then
make -C $(dirname $line) check BRIEF=1 -j4
else
make -C $(dirname $line) check -j4
fi
updateRetval $?
fi
done
}
# run checkFolder on multiple folders
function checkMultipleFolders()
{
# $* - list of folders
dirList=("$*")
for D in $dirList; do
if [ -d $D ]; then
checkFolder $D
else
print_warning "$D doesn't exist"
updateRetval 1
fi
done
}
# run make clean in dir recursively
function cleanFolder()
{
find "$1" -name Makefile | while read line; do
make -C $(dirname $line) clean
done
}
# run make all in dir recursively
function makeFolder()
{
find "$1" -name Makefile | while read line; do
print_title "Compile in $(dirname ${line})..." ;
if (($BRIEF_REPORT != 0)) ; then
make -C $(dirname $line) all -j4 > /dev/null
else
make -C $(dirname $line) all -j4
fi
local MK_RESULT=$?
updateRetval $MK_RESULT
if (($MK_RESULT!=0)) ; then
print_warning "Error code $MK_RESULT on compiling $(dirname $line)"
if (($FORCE_CONTINUE == 0)) ; then
exit $MK_RESULT
fi
fi
done
}
# run makeFolder on multiple folders
function makeMultipleFolders()
{
# $* - list of folders
dirList=("$*")
for D in $dirList; do
if [ -d $D ]; then
makeFolder $D
else
print_warning "$D doesn't exist"
updateRetval 1
fi
done
}
function checkDependency()
{
# check submodules
# for each dir in submodules
local TOP=$(dirname $(readlink -f $0))
for D in `find $TOP/submodules/ -maxdepth 1 -mindepth 1 -type d`
do
if [ -z "$(ls -A $D)" ]; then
updateRetval 1
print_warning "Missing submodule $D, perhaps you forgot to run git submodule update --init --recursive"
fi
done
# check arduino ide
if [ -z "$(which arduino 2>/dev/null)" ]; then
updateRetval 1
print_warning "Missing arduino ide, which is required for Arduino-makefile submodule, please install arduino"
fi
# check avr
if [ -z "$(which avr-gcc 2>/dev/null)" ] || [ -z "$(which avrdude 2>/dev/null)" ]; then
updateRetval 1
print_warning "Missing avr package, please install gcc-avr binutils-avr gdb-avr avr-libc avrdude"
fi
}
function showHelp()
{
cat << EOF
usage: $SCRIPT_DIR_RELATIVE [option] {value} DIR1 DIR2 ...
OPTION DECRIPTION
-c dir search in dir recursively and run make clean
-k search in DIR1 DIR2 ... recursively and run make check
-m search in DIR1 DIR2 ... recursively and run make all
-T check dependency
-f force continue on make error, default: $FORCE_CONTINUE
-b set brief report
-h this menu
EOF
}
function detectBuildFailure()
{
# check if there is .hex and .elf file generated from make
# if not, return number of failures
echo ""
}
# main ##############################################################
CHECK_DIR=0
COMPILE_DIR=0
# getopt
while getopts ":c:kbmt:fT" o; do
case "${o}" in
c)
cleanFolder ${OPTARG}
retVal=$?
rm -f $RETVAL_FILE
exit $retVal
;;
k)
CHECK_DIR=1
;;
m)
COMPILE_DIR=1
;;
t)
print_title ${OPTARG}
;;
f)
FORCE_CONTINUE=1
;;
b)
BRIEF_REPORT=1
;;
T)
checkDependency
;;
*)
showHelp
;;
esac
done
shift $((OPTIND-1))
# make check on a list of dirs recursively
if [ "$CHECK_DIR" -ne "0" ]; then
checkMultipleFolders "$*"
fi
# make all on a list of dirs recursively
if [ "$COMPILE_DIR" -ne "0" ]; then
makeMultipleFolders "$*"
fi
# make all on a list of dirs recursively
# find return value
if [ -f $RETVAL_FILE ]; then
retVal=$(cat $RETVAL_FILE)
rm -f $RETVAL_FILE
exit $retVal
else
exit -1
fi