valentina/scripts/sonar-scanner.sh

60 lines
1.6 KiB
Bash
Raw Normal View History

2024-02-05 13:46:30 +01:00
#!/bin/sh
# Analyze project with Sonar cloud on Linux.
2024-02-16 15:39:07 +01:00
# Please, run this script from <root_folder>.
2024-02-05 13:46:30 +01:00
set -x
BUILD_FOLDER=build_sonar
cd ..
rm -rf ../${BUILD_FOLDER}
mkdir ../${BUILD_FOLDER}
QMAKE_PATH=${HOME}/Qt6.6/6.6.0/gcc_64/bin/qmake
PROFILE=qt6Sonar
2024-02-16 15:39:07 +01:00
COMPILER=gcc-12
GCOV=gcov-12
2024-02-05 13:46:30 +01:00
qbs setup-toolchains /usr/bin/${COMPILER} ${COMPILER}
qbs setup-qt ${QMAKE_PATH} ${PROFILE}
qbs config profiles.${PROFILE}.baseProfile ${COMPILER}
qbs config defaultProfile ${PROFILE}
qbs config --list profiles
build-wrapper-linux-x86-64 \
--out-dir bw-output \
qbs build \
--no-install \
-d ../${BUILD_FOLDER} \
-f valentina.qbs \
--jobs $(nproc) \
profile:${PROFILE} \
2024-02-16 15:39:07 +01:00
config:debug \
modules.buildconfig.enableCcache:false \
modules.buildconfig.enableTestCoverage:true
2024-02-05 13:46:30 +01:00
# modules.cpp.linkerVariant:mold
2024-02-16 15:39:07 +01:00
# Run tests to generate coverage information
qbs -p autotest-runner -d ../${BUILD_FOLDER} profile:qt6 config:release
# Run gcov to translate `.gcda` files into `.gcov` readable by humans and SonarCloud
mkdir ../${BUILD_FOLDER}/coverage-dir
current_dir=$(pwd)
cd ../${BUILD_FOLDER}/coverage-dir
# --preserve-paths helps us avoid name clash for `.gcov` files corresponding to source files
# with the same name but in different directories.
find .. -name '*.o' | xargs ${GCOV} --preserve-paths
cd "$current_dir"
2024-02-05 13:46:30 +01:00
current_branch=$(git rev-parse --abbrev-ref HEAD)
current_revision=$(git rev-parse HEAD)
sonar-scanner \
-Dsonar.branch.name=$current_branch \
2024-02-16 15:39:07 +01:00
-Dsonar.scm.revision=$current_revision \
-Dsonar.cfamily.gcov.reportsPath="../${BUILD_FOLDER}/coverage-dir"