]> git.ipfire.org Git - thirdparty/util-linux.git/blob - .travis-functions.sh
Merge branch 'sed' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / .travis-functions.sh
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
14 ## some config settings
15 # travis docs say we get 1.5 CPUs
16 MAKE="make -j2"
17 DUMP_CONFIG_LOG="short"
18 export TS_OPT_parsable="yes"
19
20 # workaround ugly warning on travis OSX,
21 # see https://github.com/direnv/direnv/issues/210
22 shell_session_update() { :; }
23
24 function xconfigure
25 {
26 which "$CC"
27 "$CC" --version
28
29 ./configure "$@" $OSX_CONFOPTS
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
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
50 function check_nonroot
51 {
52 local make_opts="$MAKE_CHECK_OPTS --show-diff"
53 local conf_opts="\
54 --disable-use-tty-group \
55 --disable-makeinstall-chown \
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
64 $MAKE || return
65
66 osx_prepare_check
67 $MAKE check TS_OPTS="$make_opts" || return
68
69 make_checkusage || return
70
71 $MAKE install DESTDIR=/tmp/dest || return
72 }
73
74 function check_root
75 {
76 local make_opts="$MAKE_CHECK_OPTS --show-diff"
77 local conf_opts="--enable-all-programs"
78
79 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
80 conf_opts="$conf_opts --enable-asan"
81 make_opts="$make_opts --memcheck-asan"
82 fi
83
84 xconfigure $conf_opts || return
85 $MAKE || return
86
87 $MAKE check TS_COMMAND="true" || return
88 osx_prepare_check
89 sudo -E $MAKE check TS_OPTS="$make_opts" || return
90
91 # root on osx has not enough permission for make install ;)
92 [ "$TRAVIS_OS_NAME" = "osx" ] && return
93
94 # keep PATH to make sure sudo would find $CC
95 sudo env "PATH=$PATH" $MAKE install || return
96 }
97
98 function check_dist
99 {
100 xconfigure \
101 || return
102 $MAKE distcheck || return
103 }
104
105 function travis_install_script
106 {
107 if [ "$TRAVIS_OS_NAME" = "osx" ]; then
108 osx_install_script
109 return
110 fi
111
112 # install required packages
113 sudo apt-get -qq update --fix-missing
114 sudo apt-get install -qq >/dev/null \
115 bc \
116 btrfs-tools \
117 dnsutils \
118 libcap-ng-dev \
119 libncursesw5-dev \
120 libpam-dev \
121 libudev-dev \
122 gtk-doc-tools \
123 mdadm \
124 ntp \
125 socat \
126 || return
127
128 # install only if available (e.g. Ubuntu Trusty)
129 sudo apt-get install -qq >/dev/null \
130 libsystemd-daemon-dev \
131 libsystemd-journal-dev \
132 || true
133 }
134
135 function osx_install_script
136 {
137 brew update >/dev/null
138
139 brew install gettext ncurses socat xz
140 brew link --force gettext
141 brew link --force ncurses
142
143 OSX_CONFOPTS="
144 --disable-ipcrm \
145 --disable-ipcs \
146 "
147
148 # workaround: glibtoolize could not find sed
149 export SED="sed"
150 }
151
152 function osx_prepare_check
153 {
154 [ "$TRAVIS_OS_NAME" = "osx" ] || return 0
155
156 # these ones only need to be gnu for our test-suite
157 brew install coreutils findutils gnu-tar gnu-sed
158
159 # symlink minimally needed gnu commands into PATH
160 mkdir ~/bin
161 for cmd in readlink seq timeout truncate find xargs tar sed; do
162 ln -s /usr/local/bin/g$cmd $HOME/bin/$cmd
163 done
164 hash -r
165
166 export TS_OPT_col_multibyte_known_fail=yes
167 export TS_OPT_colcrt_regressions_known_fail=yes
168 export TS_OPT_column_invalid_multibyte_known_fail=yes
169 }
170
171 function travis_before_script
172 {
173 set -o xtrace
174
175 ./autogen.sh
176 ret=$?
177
178 set +o xtrace
179 return $ret
180 }
181
182 function travis_script
183 {
184 local ret
185 set -o xtrace
186
187 case "$MAKE_CHECK" in
188 nonroot)
189 check_nonroot
190 ;;
191 root)
192 check_root
193 ;;
194 dist)
195 check_dist
196 ;;
197 *)
198 echo "error, check environment (travis.yml)" >&2
199 false
200 ;;
201 esac
202
203 # We exit here with case-switch return value!
204 ret=$?
205 set +o xtrace
206 return $ret
207 }
208
209 function travis_after_script
210 {
211 local diff_dir
212 local tmp
213
214 # find diff dir from check as well as from distcheck
215 diff_dir=$(find . -type d -name "diff" | grep "tests/diff" | head -n 1)
216 if [ -d "$diff_dir" ]; then
217 tmp=$(find "$diff_dir" -type f | sort)
218 echo -en "dump test diffs:\n${tmp}\n"
219 echo "$tmp" | xargs cat
220 fi
221 }