From 35c7d20f9e2c065df27fe572438cc539b577aa51 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Mon, 29 Jul 2024 21:45:41 +0200 Subject: [PATCH] build: simpify code coverage logic --- .docker/build-linux.sh | 14 ++++---------- .github/workflows/build.yml | 9 +-------- CMakeLists.txt | 7 ++++++- ricepp/CMakeLists.txt | 5 ++++- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/.docker/build-linux.sh b/.docker/build-linux.sh index 13d79f12..7ccf5b98 100644 --- a/.docker/build-linux.sh +++ b/.docker/build-linux.sh @@ -123,20 +123,14 @@ cmake ../dwarfs/ $CMAKE_ARGS $BUILD_TOOL -if [[ "-$BUILD_TYPE-" == *-coverage-* ]]; then - export LLVM_PROFILE_FILE="$PWD/profile/%32m.profraw" -fi - ctest --output-on-failure -j$(nproc) if [[ "-$BUILD_TYPE-" == *-coverage-* ]]; then - unset LLVM_PROFILE_FILE - rm -rf /tmp-runner/coverage - mkdir -p /tmp-runner/coverage + rm -f /tmp-runner/dwarfs-coverage.txt llvm-profdata-$CLANG_VERSION merge -sparse profile/* -o dwarfs.profdata - for binary in mkdwarfs dwarfs dwarfsck dwarfsextract *_test ricepp/ricepp_test; do - llvm-cov-$CLANG_VERSION show -instr-profile=dwarfs.profdata $binary >/tmp-runner/coverage/$(basename $binary).txt - done + llvm-cov-$CLANG_VERSION show -instr-profile=dwarfs.profdata \ + $(for i in mkdwarfs dwarfs dwarfsck dwarfsextract *_test ricepp/ricepp_test; do echo $i; done | sed -e's/^/-object=/') \ + >/tmp-runner/dwarfs-coverage.txt fi if [[ "-$BUILD_TYPE-" == *-static-* ]]; then diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 47082f51..29017900 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -326,19 +326,12 @@ jobs: --env GITHUB_RUN_ATTEMPT \ dwarfs-linux-build-${{ matrix.dist }} - - name: List Coverage Files - id: coverage-files - if: matrix.build_type == 'clang-coverage-ninja' - run: | - files=$(find ${{ runner.temp }}/coverage -type f | paste -d, -s) - echo "list=$files" >> "$GITHUB_OUTPUT" - - name: Upload Coverage Data if: matrix.build_type == 'clang-coverage-ninja' uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - files: ${{ steps.coverage-files.outputs.list }} + file: ${{ runner.temp }}/dwarfs-coverage.txt fail_ci_if_error: false - name: Prepare Artifact Upload diff --git a/CMakeLists.txt b/CMakeLists.txt index e42e29c1..9a9ba147 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -991,7 +991,10 @@ if(WITH_TESTS) endforeach() foreach(tgt ${TEST_TARGETS}) - gtest_discover_tests(${tgt} DISCOVERY_TIMEOUT 120) + gtest_discover_tests(${tgt} + DISCOVERY_TIMEOUT 120 + PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/profile/%32m.profraw" + ) endforeach() endif() @@ -1401,6 +1404,8 @@ add_custom_target( build.ninja .ninja_deps Makefile compile_commands.json artifacts.env + default.profraw + profile COMMAND ${CMAKE_COMMAND} -E rm -rf ${REALCLEAN_FILES} ) diff --git a/ricepp/CMakeLists.txt b/ricepp/CMakeLists.txt index 1d2904c8..b4bee5c6 100644 --- a/ricepp/CMakeLists.txt +++ b/ricepp/CMakeLists.txt @@ -192,6 +192,9 @@ if(WITH_TESTS) endif() if(NOT CMAKE_CROSSCOMPILING) - gtest_discover_tests(ricepp_test DISCOVERY_TIMEOUT 120) + gtest_discover_tests(ricepp_test + DISCOVERY_TIMEOUT 120 + PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/profile/%32m.profraw" + ) endif() endif()