Context
Currently, coverage_to_md.py receives gcovr trace format JSON (--json) for component-level coverage and must manually compute coverage statistics by iterating over raw per-line data. This adds ~50 lines of computation logic that duplicates what gcovr already calculates internally:
_compute_line_coverage_from_trace()
_compute_branch_coverage_from_trace()
_compute_condition_coverage_from_trace()
The variant-level merged coverage already uses --json-summary-pretty (see common.cmake line 641), proving the format works in our pipeline. However, the per-component JSON (coverage.json) is still generated with --json (trace format) because it also serves as input for --add-tracefile aggregation at the variant level.
Proposed Solution
Add a lightweight conversion step per component that produces a summary JSON from the existing trace file:
# Existing (keep for --add-tracefile aggregation):
COMMAND ${GCOVR_EXE} --root ... --json --output coverage.json ...
# New (convert trace to summary for coverage_to_md.py):
COMMAND ${GCOVR_EXE} --add-tracefile coverage.json --json-summary-pretty --output coverage-summary.json
Then point coverage_to_md.py at coverage-summary.json instead of coverage.json.
Changes Required
1. common.cmake (3 locations)
| Location |
Current |
Change |
| Line ~793 (component test suite) |
Only generates trace JSON |
Add --json-summary-pretty conversion command |
| Line ~410 (component_report target) |
--json coverage.json |
--json coverage-summary.json |
| Line ~582 (variant component coverage md) |
--json coverage.json |
--json coverage-summary.json |
Note: Line 614 (variant reports target) already uses variant-coverage.json which is summary format — no change needed.
2. coverage_to_md.py
- Remove
_compute_line_coverage_from_trace() (~6 lines)
- Remove
_compute_branch_coverage_from_trace() (~8 lines)
- Remove
_compute_condition_coverage_from_trace() (~8 lines)
- Remove trace format detection and dual-path logic
- Read summary fields directly:
lines_covered, lines_total, branches_covered, branches_total, condition_covered, condition_total
- Simplify
generate_coverage_markdown() accordingly
3. Unit Tests (tests/unit/test_coverage_to_md.py)
- Remove trace-format test fixtures and test cases
- Simplify remaining tests to use summary-format fixtures only
Prerequisites
| Requirement |
Status |
| gcovr >= 8.6 |
Already pinned in pyproject.toml |
--json-summary includes per-file condition_covered / condition_total |
Confirmed for gcovr 8.6 |
Breaking Change
This is a breaking change for anyone consuming coverage_to_md.py's --json argument with trace-format files. The trace file itself (coverage.json) is still generated, so --add-tracefile pipelines are unaffected. Only coverage_to_md.py changes its expected input format.
Acceptance Criteria
Context
Currently,
coverage_to_md.pyreceives gcovr trace format JSON (--json) for component-level coverage and must manually compute coverage statistics by iterating over raw per-line data. This adds ~50 lines of computation logic that duplicates what gcovr already calculates internally:_compute_line_coverage_from_trace()_compute_branch_coverage_from_trace()_compute_condition_coverage_from_trace()The variant-level merged coverage already uses
--json-summary-pretty(seecommon.cmakeline 641), proving the format works in our pipeline. However, the per-component JSON (coverage.json) is still generated with--json(trace format) because it also serves as input for--add-tracefileaggregation at the variant level.Proposed Solution
Add a lightweight conversion step per component that produces a summary JSON from the existing trace file:
Then point
coverage_to_md.pyatcoverage-summary.jsoninstead ofcoverage.json.Changes Required
1.
common.cmake(3 locations)--json-summary-prettyconversion command--json coverage.json--json coverage-summary.json--json coverage.json--json coverage-summary.json2.
coverage_to_md.py_compute_line_coverage_from_trace()(~6 lines)_compute_branch_coverage_from_trace()(~8 lines)_compute_condition_coverage_from_trace()(~8 lines)lines_covered,lines_total,branches_covered,branches_total,condition_covered,condition_totalgenerate_coverage_markdown()accordingly3. Unit Tests (
tests/unit/test_coverage_to_md.py)Prerequisites
pyproject.toml--json-summaryincludes per-filecondition_covered/condition_totalBreaking Change
This is a breaking change for anyone consuming
coverage_to_md.py's--jsonargument with trace-format files. The trace file itself (coverage.json) is still generated, so--add-tracefilepipelines are unaffected. Onlycoverage_to_md.pychanges its expected input format.Acceptance Criteria
coverage_to_md.pyonly supports gcovr summary format (no trace parsing)--add-tracefile) still works unchanged_compute_*_from_trace()functions remain in the codebase