Browse Source

build: Inject a Perl coverage index entry into the lcov report

Add correct summary values, create a percentage bar, and remove the
lcov-epilog template, which was being inserted in every and each
generated lcov html file, not just the indices.

The injection should be considered fragile, as it depends on the input
report not changing its structure. But this is no worse than using the
local prolog and epilog html templates.
Guillem Jover 10 years ago
parent
commit
8dcb3372f4
3 changed files with 79 additions and 10 deletions
  1. 9 2
      Makefile.am
  2. 0 8
      doc/lcov-epilog
  3. 70 0
      doc/lcov-inject

+ 9 - 2
Makefile.am

@@ -34,7 +34,7 @@ EXTRA_DIST = \
 	doc/README.feature-removal-schedule \
 	doc/coding-style.txt \
 	doc/frontend.txt \
-	doc/lcov-epilog \
+	doc/lcov-inject \
 	doc/lcov-prolog \
 	doc/triggers.txt \
 	debian/changelog \
@@ -98,6 +98,7 @@ LCOV_CAPTURE_OPTS = $(LCOV_OPTS) --no-recursion \
 	-d $(top_builddir)/lib/dpkg \
 	-d $(top_builddir)/src \
 	-d $(top_builddir)/utils
+LCOV_INJECT = $(PERL) -i $(top_srcdir)/doc/lcov-inject
 
 coverage: all
 	: # Remove coverage data from any previous run
@@ -120,11 +121,17 @@ coverage: all
 	$(LCOV_GENHTML) $(LCOV_OPTS) \
 	  --legend --title "dpkg C code coverage" \
 	  --html-prolog $(top_srcdir)/doc/lcov-prolog \
-	  --html-epilog $(top_srcdir)/doc/lcov-epilog \
 	  -o doc/coverage dpkg.lcov
 
 	$(MAKE) -C scripts $@
 
+	: # XXX: Inject perl coverage into lcov index files. This is a fragile
+	: # hack which might break depending on the html output generated.
+	$(LCOV_INJECT) doc/coverage/index-sort-b.html
+	$(LCOV_INJECT) doc/coverage/index-sort-f.html
+	$(LCOV_INJECT) doc/coverage/index-sort-l.html
+	$(LCOV_INJECT) doc/coverage/index.html
+
 coverage-clean:
 	rm -rf doc/coverage/
 	find -name '*.gcno' -o -name '*.gcda' -o \

+ 0 - 8
doc/lcov-epilog

@@ -1,8 +0,0 @@
-  <table width="100%" border=0 cellspacing=0 cellpadding=0>
-    <tr>
-      <td class="coverFile"><a href="scripts/coverage.html">scripts</a></td>
-    </tr>
-  </table>
-  <br />
-</body>
-</html>

+ 70 - 0
doc/lcov-inject

@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+#
+# lcov-inject
+#
+# Copyright © 2014 Guillem Jover <guillem@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+use strict;
+use warnings;
+
+use Cwd;
+use Devel::Cover::DB;
+
+my $dir = $ARGV[0] // 'scripts';
+my $cwd = cwd();
+
+chdir $dir or die "cannot switch to $dir\n";
+
+my $db = Devel::Cover::DB->new(db => 'cover_db');
+$db = $db->merge_runs();
+$db->calculate_summary(map { $_ => 1 } $db->collected());
+
+chdir $cwd or die "cannot switch to $cwd\n";
+
+my $s = $db->{summary}{Total};
+
+my $tmpl = sprintf '
+      <td class="coverFile"><a href="%s">%s</a></td>
+      <td class="coverBar" align="center">
+        <table border=0 cellspacing=0 cellpadding=1>
+          <tr><td class="coverBarOutline">
+              <img src="ruby.png" width=%.0f height=10 alt="%.1f"><img src="snow.png" width=%.0f height=10 alt="%.1f">
+          </td></tr>
+        </table>
+      </td>
+      <td class="coverPerLo">%.1f&nbsp;%%</td>
+      <td class="coverNumLo">%d / %d</td>
+      <td class="coverPerLo">%.1f&nbsp;%%</td>
+      <td class="coverNumLo">%d / %d</td>
+      <td class="coverPerLo">%.1f&nbsp;%%</td>
+      <td class="coverNumLo">%d / %d</td>
+    </tr>
+    <tr>
+', "$dir/coverage.html", $dir,
+   $s->{total}{percentage}, $s->{total}{percentage},
+   100 - $s->{total}{percentage}, $s->{total}{percentage},
+   $s->{total}{percentage}, $s->{total}{covered}, $s->{total}{total},
+   $s->{subroutine}{percentage},
+   $s->{subroutine}{covered}, $s->{subroutine}{total},
+   $s->{branch}{percentage}, $s->{branch}{covered}, $s->{branch}{total};
+
+while (<>) {
+    s/^(.*<td .*href="src\/index\.html">.*)$/$tmpl$1/;
+    print;
+}
+
+1;