I have CI running on Drone.io with macOS agents attached to it.
Made script to do scanning, see below. But thing is that script running fine on local machine and reporting code coverage, but not on Drone.io agent, always gets 0 code coverage. I think it has some specific with user and it has broken access to some local directories, so I added SONAR_USER_HOME. Is there anything else I need to define/add if user don’t have user folder or permissions to some defaul dirs?
#!/bin/bash
THIS_PWD=`pwd`
export SONAR_USER_HOME=$THIS_PWD
PATH=$PATH:/bin/local/bin:/usr/bin:/bin
PATH="/usr/local/opt/openjdk/bin:$PATH"
echo "Install SonarQube dependencies"
if ! command -v sonar-scanner &> /dev/null
then
brew install sonar-scanner openjdk
fi
THIS_PWD=`pwd`
## note this have to be run once on runner because app not codesign.
if ! [[ -d build-wrapper-macosx-x86 ]]; then
curl -L https://__sonar_qube_websie___/static/cpp/build-wrapper-macosx-x86.zip --output build-wrapper-macosx-x86.zip
unzip build-wrapper-macosx-x86.zip -d .
fi
export LLVM_PROFILE_FILE="code-%p.profraw"
# Build project
./build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir ../../build_wrapper_output_directory xcodebuild clean build -quiet \
-workspace "Project.xcworkspace" \
-scheme "AppName" \
-derivedDataPath "DerivedData" \
GCC_PREPROCESSOR_DEFINITIONS=$GCC_PREPROCESSOR_DEFINITIONS \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO
DerivedData/Build/Products/Debug/AppName --gtest_output="xml:../results/report.xml"
echo "Generate coverage report"
xcrun llvm-profdata merge -output=code.profdata code-*.profraw
xcrun llvm-cov show DerivedData/Build/Products/Debug/AppName -instr-profile=code.profdata $THIS_PWD/include/* $THIS_PWD/src/* > coverage.txt
cd ../..
branch=$(git symbolic-ref --short HEAD)
sonar-scanner -Dproject.settings=.sonar-project.properties \
-Dsonar.cfamily.llvm-cov.reportPath="$THIS_PWD/coverage.txt" \
-Dsonar.login=$SONAR_LOGIN
SonarQube Version 7.9.1
Scanner 4.5 installed from homebrew on macOS
would you be able to share coverage.txt and the output of the scanner in verbose mode by specifying sonar.verbose=true? I can send you a PM if you want to share privately.
Thanks
Now I realised that produced code coverage is 15Mb file. And I can see in logs that sonar-scanner fails to process it.
coverage.txt less then 1Mb on my local machine.
@mpaladin problem with llvm-cov and location where drone.io by default executing builds.
I moved drone root directory to user folder and getting normal coverage.txt as on local machine.
Hi @mpaladin,
by moving to user’s documents directory it did solve problem with llvm-cov, but I got problems with other CI integration setups. MacOS security has this thing that requires user to accept access to Documents directory, which is blocking launch of testing application… So, I’m at begging again. Probably going to go and see what llvm developers can suggest, gonna file issue there