Fix: Activate the virtual environment
[releng/global-jjb.git] / shell / cmake-sonar.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 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 echo "---> cmake-sonar.sh"
12
13 build_dir="${BUILD_DIR:-$WORKSPACE/target}"
14 cmake_opts="${CMAKE_OPTS:-}"
15 make_opts="${MAKE_OPTS:-}"
16
17 ################
18 # Script start #
19 ################
20
21 set -ex -o pipefail
22
23 export SET_JDK_VERSION="${SET_JDK_VERSION:-openjdk11}"
24 echo "$SET_JDK_VERSION"
25 bash <(curl -s https://raw.githubusercontent.com/lfit/releng-global-jjb/master/shell/update-java-alternatives.sh)
26 # shellcheck disable=SC1091
27 source /tmp/java.env
28
29 cd /tmp || exit 1
30 wget -q -O /tmp/sonar-scan.zip \
31     "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip"
32 unzip -q sonar-scan.zip
33 sudo mv sonar-scanner-* /opt/sonar-scanner
34
35 wget -q -O /tmp/bw.zip \
36     "https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip"
37 unzip -q bw.zip
38 sudo mv build-wrapper-* /opt/build-wrapper
39
40 mkdir -p "$build_dir"
41 cd "$build_dir" || exit 1
42 # $cmake_opts needs to wordsplit to pass options.
43 # shellcheck disable=SC2086
44 eval cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts ..
45
46 # $make_opts may be empty.
47 # shellcheck disable=SC2086
48 /opt/build-wrapper/build-wrapper-linux-x86-64 --out-dir "$WORKSPACE/bw-output" \
49     make $make_opts
50
51 /opt/sonar-scanner/bin/sonar-scanner \
52     -Dsonar.projectKey="${PROJECT_KEY}" \
53     -Dsonar.organization="${PROJECT_ORGANIZATION}" \
54     -Dsonar.sources=. \
55     -Dsonar.cfamily.build-wrapper-output="$WORKSPACE/bw-output" \
56     -Dsonar.host.url="${SONAR_HOST_URL}" \
57     -Dsonar.login="${API_TOKEN}"