-#! /bin/sh
+#!/usr/bin/env sh
-# Run SonarQube on travis. First version was given per email by one of the SonarQube engineer.
+# Install and run SonarQube on travis.
+#
+# Use it as a wrapper to your build command, eg: ./travis-sonarqube.sh make VERBOSE=1
+# On Mac OSX or with pull requests, you don't want to run SonarQube but to exec the build command directly.
+
+# Be verbose and fail fast
set -ex
# Install required software
installSonarQubeScanner() {
- export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-2.6
+ export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-2.8
rm -rf $SONAR_SCANNER_HOME
mkdir -p $SONAR_SCANNER_HOME
- curl -sSLo $HOME/.sonar/sonar-scanner.zip http://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/2.6/sonar-scanner-cli-2.6.zip
+ curl -sSLo $HOME/.sonar/sonar-scanner.zip http://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/2.8/sonar-scanner-cli-2.8.zip
unzip $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
rm $HOME/.sonar/sonar-scanner.zip
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"
}
installBuildWrapper() {
- curl -LsS https://nemo.sonarqube.org/static/cpp/build-wrapper-linux-x86.zip > build-wrapper-linux-x86.zip
+ curl -LsS https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip > build-wrapper-linux-x86.zip
unzip build-wrapper-linux-x86.zip
}
installSonarQubeScanner
installBuildWrapper
# triggers the compilation through the build wrapper to gather compilation database
-# We need to clean the build that was used for the tests before to ensure that everything gets rebuilt (sonarqube only use what's built throught its wrappers)
-# Plus, we need to activate MC so that it does not get throught the quality net :)
-./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs make VERBOSE=1
+./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs "$@"
+
+# Run ctest before sonar to gather coverage some information
+set +e
+ctest --output-on-failure
+outcome=$?
+set -e
+
+# Only run sonar on master (not on pull requests)
+if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
+ exit $outcome
+fi
+
+# generate the gcov files
+ctest -D ExperimentalCoverage
+
+# and finally execute the actual SonarQube analysis
+# (the SONAR_TOKEN is set from the travis web interface, to not expose it with an ongoing "set -x")
+# See https://docs.travis-ci.com/user/sonarqube/ for more info on tokens
+# don't show the token in the logs
+set +x
+sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN 2>&1 \
+ | grep -v 'INFO: Parsing /home/travis/build/simgrid/simgrid/Testing/CoverageInfo' \
+ | grep -v 'WARN: File not analysed by Sonar, so ignoring coverage: /usr/include/'
-# and finally execute the actual SonarQube analysis (the SONAR_TOKEN is set from the travis web interface, to not expose it)
-sonar-scanner -Dsonar.host.url=https://nemo.sonarqube.org -Dsonar.login=$SONAR_TOKEN
+exit $outcome