@@ -12,12 +12,12 @@ mod tpm;
1212mod util;
1313
1414use crate :: opt:: { FmtOpt , TestOpt } ;
15- use anyhow:: Result ;
15+ use anyhow:: { bail , Result } ;
1616use arch:: UefiArch ;
1717use cargo:: { Cargo , CargoAction , Feature , Package , TargetTypes } ;
1818use clap:: Parser ;
1919use itertools:: Itertools ;
20- use opt:: { Action , BuildOpt , ClippyOpt , DocOpt , Opt , QemuOpt , TpmVersion } ;
20+ use opt:: { Action , BuildOpt , ClippyOpt , CovOpt , DocOpt , Opt , QemuOpt , TpmVersion } ;
2121use std:: process:: Command ;
2222use util:: run_cmd;
2323
@@ -85,6 +85,30 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
8585 run_cmd ( cargo. command ( ) ?)
8686}
8787
88+ /// Generate a code coverage report.
89+ fn code_coverage ( opt : & CovOpt ) -> Result < ( ) > {
90+ if has_cmd ( "cargo-llvm-cov" ) {
91+ let cargo = Cargo {
92+ action : CargoAction :: Coverage {
93+ lcov : opt. lcov ,
94+ open : opt. open ,
95+ } ,
96+ features : Feature :: more_code ( * opt. unstable , false ) ,
97+ // Leave out uefi-macros; the compilation tests will just make
98+ // things slower without contributing anything to the coverage
99+ // report.
100+ packages : vec ! [ Package :: UefiRaw , Package :: Uefi ] ,
101+ release : false ,
102+ target : None ,
103+ warnings_as_errors : false ,
104+ target_types : TargetTypes :: Default ,
105+ } ;
106+ run_cmd ( cargo. command ( ) ?)
107+ } else {
108+ bail ! ( "cargo-llvm-cov not found, see https://github.com/taiki-e/cargo-llvm-cov" ) ;
109+ }
110+ }
111+
88112/// Build docs.
89113fn doc ( opt : & DocOpt ) -> Result < ( ) > {
90114 let cargo = Cargo {
@@ -305,6 +329,7 @@ fn main() -> Result<()> {
305329 Action :: Build ( build_opt) => build ( build_opt) ,
306330 Action :: CheckRaw ( _) => check_raw:: check_raw ( ) ,
307331 Action :: Clippy ( clippy_opt) => clippy ( clippy_opt) ,
332+ Action :: Cov ( cov_opt) => code_coverage ( cov_opt) ,
308333 Action :: Doc ( doc_opt) => doc ( doc_opt) ,
309334 Action :: GenCode ( gen_opt) => device_path:: gen_code ( gen_opt) ,
310335 Action :: Miri ( _) => run_miri ( ) ,
0 commit comments