Python merge use git choosing strategy default
[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 cd /tmp || exit 1
24 wget -O /tmp/sonar-scan.zip \
25     "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip"
26 unzip sonar-scan.zip
27 sudo mv sonar-scanner-* /opt/sonar-scanner
28
29 wget -O /tmp/bw.zip \
30     "https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip"
31 unzip bw.zip
32 sudo mv build-wrapper-* /opt/build-wrapper
33
34 mkdir -p "$build_dir"
35 cd "$build_dir" || exit 1
36 # $cmake_opts needs to wordsplit to pass options.
37 # shellcheck disable=SC2086
38 eval cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts ..
39
40 /opt/build-wrapper/build-wrapper-linux-x86-64 --out-dir "$WORKSPACE/bw-output" \
41     make "$make_opts"
42
43 /opt/sonar-scanner/bin/sonar-scanner \
44     -Dsonar.projectKey="${PROJECT_KEY}" \
45     -Dsonar.organization="${PROJECT_ORGANIZATION}" \
46     -Dsonar.sources=. \
47     -Dsonar.cfamily.build-wrapper-output="$WORKSPACE/bw-output" \
48     -Dsonar.host.url="${SONAR_HOST_URL}" \
49     -Dsonar.login="${API_TOKEN}"