]>
Commit | Line | Data |
---|---|---|
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 | ||
9 | if [ ! -f "configure.ac" ]; then | |
10 | echo ".travis-functions.sh must be sourced from source dir" >&2 | |
11 | return 1 || exit 1 | |
12 | fi | |
13 | ||
1091e83e RM |
14 | ## some config settings |
15 | # travis docs say we get 1.5 CPUs | |
16 | MAKE="make -j2" | |
dd68764c | 17 | DUMP_CONFIG_LOG="short" |
855f7f06 | 18 | export TS_OPT_parsable="yes" |
dd68764c | 19 | |
cf76bbae RM |
20 | # workaround ugly warning on travis OSX, |
21 | # see https://github.com/direnv/direnv/issues/210 | |
22 | shell_session_update() { :; } | |
23 | ||
1091e83e | 24 | function xconfigure |
dd68764c | 25 | { |
cf76bbae RM |
26 | which "$CC" |
27 | "$CC" --version | |
28 | ||
668d6d2e | 29 | ./configure "$@" $OSX_CONFOPTS |
dd68764c RM |
30 | err=$? |
31 | if [ "$DUMP_CONFIG_LOG" = "short" ]; then | |
32 | grep -B1 -A10000 "^## Output variables" config.log | grep -v "_FALSE=" | |
33 | elif [ "$DUMP_CONFIG_LOG" = "full" ]; then | |
34 | cat config.log | |
35 | fi | |
36 | return $err | |
37 | } | |
38 | ||
d1a7c00e RM |
39 | # TODO: integrate checkusage into our regular tests and remove this function |
40 | function make_checkusage | |
41 | { | |
42 | local tmp | |
43 | if ! tmp=$($MAKE checkusage 2>&1) || test -n "$tmp"; then | |
44 | echo "$tmp" | |
45 | echo "make checkusage failed" >&2 | |
46 | return 1 | |
47 | fi | |
48 | } | |
49 | ||
dd68764c RM |
50 | function check_nonroot |
51 | { | |
450016eb KZ |
52 | local make_opts="$MAKE_CHECK_OPTS --show-diff" |
53 | local conf_opts="\ | |
dd68764c | 54 | --disable-use-tty-group \ |
a65041b5 | 55 | --disable-makeinstall-chown \ |
450016eb KZ |
56 | --enable-all-programs" |
57 | ||
58 | if [ "$TRAVIS_OS_NAME" != "osx" ]; then | |
59 | conf_opts="$conf_opts --enable-asan" | |
60 | make_opts="$make_opts --memcheck-asan" | |
61 | fi | |
62 | ||
63 | xconfigure $conf_opts || return | |
dd68764c | 64 | $MAKE || return |
668d6d2e RM |
65 | |
66 | osx_prepare_check | |
ac543a15 KZ |
67 | |
68 | # TS_OPTS= overwrites default from tests/Makemodule.am | |
450016eb | 69 | $MAKE check TS_OPTS="$make_opts" || return |
668d6d2e | 70 | |
d1a7c00e RM |
71 | make_checkusage || return |
72 | ||
dd68764c RM |
73 | $MAKE install DESTDIR=/tmp/dest || return |
74 | } | |
75 | ||
76 | function check_root | |
77 | { | |
450016eb KZ |
78 | local make_opts="$MAKE_CHECK_OPTS --show-diff" |
79 | local conf_opts="--enable-all-programs" | |
266f8562 | 80 | |
450016eb KZ |
81 | if [ "$TRAVIS_OS_NAME" != "osx" ]; then |
82 | conf_opts="$conf_opts --enable-asan" | |
83 | make_opts="$make_opts --memcheck-asan" | |
84 | fi | |
85 | ||
86 | xconfigure $conf_opts || return | |
dd68764c | 87 | $MAKE || return |
668d6d2e | 88 | |
ac543a15 KZ |
89 | # compile tests only |
90 | $MAKE check-programs || return | |
91 | ||
92 | # Modify environment for OSX | |
668d6d2e | 93 | osx_prepare_check |
ac543a15 KZ |
94 | |
95 | # TS_OPTS= overwrites default from tests/Makemodule.am | |
571f5f5b | 96 | sudo -E $MAKE check "TS_PARALLEL=--parallel=none" TS_OPTS="$make_opts" || return |
668d6d2e | 97 | |
277d61b9 RM |
98 | # root on osx has not enough permission for make install ;) |
99 | [ "$TRAVIS_OS_NAME" = "osx" ] && return | |
100 | ||
cf76bbae RM |
101 | # keep PATH to make sure sudo would find $CC |
102 | sudo env "PATH=$PATH" $MAKE install || return | |
dd68764c RM |
103 | } |
104 | ||
105 | function check_dist | |
106 | { | |
22174021 | 107 | xconfigure \ |
dd68764c RM |
108 | || return |
109 | $MAKE distcheck || return | |
110 | } | |
111 | ||
5ddcc32a RM |
112 | function travis_install_script |
113 | { | |
668d6d2e RM |
114 | if [ "$TRAVIS_OS_NAME" = "osx" ]; then |
115 | osx_install_script | |
116 | return | |
117 | fi | |
118 | ||
cf76bbae RM |
119 | # install required packages |
120 | sudo apt-get -qq update --fix-missing | |
5ddcc32a RM |
121 | sudo apt-get install -qq >/dev/null \ |
122 | bc \ | |
fc412fe4 | 123 | btrfs-tools \ |
5ddcc32a RM |
124 | dnsutils \ |
125 | libcap-ng-dev \ | |
91891979 | 126 | libncursesw5-dev \ |
5ddcc32a RM |
127 | libpam-dev \ |
128 | libudev-dev \ | |
129 | gtk-doc-tools \ | |
f81faffa | 130 | mdadm \ |
5ddcc32a | 131 | ntp \ |
fc412fe4 | 132 | socat \ |
5ddcc32a | 133 | || return |
432439a4 | 134 | |
fc412fe4 | 135 | # install only if available (e.g. Ubuntu Trusty) |
432439a4 | 136 | sudo apt-get install -qq >/dev/null \ |
fc412fe4 RM |
137 | libsystemd-daemon-dev \ |
138 | libsystemd-journal-dev \ | |
139 | || true | |
5ddcc32a RM |
140 | } |
141 | ||
668d6d2e RM |
142 | function osx_install_script |
143 | { | |
144 | brew update >/dev/null | |
668d6d2e RM |
145 | |
146 | brew install gettext ncurses socat xz | |
147 | brew link --force gettext | |
148 | brew link --force ncurses | |
149 | ||
150 | OSX_CONFOPTS=" | |
668d6d2e RM |
151 | --disable-ipcrm \ |
152 | --disable-ipcs \ | |
668d6d2e | 153 | " |
160eef81 RM |
154 | |
155 | # workaround: glibtoolize could not find sed | |
156 | export SED="sed" | |
668d6d2e RM |
157 | } |
158 | ||
159 | function osx_prepare_check | |
160 | { | |
161 | [ "$TRAVIS_OS_NAME" = "osx" ] || return 0 | |
162 | ||
163 | # these ones only need to be gnu for our test-suite | |
164 | brew install coreutils findutils gnu-tar gnu-sed | |
165 | ||
166 | # symlink minimally needed gnu commands into PATH | |
167 | mkdir ~/bin | |
4fb3fe39 | 168 | for cmd in readlink seq timeout truncate find xargs tar sed; do |
668d6d2e RM |
169 | ln -s /usr/local/bin/g$cmd $HOME/bin/$cmd |
170 | done | |
171 | hash -r | |
172 | ||
173 | export TS_OPT_col_multibyte_known_fail=yes | |
174 | export TS_OPT_colcrt_regressions_known_fail=yes | |
175 | export TS_OPT_column_invalid_multibyte_known_fail=yes | |
176 | } | |
177 | ||
dd68764c RM |
178 | function travis_before_script |
179 | { | |
dd68764c RM |
180 | set -o xtrace |
181 | ||
182 | ./autogen.sh | |
183 | ret=$? | |
184 | ||
dd68764c | 185 | set +o xtrace |
dd68764c RM |
186 | return $ret |
187 | } | |
188 | ||
189 | function travis_script | |
190 | { | |
191 | local ret | |
192 | set -o xtrace | |
193 | ||
194 | case "$MAKE_CHECK" in | |
195 | nonroot) | |
196 | check_nonroot | |
197 | ;; | |
198 | root) | |
199 | check_root | |
200 | ;; | |
201 | dist) | |
202 | check_dist | |
203 | ;; | |
204 | *) | |
205 | echo "error, check environment (travis.yml)" >&2 | |
206 | false | |
207 | ;; | |
208 | esac | |
209 | ||
210 | # We exit here with case-switch return value! | |
211 | ret=$? | |
212 | set +o xtrace | |
213 | return $ret | |
214 | } | |
215 | ||
216 | function travis_after_script | |
217 | { | |
218 | local diff_dir | |
219 | local tmp | |
220 | ||
221 | # find diff dir from check as well as from distcheck | |
1091e83e | 222 | diff_dir=$(find . -type d -name "diff" | grep "tests/diff" | head -n 1) |
dd68764c RM |
223 | if [ -d "$diff_dir" ]; then |
224 | tmp=$(find "$diff_dir" -type f | sort) | |
225 | echo -en "dump test diffs:\n${tmp}\n" | |
1091e83e | 226 | echo "$tmp" | xargs cat |
dd68764c RM |
227 | fi |
228 | } |