-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun
executable file
·342 lines (282 loc) · 9.08 KB
/
run
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#! /usr/bin/env bash
# by [email protected]
# settings
BASE_DIR=`dirname $0`
# cleanup
function bvs_clean {
[ -d build ] && cd build && echo ">>> CHDIR -> 'build'"
echo ">>> RUNNING MAKE CLEAN..."
[ -r Makefile ] && make clean
DIRS=()
for i in `ls -d ./ android daemon lib modules modules/*/ modules/*/*/ 2>/dev/null`
do
DIRS[${#DIRS[@]}]="$i"
done
echo -n ">>> REMOVING CMAKE FILES, DOCS AND DIRS:"
for (( i = ${#DIRS[@]}-1; i>=0; i-- ))
do
DIR=${DIRS[i]}
rm -f $DIR/Makefile $DIR/CMakeCache.txt $DIR/cmake_install.cmake $DIR/CTestTestfile.cmake
rm -rf $DIR/CMakeFiles
rm -f $DIR/Doxyfile
rm -rf $DIR/doc
[ -d $DIR ] && rmdir $DIR &> /dev/null
echo -n " $DIR"
done
echo
echo -n ">>> REMOVING SYMLINKS:"
for i in bin/*.conf
do
[ -L $i ] && rm $i && echo -n " $i"
done
echo
cd $BASE_DIR
}
# run example
function bvs_example {
echo ">>> This is an example of the BVS framework!"
echo
# check environment
[ ! -f CMakeLists.txt -a ! -f Changelog.txt ] && echo ">>> Please run from BVS' base directory!" && exit 1
if [ ! -d modules/bvs-modules ]
then
echo ">>> 'bvs-modules' not found, starting setup!"
echo "yNNNNNNNNNNNNN" | ./run --setup
fi
sed -i -e "s/#add_subdirectory(bvs-modules\/CaptureCV)/add_subdirectory(bvs-modules\/CaptureCV)/g" modules/CMakeLists.txt
sed -i -e "s/#add_subdirectory(bvs-modules\/ExampleCV)/add_subdirectory(bvs-modules\/ExampleCV)/g" modules/CMakeLists.txt
rm -f modules/CMakeLists.txt-e
# build system
[ ! -d build ] && mkdir build
cd build
cmake ..
make
cd -
#run example
EXAMPLE_CONFIG="$PWD/modules/bvs-modules/ExampleCV/BVS-Framework-ExampleCV.conf"
bvs_run "$EXAMPLE_CONFIG"
}
# help
function bvs_help {
cat << EOF
usage: $0 [--flags [\$arg]]
$0 [--debug] [config]
basic:
-c|--clean -- run 'make clean' and remove all CMake generated content
-n|--new-module \$[path/]name -- create new module from template (path relative to modules/)
-s|--setup -- initialize selected modules
-u|--update -- pull updates for all directories in modules/
advanced:
--rename-module \$old \$new -- rename module (path relative to modules/)
--reset \$tag -- reset (rollback) to specific version (tag)
other:
--example -- run 'bvsd' with framework example (requires bvs-modules, OpenCV and a Camera)
-h|-?|--help -- display this text
targets:
[config] -- run 'bvsd' with the given config (default:bvs.conf)
-d|--debug -- run 'bvsd' in gdb/lldb session
-f|--fifo -- run 'bvsd' reading input from 'bvsd-fifo'
EOF
}
# create new module or modify existing one
function bvs_module {
# check input
[ -z "$1" -o -z "$2" ] && echo ">>> No module name given!" && exit 1
# name stuff
ORIG_PATH=$1
ORIG=`basename $1`
ORIGC=`echo $ORIG | tr "[:lower:]" "[:upper:]"`
MOD_PATH=$2
MOD=`basename $2`
MODC=`echo $MOD | tr "[:lower:]" "[:upper:]"`
_NEW=''
# verify arguments
[ -z ${MOD/*[^[:alnum:]_]*} ] && echo ">>> Module name cannot only contain 'a-z,0-9,_' due to internal processing reasons! Please choose a different name!" && exit 1
[ -d modules/$MOD ] && echo ">>> A module of name '$MOD' already exits at location 'modules/$MOD_PATH'! Please choose a different name and/or location!" && exit 1
[ "$ORIG" == "BVSExampleModule" ] && _NEW="TRUE"
if [ $_NEW ]
then
echo ">>> Creating new module '$MOD'!"
[ ! -d modules/`dirname $MOD_PATH`/`basename $MOD_PATH` ] && mkdir -p modules/$MOD_PATH
else
echo ">>> Renaming module '$ORIG' -> '$MOD'!"
[ ! -d modules/$ORIG_PATH ] && echo ">>> Directory 'modules/$ORIG_PATH' does not exist!" && exit 1
[ -d modules/$MOD_PATH ] && echo ">>> Direcotry or module 'modules/$MOD_PATH' already exists!" && exit 1
[ ! -d modules/`dirname $MOD_PATH` ] && mkdir -p modules/`dirname $MOD_PATH`
fi
# copy
if [ $_NEW ]
then
echo ">>> Copying template to 'modules/$MOD_PATH!'"
cp lib/module/* lib/module/.gitignore modules/$MOD_PATH/
echo ">>> Modifying template!"
else
echo ">>> Copying 'modules/$ORIG_PATH' to 'modules/$MOD_PATH!'"
cp -r modules/$ORIG_PATH modules/$MOD_PATH
echo ">>> Modyfing '$MOD'!"
fi
# modify
cd modules/$MOD_PATH
mv $ORIG.h $MOD.h
mv $ORIG.cc $MOD.cc
mv ${ORIG}.conf ${MOD}.conf
FILES=(CMakeLists.txt $MOD.h $MOD.cc ${MOD}.conf)
sed -i -e "s/$ORIG/$MOD/g" ${FILES[@]}
sed -i -e "s/$ORIGC/$MODC/g" ${FILES[@]}
rm -f *-e
cd - > /dev/null
# update module cmake info
[ ! -r modules/CMakeLists.txt ] && echo "# enable/disable to be compiled modules here (entries will be created by './run --new-module <MODULE>')" > modules/CMakeLists.txt
if [ $_NEW ]
then
echo "#add_subdirectory($MOD_PATH)" >> modules/CMakeLists.txt
echo ">>> Created Module 'modules/$MOD_PATH'! Please modify modules/CMakeLists.txt to add it to compilation!"
else
eval sed -i -e "s#\(${ORIG_PATH//\//\\\/}\)#\(${MOD_PATH//\//\\\/}\)#" modules/CMakeLists.txt
eval rm -f modules/CMakeLists.txt-e
echo ">>> Renamed Module 'modules/$ORIG_PATH' to 'modules/$MOD_PATH' and modified CMakeLists.txt accordingly!"
echo ">>> 'modules/$ORIG_PATH' left intact, can be deleted now!"
fi
}
# reset to version
function bvs_reset {
TAG=$1
git tag | grep -q -E "^$TAG$" || echo ">>> $TAG does not exist (list available tags with 'git tag')!"
git tag | grep -q -E "^$TAG$" || exit 1
STATUS=`git status --porcelain --ignore-submodules=all`
[ -n "$STATUS" ] && echo ">>> UNCOMMITED LOCAL CHANGES, ABORTING (THEY WOULD BE LOST OTHERWISE)!" && exit 1
BRANCH=`git rev-parse --abbrev-ref HEAD`
REMOTE_BRANCH=`git rev-parse --abbrev-ref $BRANCH@{upstream}`
LOCAL_COMMITS=`git rev-list --reverse $REMOTE_BRANCH..HEAD`
echo ">>> STORING `echo \"$LOCAL_COMMITS\" | wc -l` LOCAL COMMIT(S)!"
echo ">>> RESETTING TO $TAG!"
git reset --hard $TAG
echo ">>> CHERRY PICKING LOCAL COMMIT(S)!"
echo "$LOCAL_COMMITS" | git cherry-pick --stdin
echo ">>> DONE!"
}
# run
function bvs_run {
[ -f $BASE_DIR/bvsd ] && BIN_DIR="."
[ -f $BASE_DIR/bin/bvsd ] && BIN_DIR="bin"
[ -f $BASE_DIR/build/bin/bvsd ] && BIN_DIR="build/bin"
[ -z $BIN_DIR ] && echo ">>> BVSD: executable not found, must build it first!" && exit
for i in $@
do
if [ "$i" = "-d" -o "$i" = "--debug" ]
then
shift
if hash gdb 2>/dev/null; then
DEBUGGER="gdb -q --args"
elif hash lldb 2>/dev/null; then
DEBUGGER="lldb --"
else
echo ">>> Could not find a debugger!"
exit
fi
fi
if [ "$i" = "-f" -o "$i" = "--fifo" ]
then
[ ! -r $BIN_DIR/bvsd-fifo ] && mkfifo $BIN_DIR/bvsd-fifo
FIFO='tail -f bvsd-fifo |'
shift
fi
done
[ $# = 0 ] && CONFIG="bvs.conf" || CONFIG=$1
[ -n "$FIFO" ] && cat << EOF
>>> FIFO ACTIVATED!!!
>>> FIFO located at: $BIN_DIR/bvsd-fifo
>>> FIFO usage e.g.: 'cat - > $BIN_DIR/bvsd-fifo' or 'echo "h" > $BIN_DIR/bvsd-fifo'
EOF
eval "(cd $BASE_DIR/$BIN_DIR && $FIFO $DEBUGGER ./bvsd --bvs.config=$CONFIG)"
}
# setup
function bvs_setup {
ORIGIN="`git config --get remote.origin.url`"
[ -z "$ORIGIN" ] && git remote add origin https://github.com/nilsonholger/bvs.git
ORIGIN="${ORIGIN:-https://github.com/nilsonholger/}"
ORIGIN="${ORIGIN/bvs.git}"
echo
echo ">>> SELECT modules to install!"
while read LINE; do MODULES[${#MODULES[@]}]=$LINE; done < .bvsmodules
[ ! -d modules ] && mkdir modules
for MOD in "${MODULES[@]}"
do
eval MOD=($MOD)
NAME=${MOD[0]}
REPO=${MOD[1]/ORIGIN:/${ORIGIN}}
[ -d modules/$NAME ] && echo ">>> SKIP $NAME!" && continue
echo
echo -e ">>> INSTALL $NAME ($REPO)? [y|N] \c"
read -n 1 CMD
[ "$CMD"x != "yx" ] && echo " >>> SKIP $NAME!" && continue
echo
(cd modules/; git clone $REPO $NAME)
[ ! -r modules/CMakeLists.txt ] && echo "# enable module compilation here (entries created by './run --new-module <MODULE>' or './run --setup')" > modules/CMakeLists.txt
if [ "${MOD[2]}" == "COLLECTION" ]
then
for i in modules/$NAME/*
do
[ ! -d $i ] && continue
MOD=${i/modules\/}
echo "#add_subdirectory($MOD)" >> modules/CMakeLists.txt
done
else
echo "#add_subdirectory($NAME)" >> modules/CMakeLists.txt
fi
done
echo
echo ">>> SETUP complete!"
[ ! -d build ] && echo ">>> ADVICE: for out of source builds, consider using the directory 'build' (see Readme.txt)"
echo ">>> ADVICE: Please modify modules/CMakeLists.txt to enable modules you want to add to compilation!"
echo
}
# update
function bvs_update {
BASE=$PWD
QUIET='--quiet'
DIRS=(./ `\find modules -depth 1`)
i=0; for DIR in ${DIRS[@]}; do [ ! -d "$BASE/$DIR" ] && unset DIRS[i]; i=$[ i+1 ]; done
STASHES=()
echo ">>> STASHING CHANGES!"
for DIR in ${DIRS[@]}
do
cd "$BASE/$DIR"
STATUS=`git status --porcelain --ignore-submodules=all`
if [ -z "$STATUS" ]
then
continue
else
echo ">>> -> $DIR"
STASHES[${#STASHES[@]}]="$DIR"
git stash $QUIET
fi
done
cd $BASE
echo ">>> UPDATING!"
for DIR in ${DIRS[@]}
do
echo ">>> -> $DIR"
(cd "$DIR"; git pull $QUIET)
done
echo ">>> REAPPLYING CHANGES!"
for STASH in ${STASHES[@]}
do
echo ">>> -> $STASH"
(cd $BASE/$STASH; git stash pop $QUIET)
done
cd $BASE
echo ">>> UPDATE DONE!"
echo ">>> Please solve any merge conflicts if necessary!"
}
case $1 in
'-c'|'--clean') bvs_clean;;
'--example') bvs_example;;
'-h'|'-?'|'--help') bvs_help;;
'-n'|'--new-module') bvs_module "BVSExampleModule" $2;;
'-s'|'--setup') bvs_setup;;
'-u'|'--update') bvs_update;;
'--rename-module') bvs_module $2 $3;;
'--reset') bvs_reset $2;;
""|*) bvs_run "$@";;
esac