Skip to content

Commit f66b326

Browse files
committed
ci: better SonarCloud reporting
* create compile_commands.json * upload coverage from xcrun(llvm-cov)
1 parent d37850c commit f66b326

4 files changed

Lines changed: 78 additions & 10 deletions

File tree

.github/workflows/analysis.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@ jobs:
1313
- uses: mobiledevops/xcode-select-version-action@v1
1414
with:
1515
xcode-select-version: "15.1"
16+
- uses: ConorMacBride/install-package@v1.1.0
17+
with:
18+
brew: ninja
1619
- uses: SonarSource/sonarcloud-github-c-cpp@v2
1720

1821
- name: "Run setup-metal-cpp.ps1"
1922
run: ./setup-metal-cpp.ps1
2023
shell: pwsh
2124

25+
- uses: lukka/run-vcpkg@v11.4
26+
with:
27+
vcpkgDirectory: "/usr/local/share/vcpkg" # $VCPKG_INSTALLATION_ROOT
28+
vcpkgGitCommitId: c8696863d371ab7f46e213d8f5ca923c4aef2a00 # 2023.12.12
29+
vcpkgJsonGlob: "${{ github.workspace }}/vcpkg.json"
30+
runVcpkgInstall: true
31+
- uses: lukka/run-cmake@v10.7
32+
with:
33+
configurePreset: "x64-osx-analysis"
34+
- name: Run build-wrapper
35+
run: |
36+
build-wrapper-macosx-x86 --out-dir bw-output cmake --build --preset x64-osx-analysis
37+
2238
- name: "Run xcodebuild(build)"
2339
run: |
2440
xcodebuild -workspace . -list
@@ -48,16 +64,26 @@ jobs:
4864
echo "path=$xcresult_path" >> "$GITHUB_OUTPUT"
4965
bash ./scripts/xccov-to-sonarqube-generic.sh $xcresult_path > docs/coverage.xml
5066
shell: bash
51-
67+
5268
- uses: kishikawakatsumi/xcresulttool@v1.7.1
5369
with:
5470
path: "${{ steps.xcresult.outputs.path }}"
5571

72+
- name: "Run xcrun(llvm-cov)"
73+
run: |
74+
profdata_path=$(find "DerivedData/Build/ProfileData" -name "Coverage.profdata" | tail -n 1)
75+
xctest_path="DerivedData/Build/Products/Debug/BaguetteBridgeTests.xctest/Contents/MacOS/BaguetteBridgeTests"
76+
xcrun --run llvm-cov show -instr-profile=$profdata_path $xctest_path > docs/coverage.report
77+
shell: bash
78+
5679
- name: "Run sonar-scanner"
5780
run: |
5881
sonar-scanner \
5982
--define sonar.links.ci=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \
60-
--define sonar.coverageReportPaths=docs/coverage.xml
83+
--define sonar.cfamily.llvm-cov.reportPath=docs/coverage.report
84+
# --define sonar.swift.coverage.reportPaths=docs/coverage.report
85+
# --define sonar.coverageReportPaths=docs/coverage.xml
86+
# --define sonar.cfamily.build-wrapper-output="${{ github.workspace }}/bw-output"
6187
env:
6288
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6389
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ include(GNUInstallDirs)
66
set(CMAKE_CXX_STANDARD 20)
77

88
if(APPLE)
9-
set(CMAKE_Swift_LANGUAGE_VERSION 5.9)
10-
find_program(CMAKE_Swift_COMPILER NAMES swiftc swift-frontend REQUIRED)
9+
set(CMAKE_Swift_LANGUAGE_VERSION 5)
10+
find_program(CMAKE_Swift_COMPILER NAMES swiftc REQUIRED)
1111
enable_language(Swift)
1212
# set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
1313
# if(ENABLE_COVERAGE)
@@ -94,6 +94,11 @@ PRIVATE
9494

9595
install(TARGETS BaguetteBridge FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
9696

97+
if(NOT BUILD_TESTING)
98+
return()
99+
endif()
100+
enable_testing()
101+
97102
add_executable(baguette_test
98103
test/baguette_test.cpp
99104
)
@@ -116,5 +121,4 @@ PRIVATE
116121

117122
install(TARGETS baguette_test RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
118123

119-
enable_testing()
120124
add_test(NAME run_baguette_test COMMAND baguette_test WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

CMakePresets.json

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@
66
"patch": 0
77
},
88
"configurePresets": [
9+
{
10+
"name": "vcpkg-find",
11+
"hidden": true,
12+
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
13+
"environment": {
14+
"VCPKG_FEATURE_FLAGS": "manifests",
15+
"VCPKG_INSTALLED_DIR": "${sourceDir}/externals"
16+
},
17+
"debug": {
18+
"find": true
19+
}
20+
},
921
{
1022
"name": "x64-osx",
11-
"displayName": "x64-osx",
23+
"inherits": [
24+
"vcpkg-find"
25+
],
1226
"generator": "Xcode",
1327
"binaryDir": "${sourceDir}/build-x64-osx",
1428
"installDir": "${sourceDir}/install",
15-
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
1629
"cacheVariables": {
30+
"BUILD_TESTING": true,
1731
"BUILD_SHARED_LIBS": false,
1832
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
1933
"CMAKE_OSX_DEPLOYMENT_TARGET": "12.0",
@@ -26,6 +40,27 @@
2640
"rhs": "Darwin"
2741
}
2842
},
43+
{
44+
"name": "x64-osx-analysis",
45+
"inherits": [
46+
"vcpkg-find"
47+
],
48+
"generator": "Ninja",
49+
"binaryDir": "${sourceDir}/build-x64-analysis",
50+
"installDir": "${sourceDir}/install",
51+
"cacheVariables": {
52+
"BUILD_TESTING": false,
53+
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
54+
"CMAKE_BUILD_TYPE": "Debug",
55+
"CMAKE_OSX_ARCHITECTURES": "x86_64",
56+
"VCPKG_TARGET_TRIPLET": "x64-osx"
57+
},
58+
"condition": {
59+
"type": "equals",
60+
"lhs": "${hostSystemName}",
61+
"rhs": "Darwin"
62+
}
63+
},
2964
{
3065
"name": "arm64-ios",
3166
"displayName": "arm64-ios",
@@ -51,6 +86,11 @@
5186
"configurePreset": "x64-osx",
5287
"configuration": "Debug"
5388
},
89+
{
90+
"name": "x64-osx-analysis",
91+
"configurePreset": "x64-osx-analysis",
92+
"configuration": "Debug"
93+
},
5494
{
5595
"name": "arm64-ios-debug",
5696
"configurePreset": "arm64-ios",

sonar-project.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ sonar.sources=src,platform-apple
1212
sonar.test=test
1313
sonar.exclusions=externals
1414

15-
# temporary disable C++ ...
16-
# sonar.cfamily.compile-commands=
17-
sonar.cpp.file.suffixes=-
15+
sonar.cfamily.compile-commands=build-x64-analysis/compile_commands.json

0 commit comments

Comments
 (0)