Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cov.el
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ COVERAGE-TOOL has created the data.
Currently the only supported COVERAGE-TOOL is gcov.")

(defvar cov-coverage-file-paths
'("." cov--locate-lcov cov--locate-coveralls cov--locate-clover cov--locate-coveragepy)
'("." cov--locate-gcov-cmake cov--locate-lcov cov--locate-coveralls cov--locate-clover cov--locate-coveragepy)
"List of paths or functions returning file paths containing coverage files.

Relative paths:
Expand Down Expand Up @@ -260,6 +260,26 @@ that filename. Otherwise search for the first matching pattern in
cov-lcov-patterns)))
(when lcov-file (cons lcov-file 'lcov))))

(defun cov--locate-gcov-cmake (file-dir file-name)
"Locate a gcov coverage file from FILE-DIR for FILE-NAME.
This works with CMake-based projects, by constructing the path to the `.gcov'
file from object file's path extracted from the \"compile_commands.json\"."
(when-let* ((root (project-root (project-current)))
(compile-commands (expand-file-name "compile_commands.json" root)))
(when (file-exists-p compile-commands)
(when-let* ((file-cmd (cl-find-if
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when-let* was introduced in Emacs 26 (as far as I can tell). cov.el supports Emacs 24.4 onward. Please use other means to do this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I fixed this!

(lambda (entry)
(equal (file-truename (alist-get 'file entry))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alist-getwas introduced in Emacs 25.1, cov.el supports from Emacs 24.4 onward.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I fixed this!

(expand-file-name file-name file-dir)))
(json-read-file compile-commands)))
(command (alist-get 'command file-cmd))
(directory (alist-get 'directory file-cmd)))
(let* ((obj-file (when (string-match
(concat "-o \\(?1:.*" (regexp-quote (concat file-name ".o")) "\\)")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match looks fragile to me. What if there is no space between -o and the file name for instance?

Copy link
Copy Markdown
Author

@abougouffa abougouffa Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, I've changed it to " -o *"..., while accepting matches "file.cpp.o" and "file.o" for a "file.cpp". This is more generic than assuming object files will have the "file.cpp.o" format (which is correct for CMake, but not necessary valid for other build tools).

command)
(match-string-no-properties 1 command))))
(cons (expand-file-name (file-name-with-extension obj-file ".gcov") directory) 'gcov))))))

(defun cov--locate-coveralls (file-dir _file-name)
"Locate coveralls coverage from FILE-DIR for FILE-NAME.

Expand Down