add --prefix option
This commit is contained in:
parent
6edbcff533
commit
4614eaea60
@ -12,7 +12,7 @@ module Gcovinator
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def run(build_dir, source_dirs, files, output_dir)
|
def run(build_dir, source_dirs, files, output_dir, prefix)
|
||||||
build_dir = Pathname.new(File.expand_path(build_dir)).cleanpath.to_s
|
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|
|
||||||
@ -23,6 +23,7 @@ module Gcovinator
|
|||||||
Pathname.new(File.expand_path(f)).cleanpath.to_s
|
Pathname.new(File.expand_path(f)).cleanpath.to_s
|
||||||
end
|
end
|
||||||
output_dir = Pathname.new(File.expand_path(output_dir)).cleanpath.to_s
|
output_dir = Pathname.new(File.expand_path(output_dir)).cleanpath.to_s
|
||||||
|
prefix = Pathname.new(File.expand_path(prefix)).cleanpath.to_s
|
||||||
file_coverages = {}
|
file_coverages = {}
|
||||||
Dir.mktmpdir do |dir|
|
Dir.mktmpdir do |dir|
|
||||||
Dir.chdir(dir) do
|
Dir.chdir(dir) do
|
||||||
@ -38,7 +39,7 @@ module Gcovinator
|
|||||||
end
|
end
|
||||||
FileUtils.mkdir_p(output_dir)
|
FileUtils.mkdir_p(output_dir)
|
||||||
file_reports = file_coverages.each_with_index.map do |(source_file_name, file_coverage), i|
|
file_reports = file_coverages.each_with_index.map do |(source_file_name, file_coverage), i|
|
||||||
FileReport.new(source_file_name, file_coverage, source_dirs, output_dir, sprintf("s%04d.html", i))
|
FileReport.new(source_file_name, file_coverage, prefix, output_dir, sprintf("s%04d.html", i))
|
||||||
end
|
end
|
||||||
IndexReport.new(output_dir, file_reports)
|
IndexReport.new(output_dir, file_reports)
|
||||||
end
|
end
|
||||||
|
@ -11,6 +11,7 @@ module Gcovinator
|
|||||||
build_dir = "."
|
build_dir = "."
|
||||||
source_dirs = []
|
source_dirs = []
|
||||||
output_dir = "coverage"
|
output_dir = "coverage"
|
||||||
|
prefix = "."
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
|
|
||||||
@ -35,6 +36,10 @@ module Gcovinator
|
|||||||
output_dir = o
|
output_dir = o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("-p PREFIX", "--prefix PREFIX", "Prefix path to strip from source file paths. Defaults to '.' if not specified.") do |p|
|
||||||
|
prefix = p
|
||||||
|
end
|
||||||
|
|
||||||
opts.on("-s SRCDIR", "--source-dir SRCDIR", "Specify a source directory. Reports will only be generated for sources under a specified source directory. Multiple source directories may be specified. Defaults to '.' if not specified.") do |s|
|
opts.on("-s SRCDIR", "--source-dir SRCDIR", "Specify a source directory. Reports will only be generated for sources under a specified source directory. Multiple source directories may be specified. Defaults to '.' if not specified.") do |s|
|
||||||
source_dirs << s
|
source_dirs << s
|
||||||
end
|
end
|
||||||
@ -46,7 +51,7 @@ module Gcovinator
|
|||||||
|
|
||||||
end.parse!(argv)
|
end.parse!(argv)
|
||||||
|
|
||||||
Gcovinator.run(build_dir, source_dirs, argv, output_dir)
|
Gcovinator.run(build_dir, source_dirs, argv, output_dir, prefix)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,8 @@ module Gcovinator
|
|||||||
attr_reader :source_file_name
|
attr_reader :source_file_name
|
||||||
attr_reader :report_file_name
|
attr_reader :report_file_name
|
||||||
|
|
||||||
def initialize(source_file_name, file_coverage, source_dirs, output_dir, report_file_name)
|
def initialize(source_file_name, file_coverage, prefix, output_dir, report_file_name)
|
||||||
@source_file_name = clean_source_file_name(source_file_name, source_dirs)
|
@source_file_name = clean_source_file_name(source_file_name, prefix)
|
||||||
@report_file_name = report_file_name
|
@report_file_name = report_file_name
|
||||||
@total_lines = 0
|
@total_lines = 0
|
||||||
@covered_lines = 0
|
@covered_lines = 0
|
||||||
@ -20,12 +20,10 @@ module Gcovinator
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def clean_source_file_name(source_file_name, source_dirs)
|
def clean_source_file_name(source_file_name, prefix)
|
||||||
source_dirs.each do |source_dir|
|
prefix_test = "#{prefix}/"
|
||||||
prefix_test = "#{source_dir}/"
|
if source_file_name.start_with?(prefix_test)
|
||||||
if source_file_name.start_with?(prefix_test)
|
return source_file_name[prefix_test.size, source_file_name.size]
|
||||||
return source_file_name[prefix_test.size, source_file_name.size]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
source_file_name
|
source_file_name
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user