簡體   English   中英

gitlab-ci.yml cpp報道

[英]gitlab-ci.yml cpp coverage report

我正在嘗試使用Gitlab為c ++項目實現CI。 首先,我添加了一個簡單的c ++ hello world程序,它在我的PC和Gitlab CI中編譯和運行。

當我嘗試為相同的命令生成覆蓋率報告時,它適用於PC但不適用於Gitlab CI。

這是我的gitlab-ci.yml

# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: gcc

build:
  stage: build
  # instead of calling g++ directly you can also use some build toolkit like make
  # install the necessary build tools when needed
  # before_script: 
  #   - apt update && apt -y install make autoconf 
  script: 
    - g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
    - ls
  artifacts:
    paths:
      - mybinary
  # depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
  # cache:
  #   paths:
  #     - "*.o"

# run tests using the binary built before
test:
  stage: test
  script:
    - bash runmytests.sh

coverage:
  stage: deploy
  before_script:
    - apt-get -qq update && apt-get -qq install -y gcovr ggcov lcov
  script:
    - ls
    - g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
    - ./mybinary
    - ls
    - gcov helloworld.cpp
    - lcov --directory . --capture --output-file coverage.info
    - lcov --remove coverage.info '/usr/*' --output-file coverage.info
    - lcov --list coverage.info
    - genhtml -o res coverage.info

這是生成的錯誤輸出

$ g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
$ ./mybinary
Hello, World!$ ls
README.md
helloworld.cpp
helloworld.gcda
helloworld.gcno
mybinary
runmytests.sh
$ gcov helloworld.cpp
File 'helloworld.cpp'
Lines executed:100.00% of 3
Creating 'helloworld.cpp.gcov'

File '/usr/local/include/c++/8.1.0/iostream'
No executable lines
Removing 'iostream.gcov'

$ lcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 8.1.0
Scanning . for .gcda files ...
geninfo: WARNING: /builds/ganeshredcobra/gshell/helloworld.gcno: Overlong record at end of file!
Found 1 data files in .
Processing helloworld.gcda
geninfo: WARNING: cannot find an entry for helloworld.cpp.gcov in .gcno file, skipping file!
Finished .info-file creation
$ lcov --list coverage.info
Reading tracefile coverage.info
lcov: ERROR: no valid records found in tracefile coverage.info
ERROR: Job failed: exit code 1

我怎樣才能解決這個問題?

通過將圖像名稱從gcc更改為ubuntu 16.04來解決問題,工作yml將如下所示

# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: ubuntu:16.04

build:
  stage: build
  # instead of calling g++ directly you can also use some build toolkit like make
  # install the necessary build tools when needed
  before_script: 
    - apt update && apt -y install make autoconf gcc g++
  script: 
    - g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
    - ls
  artifacts:
    paths:
      - mybinary
  # depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
  # cache:
  #   paths:
  #     - "*.o"

# run tests using the binary built before
test:
  stage: test
  script:
    - bash runmytests.sh

coverage:
  stage: deploy
  before_script:
    - apt-get -qq update && apt-get -qq install -y make autoconf gcc g++ gcovr ggcov lcov
  script:
    - ls
    - g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
    - ./mybinary
    - ls
    - gcov helloworld.cpp
    - lcov --directory . --capture --output-file coverage.info
    - lcov --list coverage.info

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM