system-tests: vm_test trigger kernel version
[lttng-ci.git] / scripts / common / scan-build.sh
... / ...
CommitLineData
1#!/bin/bash -exu
2#
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# Copyright (C) 2019 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
19# Required variables
20WORKSPACE=${WORKSPACE:-}
21
22DEPS_INC="$WORKSPACE/deps/build/include"
23DEPS_LIB="$WORKSPACE/deps/build/lib"
24DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
25DEPS_BIN="$WORKSPACE/deps/build/bin"
26
27export PATH="$DEPS_BIN:$PATH"
28export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
29export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
30export CPPFLAGS="-I$DEPS_INC"
31export LDFLAGS="-L$DEPS_LIB"
32
33SRCDIR="$WORKSPACE/src/$PROJECT_NAME"
34TMPDIR="$WORKSPACE/tmp"
35
36NPROC=$(nproc)
37export CFLAGS="-O0 -g -DDEBUG"
38
39# Directory to archive the scan-build report
40SCAN_BUILD_ARCHIVE="${WORKSPACE}/scan-build-archive"
41
42# Create tmp directory
43rm -rf "$TMPDIR"
44mkdir -p "$TMPDIR"
45
46export TMPDIR
47
48# temp directory to store the scan-build report
49SCAN_BUILD_TMPDIR=$(mktemp -d)
50
51case "$PROJECT_NAME" in
52babeltrace)
53 export BABELTRACE_DEV_MODE=1
54 export BABELTRACE_DEBUG_MODE=1
55 export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
56 CONF_OPTS="--enable-python-bindings --enable-python-bindings-doc --enable-python-plugins"
57 BUILD_TYPE="autotools"
58 ;;
59liburcu)
60 CONF_OPTS=""
61 BUILD_TYPE="autotools"
62 ;;
63lttng-modules)
64 CONF_OPTS=""
65 BUILD_TYPE="autotools"
66 ;;
67lttng-tools)
68 CONF_OPTS=""
69 BUILD_TYPE="autotools"
70 ;;
71lttng-ust)
72 CONF_OPTS="--enable-java-agent-all --enable-python-agent"
73 BUILD_TYPE="autotools"
74 export CLASSPATH="/usr/share/java/log4j-1.2.jar"
75 ;;
76linux-rseq)
77 CONF_OPTS=""
78 BUILD_TYPE="linux-rseq"
79 ;;
80*)
81 echo "Generic project, no configure options."
82 CONF_OPTS=""
83 BUILD_TYPE="autotools"
84 ;;
85esac
86
87if [ -d "$WORKSPACE/src/linux" ]; then
88 export KERNELDIR="$WORKSPACE/src/linux"
89fi
90
91# Enter the source directory
92cd "$SRCDIR"
93
94# Build
95case "$BUILD_TYPE" in
96autotools)
97 # Prepare build dir for autotools based projects
98 if [ -f "./bootstrap" ]; then
99 ./bootstrap
100 ./configure $CONF_OPTS
101 fi
102
103 scan-build -k -o "${SCAN_BUILD_TMPDIR}" make -j"$NPROC" V=1
104 ;;
105linux-rseq)
106 make defconfig
107 make -j"$NPROC" prepare
108 scan-build -k -o "${SCAN_BUILD_TMPDIR}" make -j"$NPROC" kernel/rseq.o kernel/do_on_cpu/core.o kernel/do_on_cpu/interpreter.o kernel/do_on_cpu/validate.o V=1
109 ;;
110*)
111 echo "Unsupported build type: $BUILD_TYPE"
112 exit 1
113 ;;
114esac
115
116
117# get the directory name of the report created by scan-build
118SCAN_BUILD_REPORT=$(find "${SCAN_BUILD_TMPDIR}" -maxdepth 1 -not -empty -not -name "$(basename "${SCAN_BUILD_TMPDIR}")")
119rc=$?
120
121if [ -z "${SCAN_BUILD_REPORT}" ]; then
122 echo ">>> No new bugs identified."
123 echo ">>> No scan-build report has been generated"
124else
125 echo ">>> New scan-build report generated in ${SCAN_BUILD_REPORT}"
126
127 if [ ! -d "${SCAN_BUILD_ARCHIVE}" ]; then
128 echo ">>> Creating scan-build archive directory"
129 mkdir "${SCAN_BUILD_ARCHIVE}"
130 else
131 echo ">>> Removing any previous scan-build reports from ${SCAN_BUILD_ARCHIVE}"
132 rm -f "${SCAN_BUILD_ARCHIVE}/*"
133 fi
134
135 echo ">>> Archiving scan-build report to ${SCAN_BUILD_ARCHIVE}"
136 mv "${SCAN_BUILD_REPORT}"/* "${SCAN_BUILD_ARCHIVE}/"
137
138 echo ">>> Removing any temporary files and directories"
139 rm -rf "${SCAN_BUILD_TMPDIR}"
140fi
141
142exit ${rc}
This page took 0.021563 seconds and 4 git commands to generate.