使用Bazel生成覆盖率报告 [英] Using Bazel to generate coverage report

查看:1080
本文介绍了使用Bazel生成覆盖率报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用genhtml命令从Bazel生成的coverage.dat文件生成html覆盖率报告:

I am using genhtml command to generate html coverage report from Bazel generated coverage.dat file:

genhtml bazel-testlogs/path/to/TestTarget/coverage.dat --output-directory coverage

使用genhtml的问题是我必须提供coverage.dat文件(在bazel-testlogs/..中生成)的路径.是否可以将这些coverage.dat文件作为另一条规则的输出来获取?

The problem with using genhtml is that I have to provide the paths to the coverage.dat files (which are generated in bazel-testlogs/..) Is it possible to fetch those coverage.dat files as an output from another rule?

我不想直接调用genthml命令,而是让Bazel处理所有事情.

I would like to not have to call genthml command directly, but have Bazel handle everything.

推荐答案

我无法找到一种方法来获取coverage.dat文件,作为bazel规则的输出.但是,我能够将所有.dat文件的所有位置作为srcs包装到WORKSPACE目录中的文件组:

I was not able to find a way to get coverage.dat files as an output of a bazel rule. However, I was able to wrap all the locations of all the .dat files as srcs to a filegroup in WORKSPACE directory:

filegroup(
    name = "coverage_files",
    srcs = glob(["bazel-out/**/coverage.dat"]),
)

,然后在包装genthml命令的自定义.bzl规则中使用该文件组,以生成html覆盖率报告.所以现在我只需要致电

and then use that filegroup in a custom .bzl rule that wraps the genthml command to generate html coverage report. So now I only have to call

bazel coverage //path/... --instrumentation_filter=/path[/:]

命令生成coverage.dat文件,生成html报告并将其压缩.因此,bazel可以处理所有内容.

command to generate the coverage.dat files, generate html report and zip it up. Thus, bazel handles everything.

这篇关于使用Bazel生成覆盖率报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆