Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GCOV JSON intermediate format #766

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ New features and notable changes:
- In Azure pipelines or GitHub actions errors and warnings are printed in an additional format captured by the CI. (:issue:`904`)
- Detect suspicious counter values in ``gcov`` output. (:issue:`903`)
- Add :option:`--html-single-page` to create a single page report (static or with Javascript). (:issue:`916`)
- Add support for GCOV JSON intermediate format. (:issue:`766`)

Bug fixes and small improvements:

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ Path Description
======================= =======================================================

The program entrypoint and command line interface is in ``gcovr/__main__.py``.
The coverage data is parsed in the ``gcovr.gcov`` module.
The coverage data is parsed in the ``gcovr.formats.gcov`` module.
The HTML, XML, text, and summary reports
are in ``gcovr.generator.html`` and respective modules.
are in ``gcovr.formats.html`` and respective modules.

.. _test suite:

Expand Down
2 changes: 1 addition & 1 deletion doc/examples/example_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ cd $BLD_DIR
(
#BEGIN cmake_gcovr
cd $BLD_DIR
gcovr -r $SRC_DIR . --txt example_cmake.txt
gcovr -r $SRC_DIR . --txt ../../example_cmake.txt
#END cmake_gcovr
)
4 changes: 3 additions & 1 deletion doc/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def find_test_cases():
basename = os.path.basename(script)
name, _ = os.path.splitext(basename)
for format in "txt cobertura csv json html".split():
if format == "html" and is_compiler(os.getenv("CC"), "gcc-5", "gcc-6"):
if format == "html" and is_compiler(
os.getenv("CC"), "gcc-5", "gcc-6", "gcc-14"
):
continue
baseline = "{datadir}/{name}.{ext}".format(
datadir=datadir,
Expand Down
1 change: 1 addition & 0 deletions doc/source/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ Following options are always used:

Following options are only used if available:

- ``--json-format``: Use JSON intermediate format. Can only be used if no calls are needed in the report.
- ``--demangled-names``: Not available for LLVM based ``gcov``.
- ``--hash-filenames``: Available since GCC 7, as fallback the option ``--preserve-paths`` is used.
2 changes: 1 addition & 1 deletion doc/source/guide/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ and must not match any :option:`-e/--exclude<gcovr --exclude>` filter.

The :option:`--gcov-filter<gcovr --gcov-filter>`
and :option:`--gcov-exclude<gcovr --gcov-exclude>` filters apply to the
``.gcov`` files created by ``gcov``.
``.gcov`` / ``.json.gz`` files created by ``gcov``.
This is useful mostly when running gcov yourself,
and then invoking gcovr with :option:`-g/--gcov-use-existing-files<gcovr --gcov-use-existing-files>`.
But these filters also apply when gcov is launched by gcovr.
Expand Down
15 changes: 9 additions & 6 deletions gcovr/formats/coveralls/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ def _make_source_file(coverage_details: FileCoverage, options) -> Dict[str, Any]
source_file = {}

# Generate md5 hash of file contents
with open(coverage_details.filename, "rb") as file_handle:
contents = file_handle.read()

source_file["source_digest"] = get_md5_hexdigest(contents)
if coverage_details.filename.endswith("<stdin>"):
total_line_count = None
else:
with open(coverage_details.filename, "rb") as file_handle:
contents = file_handle.read()

total_line_count = len(contents.splitlines())
source_file["source_digest"] = get_md5_hexdigest(contents)
total_line_count = len(contents.splitlines())

# Isolate relative file path
relative_file_path = presentable_filename(
Expand Down Expand Up @@ -229,7 +231,8 @@ def _make_source_file(coverage_details: FileCoverage, options) -> Dict[str, Any]
# source_file['coverage'].append(b_hits)

# add trailing empty lines
_extend_with_none(source_file["coverage"], total_line_count)
if total_line_count is not None:
_extend_with_none(source_file["coverage"], total_line_count)

return source_file

Expand Down
Loading
Loading