@@ -22,7 +22,7 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
2222 outfiles = []
2323 exitcode = 0
2424
25- (gcovr_exe , gcovr_version , lcov_exe , genhtml_exe , llvm_cov_exe ) = environment .find_coverage_tools ()
25+ (gcovr_exe , gcovr_version , lcov_exe , lcov_version , genhtml_exe , llvm_cov_exe ) = environment .find_coverage_tools ()
2626
2727 # load config files for tools if available in the source tree
2828 # - lcov requires manually specifying a per-project config
@@ -35,6 +35,11 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
3535 else :
3636 lcov_config = []
3737
38+ if lcov_exe and mesonlib .version_compare (lcov_version , '>=2.0' ):
39+ lcov_exe_rc_branch_coverage = ['--rc' , 'branch_coverage=1' ]
40+ else :
41+ lcov_exe_rc_branch_coverage = ['--rc' , 'lcov_branch_coverage=1' ]
42+
3843 gcovr_config = ['-e' , re .escape (subproject_root )]
3944
4045 # gcovr >= 4.2 requires a different syntax for out of source builds
@@ -90,6 +95,9 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
9095 initial_tracefile = covinfo + '.initial'
9196 run_tracefile = covinfo + '.run'
9297 raw_tracefile = covinfo + '.raw'
98+ lcov_subpoject_exclude = []
99+ if os .path .exists (subproject_root ):
100+ lcov_subpoject_exclude .append (os .path .join (subproject_root , '*' ))
93101 if use_llvm_cov :
94102 # Create a shim to allow using llvm-cov as a gcov tool.
95103 if mesonlib .is_windows ():
@@ -117,26 +125,26 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
117125 '--capture' ,
118126 '--output-file' , run_tracefile ,
119127 '--no-checksum' ,
120- '--rc' , 'lcov_branch_coverage=1' ] +
128+ * lcov_exe_rc_branch_coverage ] +
121129 lcov_config +
122130 gcov_tool_args )
123131 # Join initial and test results.
124132 subprocess .check_call ([lcov_exe ,
125133 '-a' , initial_tracefile ,
126134 '-a' , run_tracefile ,
127- '--rc' , 'lcov_branch_coverage=1' ,
135+ * lcov_exe_rc_branch_coverage ,
128136 '-o' , raw_tracefile ] + lcov_config )
129137 # Remove all directories outside the source_root from the covinfo
130138 subprocess .check_call ([lcov_exe ,
131139 '--extract' , raw_tracefile ,
132140 os .path .join (source_root , '*' ),
133- '--rc' , 'lcov_branch_coverage=1' ,
141+ * lcov_exe_rc_branch_coverage ,
134142 '--output-file' , covinfo ] + lcov_config )
135143 # Remove all directories inside subproject dir
136144 subprocess .check_call ([lcov_exe ,
137145 '--remove' , covinfo ,
138- os . path . join ( subproject_root , '*' ) ,
139- '--rc' , 'lcov_branch_coverage=1' ,
146+ * lcov_subpoject_exclude ,
147+ * lcov_exe_rc_branch_coverage ,
140148 '--output-file' , covinfo ] + lcov_config )
141149 subprocess .check_call ([genhtml_exe ,
142150 '--prefix' , build_root ,
0 commit comments