简体   繁体   English

gitlab-ci.yml cpp报道

[英]gitlab-ci.yml cpp coverage report

I am trying to implement CI using Gitlab for a c++ project. 我正在尝试使用Gitlab为c ++项目实现CI。 To start with, I added a simple c++ hello world program which compiled and ranfine in both my PC and in Gitlab CI. 首先,我添加了一个简单的c ++ hello world程序,它在我的PC和Gitlab CI中编译和运行。

When I try to generate coverage report for the same the commands, it works on PC but not in Gitlab CI. 当我尝试为相同的命令生成覆盖率报告时,它适用于PC但不适用于Gitlab CI。

This is my gitlab-ci.yml 这是我的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

This is the generated error output 这是生成的错误输出

$ 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

How can I fix this? 我怎样才能解决这个问题?

Solved the issue by changing image name from gcc to ubuntu 16.04, the working yml will look like this 通过将图像名称从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