Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
8abe9f8a MJ |
2 | # |
3 | # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
4 | # Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com> | |
5 | # | |
6 | # This program is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
51c9c62d MJ |
19 | set -exu |
20 | ||
8abe9f8a MJ |
21 | # Version compare functions |
22 | vercomp () { | |
23 | set +u | |
24 | if [[ "$1" == "$2" ]]; then | |
25 | return 0 | |
26 | fi | |
27 | local IFS=. | |
28 | local i ver1=($1) ver2=($2) | |
29 | # fill empty fields in ver1 with zeros | |
30 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do | |
31 | ver1[i]=0 | |
32 | done | |
33 | for ((i=0; i<${#ver1[@]}; i++)); do | |
34 | if [[ -z ${ver2[i]} ]]; then | |
35 | # fill empty fields in ver2 with zeros | |
36 | ver2[i]=0 | |
37 | fi | |
38 | if ((10#${ver1[i]} > 10#${ver2[i]})); then | |
39 | return 1 | |
40 | fi | |
41 | if ((10#${ver1[i]} < 10#${ver2[i]})); then | |
42 | return 2 | |
43 | fi | |
44 | done | |
45 | set -u | |
46 | return 0 | |
47 | } | |
48 | ||
49 | verlte() { | |
50 | vercomp "$1" "$2"; local res="$?" | |
51 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
52 | } | |
53 | ||
54 | verlt() { | |
55 | vercomp "$1" "$2"; local res="$?" | |
56 | [ "$res" -eq "2" ] | |
57 | } | |
58 | ||
59 | vergte() { | |
60 | vercomp "$1" "$2"; local res="$?" | |
61 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
62 | } | |
63 | ||
64 | vergt() { | |
65 | vercomp "$1" "$2"; local res="$?" | |
66 | [ "$res" -eq "1" ] | |
67 | } | |
68 | ||
69 | verne() { | |
70 | vercomp "$1" "$2"; local res="$?" | |
71 | [ "$res" -ne "0" ] | |
72 | } | |
73 | ||
74 | # Required variables | |
75 | WORKSPACE=${WORKSPACE:-} | |
76 | ||
77 | ||
78 | SRCDIR="$WORKSPACE/src/babeltrace" | |
79 | TMPDIR="$WORKSPACE/tmp" | |
80 | OUTDIR="$WORKSPACE/out" | |
81 | TAPDIR="$WORKSPACE/tap" | |
82 | ||
83 | failed_tests=0 | |
84 | ||
85 | # Create build and tmp directories | |
86 | rm -rf "$OUTDIR" "$TMPDIR" "$TAPDIR" | |
87 | mkdir -p "$OUTDIR" "$TMPDIR" "$TAPDIR" | |
88 | ||
89 | export TMPDIR | |
90 | ||
91 | ||
92 | # Enter the source directory | |
93 | cd "$SRCDIR" | |
94 | ||
95 | # Run bootstrap in the source directory prior to configure | |
96 | ./bootstrap | |
97 | ||
98 | # Get source version from configure script | |
99 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
100 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} | |
101 | ||
102 | # Version specific configurations | |
103 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
104 | BASENAME="babeltrace2" | |
105 | CONF_OPTS=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins") | |
106 | ||
107 | # Enable dev mode by default for BT 2.0 builds | |
108 | #export BABELTRACE_DEBUG_MODE=1 | |
109 | #export BABELTRACE_DEV_MODE=1 | |
110 | #export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE | |
111 | else | |
112 | BASENAME="babeltrace" | |
113 | CONF_OPTS=("--enable-python-bindings") | |
114 | fi | |
115 | ||
116 | ||
117 | TARBALL_FILE="$BASENAME-$PACKAGE_VERSION.tar.bz2" | |
118 | ||
119 | ||
120 | # Make sure the reported version matches the current git tag | |
63ffe145 | 121 | GIT_TAG="$(git describe --exact-match --tags "$(git log -n1 --pretty='%h')" || echo 'undefined')" |
8abe9f8a MJ |
122 | |
123 | if [ "v$PACKAGE_VERSION" != "$GIT_TAG" ]; then | |
124 | echo "Git checkout is not tagged or doesn't match the reported version." | |
125 | exit 1 | |
126 | fi | |
127 | ||
128 | # Generate release tarball | |
63ffe145 | 129 | ./configure |
8abe9f8a MJ |
130 | make dist |
131 | cp "./$TARBALL_FILE" "$OUTDIR/" | |
132 | ||
133 | ## Do an in-tree test build | |
134 | mkdir "$WORKSPACE/intree" | |
135 | cd "$WORKSPACE/intree" || exit 1 | |
136 | ||
137 | tar xvf "$OUTDIR/$TARBALL_FILE" --strip 1 | |
138 | ./configure --prefix="$(mktemp -d)" "${CONF_OPTS[@]}" | |
139 | ||
140 | # BUILD! | |
141 | make -j "$(nproc)" V=1 | |
142 | ||
143 | make install | |
144 | ||
145 | # Run tests, don't fail now, we want to run the archiving steps | |
146 | make --keep-going check || failed_tests=1 | |
147 | ||
148 | # Copy tap logs for the jenkins tap parser before cleaning the build dir | |
149 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR/intree" | |
150 | ||
151 | # Clean the build directory | |
152 | make clean | |
153 | ||
154 | ||
155 | ## Do an out-of-tree test build | |
156 | mkdir "$WORKSPACE/oot" | |
157 | mkdir "$WORKSPACE/oot/src" | |
158 | mkdir "$WORKSPACE/oot/build" | |
159 | cd "$WORKSPACE/oot/src" || exit 1 | |
160 | ||
161 | tar xvf "$OUTDIR/$TARBALL_FILE" --strip 1 | |
162 | cd "$WORKSPACE/oot/build" || exit 1 | |
163 | "$WORKSPACE/oot/src/configure" --prefix="$(mktemp -d)" "${CONF_OPTS[@]}" | |
164 | ||
165 | # BUILD! | |
166 | make -j "$(nproc)" V=1 | |
167 | ||
168 | make install | |
169 | ||
170 | # Run tests, don't fail now, we want to run the archiving steps | |
171 | make --keep-going check || failed_tests=1 | |
172 | ||
173 | # Copy tap logs for the jenkins tap parser before cleaning the build dir | |
174 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR/oot" | |
175 | ||
176 | # Clean the build directory | |
177 | make clean | |
178 | ||
179 | ||
180 | # Exit with failure if any of the tests failed | |
181 | exit $failed_tests | |
182 | ||
183 | # EOF |