Skip to content

Commit 6d29d27

Browse files
infra: helper: add support for -out in introspector (#15199)
This makes it easy to accummulate coverage reports e.g. ``` python3 infra/helper.py introspector --coverage-only --out json-cov-2 json-c --seconds 60 ``` --------- Signed-off-by: David Korczynski <david@adalogics.com>
1 parent 72b17df commit 6d29d27

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

infra/helper.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ def get_parser(): # pylint: disable=too-many-statements,too-many-locals
421421
'--coverage-only',
422422
action='store_true',
423423
help='if specified, will only collect coverage.')
424+
introspector_parser.add_argument(
425+
'--out',
426+
help='output directory for the coverage/introspector report. '
427+
'Useful for comparing multiple runs by writing each to a '
428+
'distinct folder.')
424429

425430
download_corpora_parser = subparsers.add_parser(
426431
'download_corpora', help='Download all corpora for a project.')
@@ -1247,6 +1252,28 @@ def _introspector_prepare_corpus(args):
12471252
return True
12481253

12491254

1255+
def _copy_coverage_report(project_out, dest_dir):
1256+
"""Copies the coverage report and per-target reports to dest_dir."""
1257+
dest_dir = os.path.abspath(dest_dir)
1258+
os.makedirs(dest_dir, exist_ok=True)
1259+
1260+
# Copy the main coverage report.
1261+
src_report = os.path.join(project_out, 'report')
1262+
dst_report = os.path.join(dest_dir, 'report')
1263+
if os.path.isdir(src_report):
1264+
shutil.rmtree(dst_report, ignore_errors=True)
1265+
shutil.copytree(src_report, dst_report)
1266+
1267+
# Copy per-target coverage reports.
1268+
src_target_report = os.path.join(project_out, 'report_target')
1269+
dst_target_report = os.path.join(dest_dir, 'report_target')
1270+
if os.path.isdir(src_target_report):
1271+
shutil.rmtree(dst_target_report, ignore_errors=True)
1272+
shutil.copytree(src_target_report, dst_target_report)
1273+
1274+
logger.info('Coverage report copied to %s', dest_dir)
1275+
1276+
12501277
def introspector(args):
12511278
"""Runs a complete end-to-end run of introspector."""
12521279
parser = get_parser()
@@ -1284,6 +1311,10 @@ def introspector(args):
12841311

12851312
logger.info('Coverage collected for %s', args.project.name)
12861313
if args.coverage_only:
1314+
if args.out:
1315+
_copy_coverage_report(args.project.out, args.out)
1316+
else:
1317+
logger.info('Report in %s', os.path.join(args.project.out, 'report'))
12871318
logger.info('Coverage-only enabled, finishing now.')
12881319
return True
12891320

@@ -1295,7 +1326,7 @@ def introspector(args):
12951326
logger.error('Failed to build project with introspector')
12961327
return False
12971328

1298-
introspector_dst = os.path.join(args.project.out,
1329+
introspector_dst = os.path.join(args.out if args.out else args.project.out,
12991330
"introspector-report/inspector")
13001331
shutil.rmtree(introspector_dst, ignore_errors=True)
13011332
shutil.copytree(os.path.join(args.project.out, "inspector"), introspector_dst)

0 commit comments

Comments
 (0)