]> git.ipfire.org Git - thirdparty/util-linux.git/blob - .travis-functions.sh
Merge branch 'travis2' of https://github.com/filbranden/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 MAKE="make -j4"
16 DUMP_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.
21 SOURCE_DIR="."
22 BUILD_DIR="."
23 CONFIGURE="$SOURCE_DIR/configure"
24
25 mkdir -p "$BUILD_DIR"
26 cd "$BUILD_DIR" || return 1 || exit 1
27
28 function 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
40 function check_nonroot
41 {
42 local opts="$MAKE_CHECK_OPTS"
43
44 configure_travis \
45 --disable-use-tty-group \
46 --with-python \
47 --enable-all-programs \
48 --enable-gtk-doc \
49 || return
50 $MAKE || return
51 $MAKE check TS_OPTS="$opts" || return
52 $MAKE install DESTDIR=/tmp/dest || return
53 }
54
55 function check_root
56 {
57 local opts="$MAKE_CHECK_OPTS --parallel=1"
58
59 configure_travis \
60 --with-python \
61 --enable-all-programs \
62 || return
63 $MAKE || return
64 $MAKE check TS_COMMAND="true" || return
65 sudo -E $MAKE check TS_OPTS="$opts" || return
66 sudo $MAKE install || return
67 }
68
69 function check_dist
70 {
71 configure_travis \
72 || return
73 $MAKE distcheck || return
74 }
75
76 function 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
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
96 }
97
98 function travis_before_script
99 {
100 pushd "$SOURCE_DIR" || return
101 set -o xtrace
102
103 ./autogen.sh
104 ret=$?
105
106 set +o xtrace
107 popd
108 return $ret
109 }
110
111 function travis_script
112 {
113 local ret
114 set -o xtrace
115
116 case "$MAKE_CHECK" in
117 nonroot)
118 check_nonroot
119 ;;
120 root)
121 check_root
122 ;;
123 dist)
124 check_dist
125 ;;
126 *)
127 echo "error, check environment (travis.yml)" >&2
128 false
129 ;;
130 esac
131
132 # We exit here with case-switch return value!
133 ret=$?
134 set +o xtrace
135 return $ret
136 }
137
138 function travis_after_script
139 {
140 local diff_dir
141 local tmp
142
143 # find diff dir from check as well as from distcheck
144 diff_dir=$(find -type d -a -name "diff" | grep "tests/diff" | head -n 1)
145 if [ -d "$diff_dir" ]; then
146 tmp=$(find "$diff_dir" -type f | sort)
147 echo -en "dump test diffs:\n${tmp}\n"
148 echo "$tmp" | xargs -r cat
149 fi
150 }