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