]> git.ipfire.org Git - thirdparty/util-linux.git/blame - .travis-functions.sh
tests: introduce ts_cleanup_on_exit()
[thirdparty/util-linux.git] / .travis-functions.sh
CommitLineData
dd68764c
RM
1#!/bin/bash
2
3#
4# .travis-functions.sh:
5# - helper functions to be sourced from .travis.yml
6# - designed to respect travis' environment but testing locally is possible
7#
8
9if [ ! -f "configure.ac" ]; then
10 echo ".travis-functions.sh must be sourced from source dir" >&2
11 return 1 || exit 1
12fi
13
14# some config settings
15MAKE="make -j4"
16DUMP_CONFIG_LOG="short"
17
18# We could test (exotic) out-of-tree build dirs using relative or abs paths.
19# After sourcing this script we are living in build dir. Tasks for source dir
20# have to use $SOURCE_DIR.
21SOURCE_DIR="."
22BUILD_DIR="."
23CONFIGURE="$SOURCE_DIR/configure"
24
25mkdir -p "$BUILD_DIR"
26cd "$BUILD_DIR" || return 1 || exit 1
27
28function configure_travis
29{
30 "$CONFIGURE" "$@"
31 err=$?
32 if [ "$DUMP_CONFIG_LOG" = "short" ]; then
33 grep -B1 -A10000 "^## Output variables" config.log | grep -v "_FALSE="
34 elif [ "$DUMP_CONFIG_LOG" = "full" ]; then
35 cat config.log
36 fi
37 return $err
38}
39
40function check_nonroot
41{
467eb52e
KZ
42 local opts="$MAKE_CHECK_OPTS"
43
dd68764c
RM
44 configure_travis \
45 --disable-use-tty-group \
46 --with-python \
47 --enable-all-programs \
48 --enable-gtk-doc \
49 || return
50 $MAKE || return
467eb52e 51 $MAKE check TS_OPTS="$opts" || return
dd68764c
RM
52 $MAKE install DESTDIR=/tmp/dest || return
53}
54
55function check_root
56{
467eb52e
KZ
57 local opts="$MAKE_CHECK_OPTS --parallel=1"
58
dd68764c
RM
59 configure_travis \
60 --with-python \
61 --enable-all-programs \
62 || return
63 $MAKE || return
64 $MAKE check TS_COMMAND="true" || return
467eb52e 65 sudo -E $MAKE check TS_OPTS="$opts" || return
dd68764c
RM
66 sudo $MAKE install || return
67}
68
69function check_dist
70{
71 configure_travis \
72 || return
73 $MAKE distcheck || return
74}
75
c72836b3
RM
76function travis_install_script
77{
78 # install some packages from Ubuntu's default sources
79 sudo apt-get -qq update || return
80 sudo apt-get install -qq >/dev/null \
81 bc \
82 dnsutils \
83 libcap-ng-dev \
84 libpam-dev \
85 libudev-dev \
86 gtk-doc-tools \
87 ntp \
88 || return
33d4ebb3
RM
89
90 # install/upgrade custom stuff from non-official sources
91 sudo add-apt-repository -y ppa:malcscott/socat || return
92 sudo apt-get -qq update || return
93 sudo apt-get install -qq >/dev/null \
94 socat \
95 || return
c72836b3
RM
96}
97
dd68764c
RM
98function travis_before_script
99{
100 pushd "$SOURCE_DIR" || return
101 set -o xtrace
102
103 ./autogen.sh
104 ret=$?
105
106 # workaround for broken pylibmount install relink
107 [ $ret -eq 0 ] && \
108 sed -i 's/\(link_all_deplibs\)=no/\1=unknown/' ./configure
109
110 set +o xtrace
111 popd
112 return $ret
113}
114
115function travis_script
116{
117 local ret
118 set -o xtrace
119
120 case "$MAKE_CHECK" in
121 nonroot)
122 check_nonroot
123 ;;
124 root)
125 check_root
126 ;;
127 dist)
128 check_dist
129 ;;
130 *)
131 echo "error, check environment (travis.yml)" >&2
132 false
133 ;;
134 esac
135
136 # We exit here with case-switch return value!
137 ret=$?
138 set +o xtrace
139 return $ret
140}
141
142function travis_after_script
143{
144 local diff_dir
145 local tmp
146
147 # find diff dir from check as well as from distcheck
148 diff_dir=$(find -type d -a -name "diff" | grep "tests/diff" | head -n 1)
149 if [ -d "$diff_dir" ]; then
150 tmp=$(find "$diff_dir" -type f | sort)
151 echo -en "dump test diffs:\n${tmp}\n"
152 echo "$tmp" | xargs -r cat
153 fi
154}