jjb: binutils-gdb: disable ASan leaks reporting during "make check"
[lttng-ci.git] / scripts / binutils-gdb / build.sh
CommitLineData
91ba8aa1
MJ
1#!/bin/bash
2#
3# Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18set -exu
19
20failed_configure() {
21 # Assume we are in the configured build directory
22 echo "#################### BEGIN config.log ####################"
23 cat config.log
24 echo "#################### END config.log ####################"
25 exit 1
26}
27
28sum2junit() {
29 local infile="$1"
30 local outfile="$2"
31
32 local tool
33 local skipped
34 local passes
35 local failures
36 local total
37 local s2jtmpfile
38
39 local result
40 local name
41 local message
42
43 set +x
44
45 tool=$(grep "tests ===" "$infile" | tr -s ' ' | cut -d ' ' -f 2)
46
47 # Get the counts for tests that didn't work properly
48 skipped=$(grep -E -c '^UNRESOLVED|^UNTESTED|^UNSUPPORTED' "$infile" || true)
49 if test x"${skipped}" = x; then
50 skipped=0
51 fi
52
53 # The total of successful results are PASS and XFAIL
54 passes=$(grep -E -c '^PASS|XFAIL' "$infile" || true)
55 if test x"${passes}" = x; then
56 passes=0
57 fi
58
59 # The total of failed results are FAIL and XPASS
60 failures=$(grep -E -c '^FAIL|XPASS' "$infile" || true)
61 if test x"${failures}" = x; then
62 failures=0
63 fi
64
65 # Calculate the total number of test cases
66 total=$((passes + failures))
67 total=$((total + skipped))
68
69 cat <<EOF > "$outfile"
70<?xml version="1.0"?>
71
72<testsuites>
73<testsuite name="DejaGnu" tests="${total}" failures="${failures}" skipped="${skipped}">
74
75EOF
76
77 s2jtmpfile="$(mktemp)"
78 grep -E 'PASS|XPASS|FAIL|UNTESTED|UNSUPPORTED|UNRESOLVED' "$infile" > "$s2jtmpfile" || true
79
80 while read -r line
81 do
82 echo -n "."
83 result=$(echo "$line" | cut -d ' ' -f 1 | tr -d ':')
84 name=$(echo "$line" | cut -d ' ' -f 2 | tr -d '\"><;:\[\]^\\&?@')
85 message=$(echo "$line" | cut -d ' ' -f 3-50 | tr -d '\"><;:\[\]^\\&?@')
86
87 echo " <testcase name=\"${name}\" classname=\"${tool}-${result}\">" >> "$outfile"
88 case "${result}" in
89 PASS|XFAIL|KFAIL)
90 # No message for successful tests in junit
91 ;;
92 UNSUPPORTED|UNTESTED)
93 if test x"${message}" != x; then
94 echo -n " <skipped message=\"${message}\"/>" >> "$outfile"
95 else
96 echo -n " <skipped type=\"$result\"/>" >> "$outfile"
97 fi
98 ;;
99 XPASS|UNRESOLVED|DUPLICATE)
100 echo -n " <failure message=\"$message\"/>" >> "$outfile"
101 ;;
102 *)
103 echo -n " <failure message=\"$message\"/>" >> "$outfile"
104 esac
105
106 echo " </testcase>" >> "$outfile"
107 done < "$s2jtmpfile"
108
109 rm -f "$s2jtmpfile"
110
111 # Write the closing tag for the test results
112 echo "</testsuite>" >> "$outfile"
113 echo "</testsuites>" >> "$outfile"
114
115 set -x
116}
117
118# Required variables
119WORKSPACE=${WORKSPACE:-}
120
121arch=${arch:-}
122conf=${conf:-}
123build=${build:-}
124cc=${cc:-}
125
126
127SRCDIR="$WORKSPACE/src/binutils-gdb"
128TMPDIR="$WORKSPACE/tmp"
129PREFIX="/build"
130
131# Create tmp directory
132rm -rf "$TMPDIR"
133mkdir -p "$TMPDIR"
134
135export TMPDIR
136export CFLAGS="-O2 -fsanitize=address"
137export CXXFLAGS="-O2 -fsanitize=address -D_GLIBCXX_DEBUG=1"
138export LDFLAGS="-fsanitize=address"
139
140# Set platform variables
141case "$arch" in
142*)
143 export MAKE=make
144 export TAR=tar
145 export NPROC=nproc
146 ;;
147esac
148
149# Print build env details
150print_os || true
151print_tooling || true
152
153# Enter the source directory
154cd "$SRCDIR"
155
156# Run bootstrap in the source directory prior to configure
157#./bootstrap
158
159# Get source version from configure script
160#eval "$(grep '^PACKAGE_VERSION=' ./configure)"
161#PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
162
163# Set configure options and environment variables for each build
164# configuration.
165CONF_OPTS=("--prefix=$PREFIX")
166
167case "$conf" in
168*)
169 echo "Standard configuration"
170
171 # Use system tools
172 CONF_OPTS+=("--disable-binutils" "--disable-ld" "--disable-gold" "--disable-gas" "--disable-sim" "--disable-gprof")
173
174 # Use system libs
175 CONF_OPTS+=("--with-system-readline" "--with-system-zlib")
176
177 # Enable optional features
178 CONF_OPTS+=("--enable-targets=all" "--with-expat=yes" "--with-python=python3" "--with-guile=guile-2.2" "--enable-libctf")
179
180 CONF_OPTS+=("--enable-build-warnings" "--enable-gdb-build-warnings" "--enable-unit-tests")
181
182 ;;
183esac
184
185# Build type
186# oot : out-of-tree build
187# dist : build via make dist
188# oot-dist: build via make dist out-of-tree
189# * : normal tree build
190#
191# Make sure to move to the build directory and run configure
192# before continuing.
193case "$build" in
194*)
195 echo "Out of tree build"
196
197 # Create and enter a temporary build directory
198 builddir=$(mktemp -d)
199 cd "$builddir"
200
201 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
202 ;;
203esac
204
205# We are now inside a configured build directory
206
207# BUILD!
208$MAKE -j "$($NPROC)" V=1 MAKEINFO=/bin/true
209
210# Install in the workspace
211$MAKE install DESTDIR="$WORKSPACE"
212
213# Run tests, don't fail now, we want to run the archiving steps
adb01414
SM
214#
215# Disable ASan leaks reporting, it might break some tests since it adds
216# unexpected output when GDB exits.
91ba8aa1 217failed_tests=0
adb01414 218ASAN_OPTIONS=detect_leaks=0 $MAKE -C gdb --keep-going check -j "$($NPROC)" || failed_tests=1
91ba8aa1
MJ
219
220# Copy the dejagnu test results for archiving before cleaning the build dir
221mkdir "${WORKSPACE}/results"
f5dbc8e5 222cp gdb/testsuite/gdb.log "${WORKSPACE}/results/"
91ba8aa1
MJ
223cp gdb/testsuite/gdb.sum "${WORKSPACE}/results/"
224sum2junit gdb/testsuite/gdb.sum "${WORKSPACE}/results/gdb.xml"
225
226# Clean the build directory
227$MAKE clean
228
229# Cleanup rpath in executables and shared libraries
230#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
231#find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
232
233# Remove libtool .la files
234find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
235
236# Exit with failure if any of the tests failed
237exit $failed_tests
238
239# EOF
This page took 0.065621 seconds and 4 git commands to generate.