我正在尝试使用 gcovr 从 gcno/gcda 生成 xml 以提供 Jenkins 中的 cobertura 插件。该应用程序构建在构建机器上,并传递给在单元测试从属设备上运行的下游作业。源文件和生成的 gcno 文件也以其原始文件夹结构复制到单元测试机器。由于应用程序的构建路径和安装路径不同,我使用 GCOV_PREFIX_STRIP 和 GCOV_PREFIX 使生成的 gcda 文件最终位于与相应 gcno 文件相同的位置。我可以确认 gcda 文件是在正确的位置生成的。
Jenkins 构建主工作区位于:
/var/lib/jenkins/workspace/Coverage/
该应用程序内置于:
/var/lib/jenkins/workspace/Coverage/BUILD/app/
Jenkins 单元测试从工作区位于:
/var/lib/jenkins/workspace/Coverage-Unittest/
源代码、gcno 和 gcda 文件位于(gcno/gcda 位于相对于相应 cpp 的名为 'o' 的子目录中):
/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/
这是通过设置实现的:
GCOV_PREFIX_STRIP=7
GCOV_PREFIX=/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/
从 Jenkins 单元测试从属执行 shell(当前目录是工作区)我执行:
python2 gcovr -v --gcov-executable=/opt/gcc-5.3.0/bin/gcov -x -r BUILD/app/.
然而,结果是:
Gathered coveraged data for 0 files
<?xml version="1.0" ?>
<!DOCTYPE coverage
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.0" line-rate="0.0" timestamp="1478904126" version="gcovr 3.3">
<sources>
<source>BUILD/app/.</source>
</sources>
<packages/>
</coverage>
这很奇怪,因为似乎找到了 gcda 文件。一些详细的输出:
Scanning directory BUILD/app/. for gcda/gcno files...
Found 1891 files (and will process 1391)
...
Processing file: /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest/BUILD'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace/Coverage-Unittest'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins/workspace'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib/jenkins'
Running gcov: '/opt/gcc-5.3.0/bin/gcov /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/MyClass.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o' in '/var/lib'
...
注意同一个 gcda 文件是如何被多次列出的,这是所有 gcda 文件的情况。目录 /var/lib/jenkins/workspace/Coverage-Unittest/BUILD/app/packages/appw/lib/model/o/ 包含 MyClass.gcda 和 MyClass.gcno 以及目录 /var/lib/jenkins/workspace/Coverage -Unittest/BUILD/app/packages/appw/lib/model/ 包含 MyClass.cpp。
该应用程序是使用带有 -coverage 标志的 gcc 5.3.0 编译的。
我希望输出 xml 包含覆盖信息,如何解决?