From f85bc2906bf270f1cc8972b4f496218059cd9bc2 Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 4 Jul 2017 16:02:19 +0000 Subject: [PATCH] Use lcov visualizer for gcov statistics This experimental feature is only for Ruby-core team, not for casual users. Usage: `./configure --enable-gcov && make && make exam && make lcov` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- .gitignore | 2 ++ Makefile.in | 4 ++++ tool/run-lcov.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tool/run-lcov.rb diff --git a/.gitignore b/.gitignore index e1313d6cb5..af330be95c 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ y.tab.c *.gcda *.gcno *.gcov +lcov*.info # / /*-fake.rb @@ -85,6 +86,7 @@ y.tab.c /goruby /id.[ch] /largefile.h +/lcov-out /lex.c /libruby*.* /miniprelude.c diff --git a/Makefile.in b/Makefile.in index b1da163cb4..6b3785e403 100644 --- a/Makefile.in +++ b/Makefile.in @@ -484,6 +484,10 @@ after-update:: prereq gcov: $(Q) $(BASERUBY) $(srcdir)/tool/run-gcov.rb +lcov: + $(Q) $(BASERUBY) $(srcdir)/tool/run-lcov.rb + $(Q) genhtml --ignore-errors source lcov-c-all.info -o lcov-out + update-doclie: $(Q) $(srcdir)/tool/git-refresh -C $(srcdir)/coverage $(Q1:0=-q) \ --branch $(DOCLIE_GIT_REF) \ diff --git a/tool/run-lcov.rb b/tool/run-lcov.rb new file mode 100644 index 0000000000..384d4a9e70 --- /dev/null +++ b/tool/run-lcov.rb @@ -0,0 +1,41 @@ +#!ruby +require "pathname" +require "open3" + +def backup_gcda_files(gcda_files) + gcda_files = gcda_files.map do |gcda| + [gcda, gcda.sub_ext(".bak")] + end + begin + gcda_files.each do |before, after| + before.rename(after) + end + yield + ensure + gcda_files.each do |before, after| + after.rename(before) + end + end +end + +$info_files = [] +def run_lcov(dir, info) + $info_files << info + system("lcov", "-c", "-d", dir, "--rc", "lcov_branch_coverage=1", "-o", info) +end + +gcda_files = Pathname.glob("**/*.gcda") +ext_gcda_files = gcda_files.select {|f| f.fnmatch("ext/*") } +rubyspec_temp_gcda_files = gcda_files.select {|f| f.fnmatch("rubyspec_temp/*") } + +backup_gcda_files(rubyspec_temp_gcda_files) do + backup_gcda_files(ext_gcda_files) do + info = "lcov-root.info" + run_lcov(".", info) + end + ext_gcda_files.group_by {|f| f.descend.to_a[1] }.each do |key, files| + info = "lcov-#{ key.to_s.gsub(File::Separator, "-") }.info" + run_lcov(key.to_s, info) + end +end +system("lcov", *$info_files.flat_map {|f| ["-a", f] }, "-o", "lcov-c-all.info")