forked from util-linux/util-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis-functions.sh
executable file
·367 lines (302 loc) · 9.05 KB
/
.travis-functions.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
#!/bin/bash
#
# .travis-functions.sh:
# - helper functions to be sourced from .travis.yml
# - designed to respect travis' environment but testing locally is possible
#
# Variables:
#
# TS_OPT_<name>_<something>=yes
# - forces tests/functions.sh:ts_has_option() to return "yes" for
# variable <something> in test <name>
#
# TESTS_OPTIONS=
# TESTS_PARALLEL=
# TESTS_COMMAND=
# - overwrites default from tests/Makemodule.am
#
# Do not use TS_* prefix for any travis or build-system stuff. This prefix is
# exclusively used by tests/ stuff.
#
if [ ! -f "configure.ac" ]; then
echo ".travis-functions.sh must be sourced from source dir" >&2
return 1 || exit 1
fi
## some config settings
# travis docs say we get 1.5 CPUs
MAKE="make -j2"
DUMP_CONFIG_LOG="short"
# Coverity-related settings
COVERITY_SCAN_TOOL_BASE="/tmp/coverity-scan-analysis"
COVERITY_SCAN_PROJECT_NAME="karelzak/util-linux"
# workaround ugly warning on travis OSX,
# see https://github.com/direnv/direnv/issues/210
shell_session_update() { :; }
function xconfigure
{
local gcc_version clang_version cxx
which "$CC"
"$CC" --version
if [[ "$CC" =~ ^clang-([0-9]+)$ ]]; then
clang_version=${BASH_REMATCH[1]}
cxx=clang++-${clang_version}
elif [[ "$CC" =~ ^gcc-([0-9]+)$ ]]; then
gcc_version=${BASH_REMATCH[1]}
cxx=g++-${gcc_version}
elif [[ "$CC" == "clang" ]]; then
cxx=clang++
elif [[ "$CC" == "gcc" ]]; then
cxx=g++
fi
which "$cxx"
"$cxx" --version
CC=$CC CXX=$cxx ./configure "$@" $OSX_CONFOPTS
err=$?
if [ "$DUMP_CONFIG_LOG" = "short" ]; then
grep -B1 -A10000 "^## Output variables" config.log | grep -v "_FALSE="
elif [ "$DUMP_CONFIG_LOG" = "full" ]; then
cat config.log
fi
return $err
}
# TODO: integrate checkusage into our regular tests and remove this function
function make_checkusage
{
local tmp
# memory leaks are ignored here. See https://github.com/karelzak/util-linux/issues/1077
if ! tmp=$(ASAN_OPTIONS="$ASAN_OPTIONS:detect_leaks=0" $MAKE checkusage 2>&1) || test -n "$tmp"; then
echo "$tmp"
echo "make checkusage failed" >&2
return 1
fi
}
function check_nonroot
{
local make_opts="$MAKE_CHECK_OPTS --show-diff --parsable"
local conf_opts="\
--disable-use-tty-group \
--disable-makeinstall-chown \
--enable-all-programs"
if [ "$TRAVIS_OS_NAME" != "osx" ]; then
conf_opts="$conf_opts --enable-asan --enable-ubsan"
make_opts="$make_opts --memcheck-asan --memcheck-ubsan"
if [ "$TRAVIS_DIST" != "precise" ]; then
conf_opts="$conf_opts --enable-werror"
fi
if [[ "$CC" =~ "clang" ]]; then
conf_opts="$conf_opts --enable-fuzzing-engine"
fi
fi
xconfigure $conf_opts || return
$MAKE || return
osx_prepare_check
# TESTS_* overwrites default from tests/Makemodule.am
$MAKE check TESTS_OPTIONS="$make_opts" || return
make_checkusage || return
$MAKE install DESTDIR=/tmp/dest || return
}
function check_root
{
local make_opts="$MAKE_CHECK_OPTS --show-diff"
local conf_opts="--enable-all-programs"
if [ "$TRAVIS_OS_NAME" != "osx" ]; then
conf_opts="$conf_opts --enable-asan --enable-ubsan"
make_opts="$make_opts --memcheck-asan --memcheck-ubsan"
if [ "$TRAVIS_DIST" != "precise" ]; then
conf_opts="$conf_opts --enable-werror"
fi
if [[ "$CC" =~ "clang" ]]; then
conf_opts="$conf_opts --enable-fuzzing-engine"
fi
fi
xconfigure $conf_opts || return
$MAKE || return
# compile tests only
$MAKE check-programs || return
# Modify environment for OSX
osx_prepare_check
# TESTS_* overwrites default from tests/Makemodule.am
sudo -E $MAKE check TESTS_PARALLEL="" TESTS_OPTIONS="$make_opts" || return
# root on osx has not enough permission for make install ;)
[ "$TRAVIS_OS_NAME" = "osx" ] && return
# keep PATH to make sure sudo would find $CC
sudo env "PATH=$PATH" $MAKE install || return
}
function run_coverity
{
local results_dir="cov-int"
local tool_dir=$(find $COVERITY_SCAN_TOOL_BASE -type d -name 'cov-analysis*')
local results_archive="analysis-results.tgz"
local sha=$(git rev-parse --short HEAD)
local author_email=$(git log -1 --pretty="%aE")
local response status_code
xconfigure --enable-all-programs || return
echo -e "\033[33;1mRunning Coverity Scan Analysis Tool...\033[0m"
COVERITY_UNSUPPORTED=1 $tool_dir/bin/cov-build --dir $results_dir sh -c "$MAKE check-programs all" || return
$tool_dir/bin/cov-import-scm --dir $results_dir --scm git --log $results_dir/scm_log.txt || return
echo -e "\033[33;1mTarring Coverity Scan Analysis results...\033[0m"
tar czf $results_archive $results_dir || return
echo -e "\033[33;1mUploading Coverity Scan Analysis results...\033[0m"
response=$(curl \
--silent --write-out "\n%{http_code}\n" \
--form project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN \
--form email=$author_email \
--form file=@$results_archive \
--form version=$sha \
--form description="Travis CI build" \
https://scan.coverity.com/builds)
printf "\033[33;1mThe response is\033[0m\n%s\n" "$response"
status_code=$(echo "$response" | sed -n '$p')
if [ "$status_code" != "200" ]; then
echo -e "\033[33;1mCoverity Scan upload failed: $(echo "$response" | sed '$d').\033[0m"
return 1
fi
echo -e "\n\033[33;1mCoverity Scan Analysis completed successfully.\033[0m"
}
function check_dist
{
xconfigure \
|| return
$MAKE distcheck || return
}
function travis_install_script
{
local ubuntu_release
local additional_packages=()
local clang_version gcc_version
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
osx_install_script
return
fi
ubuntu_release=$(lsb_release -cs)
# install required packages
sudo bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ $ubuntu_release main restricted universe multiverse' >>/etc/apt/sources.list"
if [[ "$CC" =~ ^clang-([0-9]+)$ ]]; then
clang_version=${BASH_REMATCH[1]}
# the following snippet was borrowed from https://apt.llvm.org/llvm.sh
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.llvm.org/$ubuntu_release/ llvm-toolchain-$ubuntu_release-$clang_version main"
additional_packages+=(clang-$clang_version llvm-$clang_version)
elif [[ "$CC" =~ ^gcc-([0-9]+)$ ]]; then
gcc_version=${BASH_REMATCH[1]}
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
additional_packages+=(gcc-$gcc_version)
fi
sudo apt-get -qq update --fix-missing
sudo apt-get build-dep -y util-linux
sudo apt-get install -qq >/dev/null \
bc \
btrfs-tools \
dnsutils \
libcap-ng-dev \
libncursesw5-dev \
libpam-dev \
libudev-dev \
gtk-doc-tools \
mdadm \
ntp \
socat \
"${additional_packages[@]}" \
|| return
# install only if available (e.g. Ubuntu Trusty)
sudo apt-get install -qq >/dev/null \
libsystemd-daemon-dev \
libsystemd-journal-dev \
|| true
if [ "$TRAVIS_BUILD_STAGE_NAME" = "Coverity" ]; then
coverity_install_script
return
fi
}
function coverity_install_script
{
local platform=$(uname)
local tool_url="https://scan.coverity.com/download/${platform}"
local tool_archive="/tmp/cov-analysis-${platform}.tgz"
echo -e "\033[33;1mDownloading Coverity Scan Analysis Tool...\033[0m"
wget -nv -O $tool_archive $tool_url --post-data "project=$COVERITY_SCAN_PROJECT_NAME&token=$COVERITY_SCAN_TOKEN" || return
echo -e "\033[33;1mExtracting Coverity Scan Analysis Tool...\033[0m"
mkdir -p $COVERITY_SCAN_TOOL_BASE
pushd $COVERITY_SCAN_TOOL_BASE
tar xzf $tool_archive || return
popd
}
function osx_install_script
{
brew update >/dev/null
brew install gettext ncurses socat xz
brew link --force gettext
brew link --force ncurses
OSX_CONFOPTS="
--disable-ipcrm \
--disable-ipcs \
--disable-libmount \
"
# workaround: glibtoolize could not find sed
export SED="sed"
}
function osx_prepare_check
{
[ "$TRAVIS_OS_NAME" = "osx" ] || return 0
# these ones only need to be gnu for our test-suite
brew install coreutils findutils gnu-tar gnu-sed
# symlink minimally needed gnu commands into PATH
mkdir ~/bin
for cmd in readlink seq timeout truncate find xargs tar sed; do
ln -s /usr/local/bin/g$cmd $HOME/bin/$cmd
done
hash -r
export TS_OPT_col_multibyte_known_fail=yes
export TS_OPT_colcrt_regressions_known_fail=yes
export TS_OPT_column_invalid_multibyte_known_fail=yes
}
function travis_before_script
{
set -o xtrace
./autogen.sh
ret=$?
set +o xtrace
return $ret
}
function travis_script
{
local ret
# run_coverity should be run before set -o xtrace so as not to expose COVERITY_SCAN_TOKEN
if [ "$TRAVIS_BUILD_STAGE_NAME" = "Coverity" ]; then
run_coverity
return
fi
set -o xtrace
case "$MAKE_CHECK" in
nonroot)
check_nonroot
;;
root)
check_root
;;
dist)
check_dist
;;
*)
echo "error, check environment (travis.yml)" >&2
false
;;
esac
# We exit here with case-switch return value!
ret=$?
set +o xtrace
return $ret
}
function travis_after_script
{
local diff_dir
local tmp
# find diff dir from check as well as from distcheck
diff_dir=$(find . -type d -name "diff" | grep "tests/diff" | head -n 1)
if [ -d "$diff_dir" ]; then
tmp=$(find "$diff_dir" -type f | sort)
echo -en "dump test diffs:\n${tmp}\n"
echo "$tmp" | xargs cat
fi
}