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