/
build_cmake.sh
executable file
·274 lines (236 loc) · 7.38 KB
/
build_cmake.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
#!/usr/bin/env bash
# Copyright (C) 2016-2018 The ESPResSo project
# Copyright (C) 2014 Olaf Lenz
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
abort()
{
echo "An error occurred. Exiting..." >&2
echo "Command that failed: $BASH_COMMAND" >&2
exit 1
}
trap 'abort' 0
set -e
# HELPER FUNCTIONS
# output value of env variables
function outp {
for p in $*; do
echo " $p=${!p}"
done
}
# start a block
function start {
echo "=================================================="
echo "START $1"
echo "=================================================="
}
# end a block
function end {
echo "=================================================="
echo "END $1"
echo "=================================================="
}
# execute and output a command
function cmd {
echo ">$1"
eval $1
}
# handle environment variables
[ -z "$insource" ] && insource="false"
[ -z "$srcdir" ] && srcdir=`pwd`
[ -z "$cmake_params" ] && cmake_params=""
[ -z "$with_fftw" ] && with_fftw="true"
[ -z "$with_python_interface" ] && with_python_interface="true"
[ -z "$with_coverage" ] && with_coverage="false"
[ -z "$with_ubsan" ] && with_ubsan="false"
[ -z "$with_asan" ] && with_asan="false"
[ -z "$with_static_analysis" ] && with_static_analysis="false"
[ -z "$myconfig" ] && myconfig="default"
[ -z "$check_procs" ] && check_procs=2
[ -z "$build_procs" ] && build_procs=2
[ -z "$make_check" ] && make_check="true"
[ -z "$check_odd_only" ] && check_odd_only="false"
[ -z "$python_version" ] && python_version="2"
[ -z "$with_cuda" ] && with_cuda="true"
[ -z "$build_type" ] && build_type="Debug"
[ -z "$with_ccache" ] && with_ccache="false"
# If there are no user-provided flags they
# are added according to with_coverage.
if [ -z "$cxx_flags" ]; then
if $with_coverage; then
cxx_flags="-Og"
else
if $make_check; then
cxx_flags="-O3"
else
cxx_flags="-O0"
fi
fi
fi
if [[ ! -z ${with_coverage+x} ]]; then
bash <(curl -s https://codecov.io/env) &> /dev/null;
fi
cmake_params="-DCMAKE_BUILD_TYPE=$build_type -DPYTHON_EXECUTABLE=$(which python$python_version) -DWARNINGS_ARE_ERRORS=ON -DTEST_NP:INT=$check_procs $cmake_params -DWITH_SCAFACOS=ON"
cmake_params="$cmake_params -DCMAKE_CXX_FLAGS=$cxx_flags"
cmake_params="$cmake_params -DCMAKE_INSTALL_PREFIX=/tmp/espresso-unit-tests"
if $with_ccache; then
cmake_params="$cmake_params -DWITH_CCACHE=ON"
fi
if $insource; then
builddir=$srcdir
elif [ -z "$builddir" ]; then
builddir=$srcdir/build
fi
outp insource srcdir builddir make_check \
cmake_params with_fftw \
with_python_interface with_coverage \
with_ubsan with_asan \
build_procs check_odd_only \
with_static_analysis myconfig \
check_procs build_procs \
python_version with_cuda with_ccache
# check indentation of python files
pep8_command () {
if hash pep8 2> /dev/null; then
pep8 "$@"
elif hash pycodestyle 2> /dev/null; then
pycodestyle "$@"
else
echo "pep8 not found";
exit 1
fi
}
pep8_command --filename=*.pyx,*.pxd,*.py --select=E111 $srcdir/src/python/espressomd/
ec=$?
if [ $ec -eq 0 ]; then
echo ""
echo "Indentation in Python files correct..."
echo ""
else
echo ""
echo "Error: Python files are not indented the right way. Please use 4 spaces per indentation level!"
echo ""
exit $ec
fi
# enforce style rules
pylint_command () {
if hash pylint 2> /dev/null; then
pylint "$@"
elif hash pylint3 2> /dev/null; then
pylint3 "$@"
elif hash pylint-2 2> /dev/null; then
pylint-2 "$@"
elif hash pylint-3 2> /dev/null; then
pylint-3 "$@"
else
echo "pylint not found";
exit 1
fi
}
if [ $(pylint_command --version | grep -o 'pylint.*[0-9]\.[0-9]\.[0-9]' | awk '{ print $2 }' | cut -d'.' -f2) -gt 6 ]; then
score_option='--score=no'
else
score_option=''
fi
pylint_command $score_option --reports=no --disable=all --enable=C1001 $(find . -name '*.py*') || { echo -e "\nOld-style classes found.\nPlease convert to new-style:\nclass C: => class C(object):\n" && exit 1; }
if ! $insource; then
if [ ! -d $builddir ]; then
echo "Creating $builddir..."
mkdir -p $builddir
fi
fi
if ! $insource; then
cd $builddir
fi
# load MPI module if necessary
if [ -f "/etc/os-release" ]; then
grep -q suse /etc/os-release && source /etc/profile.d/modules.sh && module load gnu-openmpi
grep -q 'rhel\|fedora' /etc/os-release && for f in /etc/profile.d/*module*.sh; do source $f; done && module load mpi
fi
# CONFIGURE
start "CONFIGURE"
if [ $with_fftw = "true" ]; then
:
else
cmake_params="-DCMAKE_DISABLE_FIND_PACKAGE_FFTW3=ON $cmake_params"
fi
if [ $with_python_interface = "true" ]; then
cmake_params="-DWITH_PYTHON=ON $cmake_params"
else
cmake_params="-DWITH_PYTHON=OFF $cmake_params"
fi
if [ $with_coverage = "true" ]; then
cmake_params="-DWITH_COVERAGE=ON $cmake_params"
fi
if [ $with_asan = "true" ]; then
cmake_params="-DWITH_ASAN=ON $cmake_params"
fi
if [ $with_ubsan = "true" ]; then
cmake_params="-DWITH_UBSAN=ON $cmake_params"
fi
if [ $with_static_analysis = "true" ]; then
cmake_params="-DWITH_CLANG_TIDY=ON $cmake_params"
fi
if [ $with_cuda = "true" ]; then
:
else
cmake_params="-DWITH_CUDA=OFF $cmake_params"
fi
MYCONFIG_DIR=$srcdir/maintainer/configs
if [ "$myconfig" = "default" ]; then
echo "Using default myconfig."
else
myconfig_file=$MYCONFIG_DIR/$myconfig.hpp
if [ ! -e "$myconfig_file" ]; then
echo "$myconfig_file does not exist!"
exit 1
fi
echo "Copying $myconfig.hpp to $builddir/myconfig.hpp..."
cp $myconfig_file $builddir/myconfig.hpp
fi
cmd "cmake $cmake_params $srcdir" || exit 1
end "CONFIGURE"
# BUILD
start "BUILD"
cmd "make -k -j${build_procs}" || cmd "make -k -j1" || exit $?
end "BUILD"
if $make_check; then
start "TEST"
if [ -z "$run_tests" ]; then
if $check_odd_only; then
cmd "make -j${build_procs} check_python_parallel_odd $make_params" || exit 1
else
cmd "make -j${build_procs} check_python $make_params" || exit 1
fi
else
cmd "make python_tests $make_params"
for t in $run_tests; do
cmd "ctest --output-on-failure -R $t" || exit 1
done
fi
cmd "make -j${build_procs} check_unit_tests $make_params" || exit 1
cmd "make check_cmake_install $make_params" || exit 1
end "TEST"
else
start "TEST"
if [ "$HIP_PLATFORM" != "hcc" ]; then
cmd "mpiexec -n $check_procs ./pypresso $srcdir/testsuite/python/particle.py" || exit 1
fi
end "TEST"
fi
if $with_coverage; then
cd $builddir
lcov -q --directory . --capture --output-file coverage.info # capture coverage info
lcov -q --remove coverage.info '/usr/*' --output-file coverage.info # filter out system
lcov -q --remove coverage.info '*/doc/*' --output-file coverage.info # filter out docs
# Uploading report to CodeCov
if [ -z "$CODECOV_TOKEN" ]; then
bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
else
bash <(curl -s https://codecov.io/bash) -t "$CODECOV_TOKEN" || echo "Codecov did not collect coverage reports"
fi
fi
trap : 0