-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·383 lines (317 loc) · 8.44 KB
/
run.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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
function finish
{
if [ $# -eq 2 ]; then
echo $2
fi
echo
echo "=============================="
if [ $1 -eq 0 ]; then
echo "Run successfully finished!"
else
echo "Run failed!!!"
fi
echo "=============================="
exit $1
}
function getConfigValue
{
OS=$(uname)
PATTERN="Linux"
if echo "$OS" | grep -Eq "$PATTERN"; then
search="\"$1 - Linux\""
else
search="\"$1 - Windows\""
fi
configFile="./build.config"
local result
while IFS=, read -r key value; do
if [ "$key" = "$search" ]; then
result="$value"
break
fi
done < "$configFile"
echo $"${result//\"}"
}
function solveDependecies
{
echo "Solve dependecies"
DIR="./../../Deps"
if [ -d "$DIR" ]; then
echo "Directory: $DIR already exists."
else
echo "Create directory: $DIR."
mkdir "$DIR"
fi
cd "$DIR"
DIR="googletest"
if [ -d "$DIR" ]; then
echo "Directory: $DIR already exists."
else
echo "Fetch and build: $DIR."
git clone https://github.com/google/googletest.git
cd -
cmakeGen=$(getConfigValue "CMake generator")
cd -
echo The generator is: $cmakeGen
command="cmake -S googletest -B googletest/build"
if [ ${#cmakeGen} -gt 0 ]; then
command="$command -G \"$cmakeGen\""
fi
eval $command
cmake --build googletest/build -j 10
fi
error=$?
cd -
return $error
}
function runSetup
{
echo "Run setup"
git config core.hooksPath ./tools/git/hooks
git config commit.template ./tools/git/hooks/template_commit-msg
return $?
}
function configure
{
echo "Configure CMake"
if [ "$1" = "TestCov" ]; then
buildDir=$1
else
buildDir=$buildType
fi
command="cmake -B build/$buildDir"
if [ "$1" = "TestCov" ]; then
command="$command -DCODE_COVERAGE=ON"
else
command="$command -DCMAKE_BUILD_TYPE:STRING=$buildType -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
fi
cmakeGen=$(getConfigValue "CMake generator")
echo The generator is: $cmakeGen
if [ ${#cmakeGen} -gt 0 ]; then
command="$command -G \"$cmakeGen\""
fi
echo Running: $command
eval $command
error=$?
grep "CXX_FLAGS = " ./build/ -r
(( error |= $? ))
return $error
}
function build
{
echo "Build the project"
if [ "$1" = "TestCov" ]; then
buildDir=$1
else
buildDir=$buildType
fi
command="cmake --build ./build/$buildDir"
if ! [ "$1" = "TestCov" ]; then
command="$command --config $buildType"
fi
command="$command -j 10"
echo Running: $command
eval $command
return $?
}
function run
{
echo "Run the application"
./build/"$buildType"/src/$(basename $(pwd))
return $?
}
function test
{
echo "Run the test"
./build/"$buildType"/test/$(basename $(pwd))Test
return $?
}
function clean
{
echo "Clean the build"
rm -rf ./build
return $?
}
function setBuildType
{
echo "Set build type to $1"
DIR="./build"
if [ -d "$DIR" ]; then
echo "Directory: $DIR already exists."
else
echo "Create directory: $DIR."
mkdir "$DIR"
fi
echo "$1" > "$DIR/BuildType"
return $?
}
function createPatch
{
echo "Create a patch from the last commit"
git format-patch -1 HEAD --stdout > ./build/patchFile.patch
return $?
}
function applyPatch
{
echo "Apply the patch"
git am < ./build/patchFile.patch
return $?
}
function runValgrind
{
echo "Run Valgrind"
if ! [ -f "./build/Debug/src/$(basename $(pwd))" ]; then
echo "Debug executable is not found"
return 1
fi
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=1 ./build/Debug/src/$(basename $(pwd))
return $?
}
function testCoverage
{
configure "TestCov"
error=$?
build "TestCov"
(( error |= $? ))
executableName=$(basename $(pwd))
cd ./build/TestCov
lcov --capture --initial --rc lcov_branch_coverage=1 --directory . --output-file lcovResultBefore
src/"$executableName" # Run the program because the main function of the App is not tested.
test/"$executableName"Test
lcov --capture --rc lcov_branch_coverage=1 --directory . --output-file lcovResultAfter
lcov --rc lcov_branch_coverage=1 --add-tracefile lcovResultBefore --add-tracefile lcovResultAfter --output-file lcovResultCombined
sed -i '/_ZN11IHelloWorldD0Ev/d' lcovResultCombined # _ZN11IHelloWorldD0Ev and _ZN11IHelloWorldD2Ev destructors are created by compiler, but the former (deleting destructor of a pure virtual class) is expectedly never called.
lcov --remove --rc lcov_branch_coverage=1 lcovResultCombined '/usr/*' '*/Deps/*' -o lcovResult
genhtml lcovResult --rc genhtml_branch_coverage=1 --output-directory CodeCoverage > log
(( error |= $? ))
if ! grep -Eq "lines\.*: 100.0%" ./log; then
return 1
elif ! grep -Eq "functions\.*: 100.0%" ./log; then
return 1
fi
# Remove the test files before check the branches because measuring of branches is not applicable for them.
lcov --remove --rc lcov_branch_coverage=1 lcovResult '*/test/*' -o lcovResultNoTest
genhtml lcovResultNoTest --rc genhtml_branch_coverage=1 --output-directory CodeCoverageNoTest > logNoTest
# Search for no data since currently there are no any branches in the code.
if ! grep -Eq "branches\.*: no data found" ./logNoTest; then
return 1
fi
return $error
}
function analyseCode
{
error=0
for file in `find . -path ./build -prune -o -regex '.*\.\(cpp\|h\)' -print`
do
echo " --- Checking file: $file --- "
clang-tidy $file -p ./build/"$buildType"/
(( error |= $? ))
done
return $error
}
function formatCode
{
# Check if there is any modified files
numBefore=$(git diff --shortstat | tr -dc '0-9');
find . -path ./build -prune -o -regex '.*\.\(cpp\|h\)' -print -exec clang-format -style=file -i {} \;
error=$?
# Check if there is any modified files
numAfter=$(git diff --shortstat | tr -dc '0-9');
if ! [ "$numBefore" = "$numAfter" ]; then
echo "There is modified file. Check them!!!"
error=1
fi
return $error
}
function doc
{
doxygen Doxyfile
error=$?
# Remove unwanted 'strong' html tags from the results, Doxygen puts them for some reason...
sed -i -e 's/\(<strong>\|<\/strong>\|<strong>\|<\/strong>\)//g' ./build/Doc/html/index.html \
./build/Doc/html/navtreedata.js \
./build/Doc/html/search/pages_0.js \
./build/Doc/html/search/all_0.js
(( error |= $? ))
return $error
}
function complexity
{
# The limits and extensions should be re-investigated, the tool was sometimes stuck with t4
lizard \
-Tnloc=200 -Tcyclomatic_complexity=10 -Ttoken_count=1000 -Tparameter_count=5 -Tlength=250 \
-t1 \
-scyclomatic_complexity \
-Eboolcount -Edependencycount -Eduplicate -Eduplicated_param_list -Eexitcount -Egotocount -Eio -End -Ens -Estatementcount -Ewordcount \
-x'./build/*'
error=$?
mkdir ./build/
mv codecloud.html ./build/
return $error
}
function runTheJob
{
if [ $1 = "setRel" ]; then
setBuildType "Release"
elif [ $1 = "setDeb" ]; then
setBuildType "Debug"
elif [ $1 = "deps" ]; then
solveDependecies
elif [ $1 = "setup" ]; then
runSetup
elif [ $1 = "config" ]; then
configure
elif [ $1 = "build" ]; then
build
elif [ $1 = "run" ]; then
run
elif [ $1 = "test" ]; then
test
elif [ $1 = "all" ]; then
solveDependecies || finish 1
runSetup || finish 1
configure || finish 1
build || finish 1
run || finish 1
test || finish 1
elif [ $1 = "clean" ]; then
clean
elif [ $1 = "createPatch" ]; then
createPatch
elif [ $1 = "applyPatch" ]; then
applyPatch
elif [ $1 = "valgrind" ]; then
runValgrind
elif [ $1 = "testCov" ]; then
testCoverage
elif [ $1 = "analyseCode" ]; then
analyseCode
elif [ $1 = "formatCode" ]; then
formatCode
elif [ $1 = "doc" ]; then
doc
elif [ $1 = "complex" ]; then
complexity
else
finish 1 "The parameter is wrong!"
fi
return $?
}
function readBuildType
{
buildType=$(head -n 1 ./build/BuildType)
if [ ${#buildType} -eq 0 ]; then
buildType="Release"
fi
echo The current build type is: $buildType
}
echo "Run is starting..."
echo "The received parameter is \"$1\"."
if [ $# -eq 1 ]; then
readBuildType
runTheJob $1
finish $?
else
finish 1 "The number of parameters must be 1!"
fi