Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azure-pipelines | analyzer] Code coverage integration #110

Merged
merged 15 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ include(CPack)
option(BUILD_SHARED_LIBS "build shared libs with C inteface" ON)
option(BUILD_EXAMPLES "build examples" ON)
include(CTest)
option(ENABLE_CODE_COVERAGE "compile Debug with code coverage" OFF)
option(BUILD_SNAPSHOT "build snapshot test" OFF)
include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(TEST_DUMP_SNAPSHOT "build test to dump the expected output instead of verifing it" OFF
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SDL2 VGA Terminal

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/83e178fb7d9343b78be651f2797fe3f8)](https://app.codacy.com/manual/Raffaello/sdl2-vga-terminal?utm_source=github.com&utm_medium=referral&utm_content=Raffaello/sdl2-vga-terminal&utm_campaign=Badge_Grade_Settings)
[![codecov](https://codecov.io/gh/Raffaello/sdl2-vga-terminal/branch/master/graph/badge.svg)](https://codecov.io/gh/Raffaello/sdl2-vga-terminal)

| Monolithic CI | Note |
|:-------------:|-----:|
Expand Down
21 changes: 17 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configuration:

environment:
VCPKG_SCRIPT: scripts/buildsystems/vcpkg.cmake
ENABLE_CODE_COVERAGE: OFF

matrix:
allow_failures:
Expand Down Expand Up @@ -46,17 +47,29 @@ for:
environment:
WS: /Users/appveyor/projects
TRIPLET: $PLATFORM-osx
# ENABLE_CODE_COVERAGE: ON
cache:
#- $WS/vcpkg
- $WS/vcpkg/installed
init:
- sh: if [ $PLATFORM = "x86" ]; then exit 1; fi
- sh: brew install p7zip
- sh: brew install p7zip #lcov
- sh: cd $WS && git clone https://github.com/Microsoft/vcpkg.git
- sh: cd $APPVEYOR_BUILD_FOLDER
# /Library/Developer/CommandLineTools/usr/bin/llvm-cov
#- sh: sudo find / -name llvm-cov 2> /dev/null
#- sh: llvm-cov --help
test_script:
- sh: ctest -V

#- sh: find . -name *.gcda
#- sh: echo '#!/bin/bash' > g.sh
#- sh: echo 'exec /Library/Developer/CommandLineTools/usr/bin/llvm-cov gcov "$@"' >> g.sh
#- sh: chmod +x g.sh
#- sh: ./g.sh -f -b -u $(find . -name *.gcda)
#- sh: lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info
#- sh: lcov --remove cov.info '/Applications/*' --output-file coverage.info
#- sh: lcov --list coverage.info
#- sh: bash <(curl -s https://codecov.io/bash) -f coverage.info -t b8f07100-6985-49f7-aa4c-14e36f29ac80

skip_commits:
files:
Expand Down Expand Up @@ -90,8 +103,8 @@ before_build:
build_script:
- mkdir out
- cd out
- cmd: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DWITH_SDL2_STATIC=OFF -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/%VCPKG_SCRIPT% ..
- sh : cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION -DWITH_SDL2_STATIC=ON -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=$WS/vcpkg/$VCPKG_SCRIPT ..
- cmd: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DWITH_SDL2_STATIC=OFF -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/%VCPKG_SCRIPT% ..
- sh : cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION -DWITH_SDL2_STATIC=ON -DBUILD_SNAPSHOT=OFF -DENABLE_CODE_COVERAGE=$ENABLE_CODE_COVERAGE -DCMAKE_TOOLCHAIN_FILE=$WS/vcpkg/$VCPKG_SCRIPT ..
- cmake --build .

test_script:
Expand Down
45 changes: 31 additions & 14 deletions azure-pipelines/analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ pr:
- LICENSE

variables:
- template: variables.yml
- template: variables/global.yml
- template: variables/images.yml
- template: variables/build_switches.yml

stages:
- stage: Dep
jobs:
- job: vcpkg
strategy:
matrix:
Win 64 bits:
imageName: ${{ variables.windows_image }}
TRIPLET: x64-windows
ARCH: 64
osx:
imageName: ${{ variables.mac_image }}
TRIPLET: x64-osx
pool:
vmImage: $(imageName)
steps:
Expand All @@ -46,18 +47,34 @@ stages:
triplet: $(TRIPLET)
arch: $(ARCH)


- stage: Analyzer
variables:
BUILD_EXAMPLES: OFF
BUILD_SHARED_LIBS: ON
ENABLE_CODE_COVERAGE: ON
jobs:
# - template: 'templates/sonarcloud-job.yml'
# parameters:
# imageName: ${{ variables.windows_image }}
# jobName: SonarCloud_win
# jobDisplayName: SonarCloud (WIN)
# vcpkg_key_cache: $(CACHE_VCPKG_KEY)
# triplet: x64-windows
# arch: 64
# build_type: Debug
# sonar_wrapper_url: 'https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip'
# build_wrapper: 'build-wrapper-win-x86\build-wrapper-win-x86-64.exe'
# build_wrapper_path: build/build-wrapper-win-x86
# cmake_ignore_path: $(CMAKE_IGNORE_PATH_WIN)
- template: 'templates/sonarcloud-job.yml'
parameters:
imageName: ${{ variables.windows_image }}
jobName: SonarCloud_win
jobDisplayName: SonarCloud (WIN)
imageName: ${{ variables.mac_image }}
jobName: SonarCloud_macos
jobDisplayName: SonarCloud (macOS)
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: x64-windows
arch: 64
triplet: x64-osx
build_type: Debug
sonar_wrapper_url: 'https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip'
build_wrapper: 'build-wrapper-win-x86\build-wrapper-win-x86-64.exe'
build_wrapper_path: build/build-wrapper-win-x86
cmake_ignore_path: $(CMAKE_IGNORE_PATH_WIN)
sonar_wrapper_url: 'https://sonarcloud.io/static/cpp/build-wrapper-macosx-x86.zip'
build_wrapper: 'build-wrapper-macosx-x86/build-wrapper-macosx-x86'
build_wrapper_path: build/build-wrapper-macosx-x86
18 changes: 6 additions & 12 deletions azure-pipelines/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,25 @@ pr:
- LICENSE

variables:
- template: variables.yml
- template: variables/global.yml
- template: variables/images.yml
- template: variables/build_switches.yml

stages:
- stage: Dep
jobs:
- job: vcpkg
strategy:
matrix:
Linux:
imageName: ${{ variables.linux_image }}
TRIPLET: x64-linux
pool:
vmImage: $(imageName)
vmImage: ${{ variables.linux_image }}
steps:
- template: templates/dep-vcpkg-steps.yml
parameters:
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: $(TRIPLET)
arch: $(ARCH)
triplet: x64-linux

- stage: CI
jobs:
- job: Linux
variables:
TRIPLET: x64-linux
strategy:
matrix:
GCC Debug:
Expand All @@ -62,7 +56,7 @@ stages:
- template: 'templates/ci-steps.yml'
parameters:
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: $(TRIPLET)
triplet: x64-linux
build_type: $(CONFIGURATION)
test: false
install: false
19 changes: 6 additions & 13 deletions azure-pipelines/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,26 @@ pr:
- README.md
- appveyor.yml
- LICENSE

variables:
- template: variables.yml
- template: variables/global.yml
- template: variables/images.yml
- template: variables/build_switches.yml

stages:
- stage: Dep
jobs:
- job: vcpkg
strategy:
matrix:
MacOS:
imageName: ${{ variables.mac_image }}
TRIPLET: x64-osx
pool:
vmImage: $(imageName)
vmImage: ${{ variables.mac_image }}
steps:
- template: templates/dep-vcpkg-steps.yml
parameters:
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: $(TRIPLET)
arch: $(ARCH)
triplet: x64-osx

- stage: CI
jobs:
- job: macOS
variables:
TRIPLET: x64-osx
strategy:
matrix:
Debug:
Expand All @@ -62,6 +55,6 @@ stages:
- template: 'templates/ci-steps.yml'
parameters:
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: $(TRIPLET)
triplet: x64-osx
build_type: $(CONFIGURATION)
install: false
4 changes: 3 additions & 1 deletion azure-pipelines/monolithic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pr:
- LICENSE

variables:
- template: variables.yml
- template: variables/global.yml
- template: variables/images.yml
- template: variables/build_switches.yml

stages:
- stage: Dep
Expand Down
14 changes: 13 additions & 1 deletion azure-pipelines/templates/ci-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,27 @@ steps:
- template: 'cmake-gen-build-steps.yml'
parameters:
build_type: ${{ parameters.build_type }}
triplet: ${{ parameters.triplet }}
vcpkg_cmake: ${{ parameters.vcpkg_cmake }}
cmake_args: ${{ parameters.cmake_args }}
cmake_ignore_path: ${{ parameters.cmake_ignore_path }}
arch: ${{ parameters.arch }}
#build_wrapper:
- ${{ if eq(parameters.test, true) }}:
- script: ctest -C ${{ parameters.build_type }} -V
- script: ctest -C ${{ parameters.build_type }} -v -V -T Test
displayName: cmake test (ctest)
workingDirectory: build
- task: PublishTestResults@2
inputs:
testResultsFormat: 'cTest' # Options: JUnit, NUnit, VSTest, xUnit, cTest
testResultsFiles: '**/Test.xml'
searchFolder: build # Optional
#mergeTestResults: false # Optional
#failTaskOnFailedTests: false # Optional
#testRunTitle: # Optional
#buildPlatform: # Optional
#buildConfiguration: # Optional
#publishRunAttachments: true # Optional

- ${{ if eq(parameters.install, true) }}:
- script: cmake --build . --target install
Expand Down
8 changes: 6 additions & 2 deletions azure-pipelines/templates/cmake-gen-build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ parameters:
- name: build_type
displayName: Build Type
type: string

- name: triplet
displayName: triplet
type: string

- name: vcpkg_cmake
displayName: VCPKG_CMAKE
Expand Down Expand Up @@ -31,7 +35,7 @@ parameters:
steps:
- bash: |
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} ..
cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.triplet }} -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} ..
displayName: cmake generator (UNIX)
condition: ne(variables['Agent.OS'], 'Windows_NT')
- bash: ${{ parameters.build_wrapper }} cmake --build .
Expand All @@ -42,7 +46,7 @@ steps:
- script: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars${{ parameters.arch }}.bat"
mkdir build & cd build
cmake -DCMAKE_IGNORE_PATH="${{ parameters.cmake_ignore_path }}" -G"Ninja" -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} ..
cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.triplet }} -DCMAKE_IGNORE_PATH="${{ parameters.cmake_ignore_path }}" -G"Ninja" -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} ..
displayName: 'CMake generator (WIN)'
condition: eq(variables['Agent.OS'], 'Windows_NT')
- script: |
Expand Down
9 changes: 4 additions & 5 deletions azure-pipelines/templates/dep-vcpkg-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ parameters:

steps:
- checkout: none
- task: Cache@2
inputs:
key: '${{ parameters.vcpkg_key_cache }} | ${{ parameters.triplet }}'
path: "vcpkg"
cacheHitVar: CACHE_RESTORED
- template: 'vcpkg-cache-step.yml'
parameters:
vcpkg_key_cache: ${{ parameters.vcpkg_key_cache }}
triplet: ${{ parameters.triplet }}
- bash: test -d vcpkg || git clone https://github.com/Microsoft/vcpkg.git
displayName: clone vcpkg
- script: echo "installing packages ${{ parameters.packages }}"
Expand Down
44 changes: 43 additions & 1 deletion azure-pipelines/templates/sonarcloud-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ parameters:
- build/build-wrapper-linux-x86-64
- build/build-wrapper-macosx-x86

- name: test
displayName: Run Test?
type: boolean
default: true

- name: publish_timeout
displayName: PUBLISH_TIMEOUT
type: number
Expand All @@ -90,6 +95,7 @@ jobs:
parameters:
vcpkg_key_cache: ${{ parameters.vcpkg_key_cache }}
triplet: ${{ parameters.triplet }}

- task: Cache@2
inputs:
key: '"${{ parameters.sonar_wrapper_url }}" | "$(Agent.OS)"'
Expand All @@ -102,21 +108,57 @@ jobs:
unzip build-wrapper.zip
displayName: build-wrapper
condition: ne(variables.CACHED_BUILD_WRAPPER, 'true')

- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'sonarCloud'
organization: 'raffaello-github'
scannerMode: 'CLI'
configMode: 'file'
displayName: Prepare sonarCloud

- template: 'cmake-gen-build-steps.yml'
parameters:
build_type: ${{ parameters.build_type }}
triplet: ${{ parameters.triplet }}
vcpkg_cmake: ${{ parameters.vcpkg_cmake }}
cmake_args: ${{ parameters.cmake_args }}
cmake_ignore_path: ${{ parameters.cmake_ignore_path }}
arch: ${{ parameters.arch }}
build_wrapper: "${{ parameters.build_wrapper }} --out-dir bw-output"
build_wrapper: "${{ parameters.build_wrapper }} --out-dir bw-output"

- ${{ if eq(parameters.test, true) }}:
- script: ctest -C ${{ parameters.build_type }}
displayName: ctest
workingDirectory: build
# /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov
- bash: |
echo '#!/bin/bash' > g.sh
echo 'exec /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov gcov "$@"' >> g.sh
chmod +x g.sh
cat g.sh
displayName: llvm-cov gcov wrapper
workingDirectory: build
condition: ne(variables['Agent.OS'], 'Windows_NT')

#- bash: sudo find / -name llvm-cov 2> /dev/null
# displayName: llvm-cov DEBUG
# condition: ne(variables['Agent.OS'], 'Windows_NT')
- bash: |
echo $OSTYPE
test $OSTYPE = "darwin19" && brew install lcov || apt-get install -y lcov
#brew install lcov
#echo "finding..."
#find . -name *.gcda
#echo "...."
./g.sh -f -b -u $(find . -name *.gcda)
lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info
lcov --remove cov.info '/Applications/*' --output-file coverage.info
lcov --list coverage.info
bash <(curl -s https://codecov.io/bash) -f coverage.info -t b8f07100-6985-49f7-aa4c-14e36f29ac80
displayName: collect coverage data
workingDirectory: build
condition: ne(variables['Agent.OS'], 'Windows_NT')
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
inputs:
Expand Down
Loading