add FileCoverage and GcovParser to begin parsing .gcov files
This commit is contained in:
parent
075632710d
commit
f0b5a36252
@ -1,26 +1,34 @@
|
|||||||
|
require_relative "gcovinator/file_coverage"
|
||||||
|
require_relative "gcovinator/gcov_parser"
|
||||||
require_relative "gcovinator/version"
|
require_relative "gcovinator/version"
|
||||||
require "tmpdir"
|
require "tmpdir"
|
||||||
|
require "open3"
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
module Gcovinator
|
module Gcovinator
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def run(build_dir, source_dirs, files, output_dir)
|
def run(build_dir, source_dirs, files, output_dir)
|
||||||
build_dir = File.expand_path(build_dir)
|
build_dir = Pathname.new(File.expand_path(build_dir)).cleanpath.to_s
|
||||||
source_dirs = ["."] if source_dirs.empty?
|
source_dirs = ["."] if source_dirs.empty?
|
||||||
source_dirs = source_dirs.map do |s|
|
source_dirs = source_dirs.map do |s|
|
||||||
File.expand_path(s)
|
Pathname.new(File.expand_path(s)).cleanpath.to_s
|
||||||
end
|
end
|
||||||
files = Dir["#{build_dir}/**/*.gcda"] if files.empty?
|
files = Dir["#{build_dir}/**/*.gcda"] if files.empty?
|
||||||
files = files.map do |f|
|
files = files.map do |f|
|
||||||
File.expand_path(f)
|
Pathname.new(File.expand_path(f)).cleanpath.to_s
|
||||||
end
|
end
|
||||||
output_dir = File.expand_path(output_dir)
|
output_dir = Pathname.new(File.expand_path(output_dir)).cleanpath.to_s
|
||||||
|
file_coverages = {}
|
||||||
Dir.mktmpdir do |dir|
|
Dir.mktmpdir do |dir|
|
||||||
Dir.chdir(dir) do
|
Dir.chdir(dir) do
|
||||||
files.each do |f|
|
files.each do |f|
|
||||||
IO.popen(["gcov", "-bmi", f]) do |io|
|
stdout, stderr, status = Open3.capture3("gcov", "-bc", f)
|
||||||
io.read
|
gcov_files = Dir["*.gcov"]
|
||||||
|
gcov_files.each do |gcov_file|
|
||||||
|
GcovParser.parse(gcov_file, file_coverages, build_dir, source_dirs)
|
||||||
|
File.unlink(gcov_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
lib/gcovinator/file_coverage.rb
Normal file
4
lib/gcovinator/file_coverage.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module Gcovinator
|
||||||
|
class FileCoverage
|
||||||
|
end
|
||||||
|
end
|
28
lib/gcovinator/gcov_parser.rb
Normal file
28
lib/gcovinator/gcov_parser.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
module Gcovinator
|
||||||
|
module GcovParser
|
||||||
|
class << self
|
||||||
|
|
||||||
|
def parse(gcov_file, file_coverages, build_dir, source_dirs)
|
||||||
|
gcov_file = File.read(gcov_file)
|
||||||
|
file_coverage = nil
|
||||||
|
gcov_file.each_line do |line|
|
||||||
|
if line =~ /^\s+\S*:\s*\d*:Source:(.*)$/
|
||||||
|
filename = $1
|
||||||
|
unless Pathname.new(filename).absolute?
|
||||||
|
filename = Pathname.new(File.join(build_dir, filename)).cleanpath.to_s
|
||||||
|
end
|
||||||
|
filename = filename.gsub("\\", "/")
|
||||||
|
unless source_dirs.any? {|s| filename.start_with?("#{s}/")}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
file_coverages[filename] ||= FileCoverage.new
|
||||||
|
file_coverage = file_coverages[filename]
|
||||||
|
next
|
||||||
|
end
|
||||||
|
next unless file_coverage
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user