Skip to content

Commit

Permalink
chore: refine coverage support
Browse files Browse the repository at this point in the history
Signed-off-by: msclock <msclock@qq.com>
  • Loading branch information
msclock committed Mar 12, 2024
1 parent 36c43d8 commit 4c00330
Show file tree
Hide file tree
Showing 113 changed files with 2,029 additions and 891 deletions.
57 changes: 46 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ jobs:
fail-fast: false
matrix:
presets:
- {os: {name: ubuntu-latest, type: linux}, compiler: {name: gcc, type: gcc}}
- {os: {name: ubuntu-latest, type: linux}, compiler: {name: llvm, type: clang}}
- {os: {name: macos-latest, type: osx}, compiler: {name: gcc, type: gcc}}
- {os: {name: macos-latest, type: osx}, compiler: {name: llvm, type: clang}}
- {os: {name: ubuntu-latest, type: linux}, compiler: {name: gcc-11, type: gcc}}
- {os: {name: ubuntu-latest, type: linux}, compiler: {name: llvm, type: llvm}}
- {os: {name: ubuntu-latest, type: mingw-dynamic-linux}, compiler: {name: mingw, type: mingw}}
- {os: {name: macos-latest, type: osx}, compiler: {name: applellvm, type: llvm}}
- {os: {name: macos-latest, type: osx}, compiler: {name: llvm, type: llvm}}
# setup-cpp doesn't support mingw on macOS yet
# - {os: {name: macos-latest, type: mingw-dynamic-darwin}, compiler: {name: mingw, type: mingw}}
- {os: {name: windows-latest, type: windows}, compiler: {name: msvc, type: msvc}}
- {os: {name: windows-latest, type: windows}, compiler: {name: llvm, type: llvm}}
- {os: {name: windows-latest, type: mingw-dynamic-windows}, compiler: {name: mingw, type: mingw-gcc}}
arch:
- {name: x64, type: x64}
vcpkg:
Expand All @@ -100,6 +105,22 @@ jobs:
with:
fetch-depth: 0

- name: Cache
uses: actions/cache@v4
with:
path: |
~/vcpkg
./build/vcpkg_installed
~/.cache/pip
${{ env.HOME }}/.cache/vcpkg/archives
${{ env.XDG_CACHE_HOME }}/vcpkg/archives
${{ env.LOCALAPPDATA }}\vcpkg\archives
${{ env.APPDATA }}\vcpkg\archives
key: |
${{ matrix.arch.name }}-${{ matrix.presets.os.name }}-${{ matrix.presets.compiler.name }}-${{ matrix.vcpkg }}-${{ hashFiles('./vcpkg.json') }}
restore-keys: |
${{ matrix.arch.name }}-${{ matrix.presets.os.name }}-${{ matrix.presets.compiler.name }}-${{ matrix.vcpkg }}-${{ hashFiles('./vcpkg.json') }}
- uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.presets.compiler.name }}
Expand All @@ -108,20 +129,34 @@ jobs:
ninja: true
vcpkg: ${{ matrix.vcpkg }}
ccache: true
doxygen: true
graphviz: true
python: true
gcovr: true
opencppcoverage: true

- name: Install Python dependencies
- name: Gcc Lcov
if: contains(matrix.presets.compiler.type, 'gcc') && contains(matrix.presets.os.type, 'linux')
run: |
sudo apt-get update
sudo apt-get install lcov
- name: Gcovr
if: contains(matrix.presets.compiler.type, 'mingw') && contains(matrix.presets.os.type, 'mingw')
run: |
python -m pip install --upgrade pip
pip install -r docs/requirements.txt
pip install gcovr
- name: Target Windows on Linux (Mingw-w64)
if: contains(matrix.presets.compiler.type, 'mingw') && contains(matrix.presets.os.type, 'linux')
run: |
sudo apt-get update && sudo apt-get install mingw-w64 wine wine64 powershell
sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
wine64 true || true
echo "wait 10s for wine registry to be created" && sleep 10
sed -i '/"PATH"/ s|"$|;Z:/usr/lib/gcc/x86_64-w64-mingw32/10-posix;Z:/usr/x86_64-w64-mingw32/lib"|g' ~/.wine/system.reg && echo "wine registry updated"
- name: Configure CMake
run: |
cmake -S . --preset=${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON -DBUILD_TESTING=ON
cmake -S . --preset=${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON -DBUILD_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=TRUE
- name: Coverage
run: |
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
compiler: gcc
cmake: true
ninja: true
vcpkg: true
ccache: true
doxygen: true
graphviz: true
Expand All @@ -40,12 +39,10 @@ jobs:
pip install -r docs/requirements.txt
- name: Configure
env:
VCPKG_ROOT: /home/runner/vcpkg
run: cmake -S . --preset=x64-Debug-GNUC -DBUILD_TESTING=OFF -DCODE_COVERAGE=OFF
run: cmake -S . --preset=x64-linux-gcc -DBUILD_TESTING=OFF -DCODE_COVERAGE=OFF

- name: Build Docs
run: cmake --build out/build/x64-Debug-GNUC --target ss-cpp-docs
run: cmake --build out/build/x64-linux-gcc --target ss-cpp-docs

- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
Expand Down
31 changes: 0 additions & 31 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,6 @@
"environment": [],
"console": "integratedTerminal"
},
{
"name": "(gdb) Launch jni",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": ".",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
// jvm handle sigsegv self, see
// https://medium.com/@pirogov.alexey/gdb-debug-native-part-of-java-application-c-c-libraries-and-jdk-6593af3b4f3f
"description": "Disable segfaults from jvm",
"text": "handle SIGSEGV nostop noprint pass",
"ignoreFailures": true,
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cmake.useCMakePresets": "always",
"cmake.options.statusBarVisibility": "visible",
"cmake.options.statusBarVisibility": "icon",
"files.exclude": {
"**/.clangd/**": true
},
Expand Down Expand Up @@ -97,6 +97,8 @@
"cwctype": "cpp",
"memory_resource": "cpp",
"numbers": "cpp",
"semaphore": "cpp"
"semaphore": "cpp",
"codecvt": "cpp",
"source_location": "cpp"
}
}
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.25)
message(STATUS "CMAKE VERSION:${CMAKE_VERSION}")

# Project settings
Expand Down Expand Up @@ -28,8 +28,8 @@ include(cmake-modules/test/Default)
include(cmake-modules/test/GoogleTest)
include(cmake-modules/test/Sanitizer)
include(cmake-modules/test/Valgrind)
include(cmake-modules/install/Common)
include(cmake-modules/install/Default)
include(cmake-modules/install/Common)
include(cmake-modules/install/InstallDependency)
include(cmake-modules/install/Runpath)

Expand All @@ -44,9 +44,6 @@ include(ConfigureVersion)
include(ConfigureDocs)
include(ConfigureCoverage)

# Package dependencies using find_package
find_package(absl CONFIG REQUIRED)

add_subdirectory(src)

# Print project final information
Expand Down
12 changes: 8 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"patch": 0
},
"include": [
"cmake/presets/x64-windows-msvc.json",
"cmake/presets/x64-linux-clang.json",
"cmake/presets/x64-linux-llvm.json",
"cmake/presets/x64-linux-gcc.json",
"cmake/presets/x64-osx-clang.json",
"cmake/presets/x64-osx-gcc.json"
"cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json",
"cmake/presets/x64-mingw-dynamic-darwin-mingw.json",
"cmake/presets/x64-mingw-dynamic-linux-mingw.json",
"cmake/presets/x64-osx-gcc.json",
"cmake/presets/x64-osx-llvm.json",
"cmake/presets/x64-windows-llvm.json",
"cmake/presets/x64-windows-msvc.json"
]
}
27 changes: 23 additions & 4 deletions cmake/ConfigureCoverage.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
#[[
This file is used to configure code coverage for all targets in the project.

It supports detecting and using the following coverage tools:
- gcov (GNU gcov)
- llvm-cov (LLVM's llvm-cov)
- lcov (GNU lcov)
- opencppcoverage (OpenCppCoverage)

]]

include_guard(GLOBAL)

# cmake-format: off
include(cmake-modules/test/Coverage)
list(APPEND _excludes "${CMAKE_BINARY_DIR}" "${VCPKG_INSTALLED_DIR}")

if(UNIX)
list(APPEND _excludes "/usr" "/usr/local" "/opt" "/opt/local")
endif()

add_code_coverage_all_targets(
EXCLUDE_DIRS
"${VCPKG_INSTALLED_DIR}"
"${CMAKE_BINARY_DIR}"
"/usr"
EXCLUDE_DIRS ${_excludes}
INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src")
unset(_exclude_dirs)
unset(_excludes)

# cmake-format: on
10 changes: 6 additions & 4 deletions cmake/ConfigureDocs.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Build the target by issuing: cmake --build . --target
# ${CMAKE_PROJECT_NAME}-docs
#[[
This file creates targets to generate documentation:

- Doxygen: ${CMAKE_PROJECT_NAME}-doxygen
- Sphinx: ${CMAKE_PROJECT_NAME}-docs
]]

include(cmake-modules/configure/ConfigDoxygen)
configdoxygen()

if(DOXYGEN_FOUND)

# Generate XML OUTPUT for breathe
set(DOXYGEN_GENERATE_HTML NO)
set(DOXYGEN_GENERATE_XML YES)
Expand Down Expand Up @@ -43,5 +46,4 @@ if(DOXYGEN_FOUND)
OUTPUT_DIRECTORY
${CMAKE_SOURCE_DIR}/docs/_build/html)
endif()

endif()
8 changes: 8 additions & 0 deletions cmake/ConfigureVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#[[
This file configures the version of the project based on the git commit.

It creates a header file ${CMAKE_BINARY_DIR}/git/include with the version
information, which can be included in the project.

]]

include_guard(GLOBAL)
include(cmake-modules/configure/GitTools)

Expand Down
10 changes: 10 additions & 0 deletions cmake/build_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SS-CPP Build Congfiguration

## Triplets = {Architecture}-{Target-Compiling-OS/Toolchain}-{Distribution}

- Architecture: x86, x64, arm, arm64, ppc64le, s390x, wasm32, etc.
- Target-Compiling-OS/Toolchain: windows, linux, macos, freebsd, android, ios, mingw, etc.
- Distribution: dynamic, static, release, etc.
- Compiler(Optional): MSVC, GCC, Clang, MinGW

More about triplets, see: <https://learn.microsoft.com/en-us/vcpkg/users/triplets>
5 changes: 4 additions & 1 deletion cmake/presets/arch/x64.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"value": "host=x64",
"strategy": "external"
},
"hidden": true
"hidden": true,
"cacheVariables": {
"VCPKG_TARGET_ARCHITECTURE": "x64"
}
}
]
}
1 change: 1 addition & 0 deletions cmake/presets/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"vcpkg"
],
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_COMPILE_WARNING_AS_ERROR": true,
Expand Down
21 changes: 21 additions & 0 deletions cmake/presets/compilers/llvm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 6,
"configurePresets": [
{
"name": "llvm",
"hidden": true,
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"name": "llvm-cl",
"hidden": true,
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
}
}
]
}
9 changes: 9 additions & 0 deletions cmake/presets/compilers/mingw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 6,
"configurePresets": [
{
"name": "mingw",
"hidden": true
}
]
}
3 changes: 2 additions & 1 deletion cmake/presets/triplets/x64-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"x64"
],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-linux"
"VCPKG_TARGET_TRIPLET": "x64-linux",
"VCPKG_HOST_TRIPLET": "x64-linux"
}
}
]
Expand Down
20 changes: 20 additions & 0 deletions cmake/presets/triplets/x64-mingw-dynamic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 6,
"include": [
"../arch/x64.json"
],
"configurePresets": [
{
"name": "x64-mingw-dynamic",
"hidden": true,
"inherits": [
"x64"
],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic",
"VCPKG_HOST_TRIPLET": "x64-mingw-dynamic",
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/vcpkg/scripts/toolchains/mingw.cmake"
}
}
]
}
3 changes: 2 additions & 1 deletion cmake/presets/triplets/x64-osx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"x64"
],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-osx"
"VCPKG_TARGET_TRIPLET": "x64-osx",
"VCPKG_HOST_TRIPLET": "x64-osx"
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion cmake/presets/triplets/x64-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"x64"
],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows"
"VCPKG_TARGET_TRIPLET": "x64-windows",
"VCPKG_HOST_TRIPLET": "x64-windows"
}
}
]
Expand Down
Loading

0 comments on commit 4c00330

Please sign in to comment.