Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / autotools-sonarqube.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2020 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # Invokes configure and make with the specified options,
13 # using a wrapper for the SonarQube Jenkins plug-in
14 # https://docs.sonarqube.org/latest/analysis/languages/cfamily/
15 # Prereqs:
16 # The build minion has make, gcc etc.
17 # The project repo has an executable shell script "configure"
18 # Environment variables:
19 # WORKSPACE is a non-empty path (required)
20 # INSTALL_PREFIX is a non-empty path (required)
21 # CONFIGURE_OPTS has options for configure (optional, empty default)
22 # MAKE_OPTS has options for make (optional, empty default)
23 # BUILD_WRAP_DIR is a path (optional, this provides a usable default)
24
25 echo "---> autotools-sonarqube.sh"
26
27 # be careful and verbose
28 set -eux -o pipefail
29
30 c="$WORKSPACE/configure"
31 if [[ ! -f $c || ! -x $c ]]; then
32     echo "ERROR: failed to find executable file $c"
33     exit 1
34 fi
35
36 configure_opts="${CONFIGURE_OPTS:-}"
37 make_opts="${MAKE_OPTS:-}"
38 build_wrap_dir="${BUILD_WRAP_DIR:-$WORKSPACE/bw-output}"
39
40 # download and install the Sonar build wrapper
41 bw=bw.zip
42 wget -q -O "$bw" https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
43 unzip -q "$bw"
44 sudo mv build-wrapper-* /opt/build-wrapper
45 rm -f "$bw"
46
47 # use eval to disable bash quoting behavior;
48 # e.g., if configure-opts=CXXFLAGS="-O0 --coverage"
49 # configure needs to wordsplit to pass options
50 # shellcheck disable=SC2086
51 eval $c --prefix="$INSTALL_PREFIX" $configure_opts
52
53 # to analyze coverage, make must run tests and run gcov
54 # to process .gcno/.gcda files into .gcov files.
55 # use eval to disable bash quoting behavior
56 # $make_opts may be empty
57 # make needs to wordsplit to pass options
58 # shellcheck disable=SC2086
59 eval /opt/build-wrapper/build-wrapper-linux-x86-64 --out-dir \
60     "$build_wrap_dir" make $make_opts
61
62 echo "---> autotools-sonarqube.sh ends"