From 2c95cf5a1f9f2eb0f4e384adba7401105106449a Mon Sep 17 00:00:00 2001 From: Grigory Entin Date: Thu, 5 Oct 2023 16:57:09 +0200 Subject: [PATCH 1/2] Added primitive support for COVERAGE_PATH_EQUIVALENCE. --- lib/slather/coverage_info.rb | 6 +++++- lib/slather/project.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/slather/coverage_info.rb b/lib/slather/coverage_info.rb index 1fad52b8..0a4d9005 100644 --- a/lib/slather/coverage_info.rb +++ b/lib/slather/coverage_info.rb @@ -71,7 +71,11 @@ def rate_branches_tested end def source_file_pathname_relative_to_repo_root - source_file_pathname.realpath.relative_path_from(Pathname("./").realpath) + test_path=source_file_pathname + if ENV["COVERAGE_PATH_EQUIVALENCE"] + test_path=Pathname("." + "#{source_file_pathname}".delete_prefix(ENV["COVERAGE_PATH_EQUIVALENCE"].delete_suffix(",."))) + end + test_path.realpath.relative_path_from(Pathname("./").realpath) end def ignored? diff --git a/lib/slather/project.rb b/lib/slather/project.rb index 22534317..82385d03 100755 --- a/lib/slather/project.rb +++ b/lib/slather/project.rb @@ -269,6 +269,9 @@ def unsafe_llvm_cov_export_output(binary_path) if self.arch llvm_cov_args << "--arch" << self.arch end + if ENV["COVERAGE_PATH_EQUIVALENCE"] + llvm_cov_args << "-path-equivalence=#{ENV["COVERAGE_PATH_EQUIVALENCE"]}" + end `xcrun llvm-cov #{llvm_cov_args.shelljoin}` end private :unsafe_llvm_cov_export_output @@ -293,6 +296,9 @@ def unsafe_profdata_llvm_cov_output(binary_path, source_files) if self.arch llvm_cov_args << "--arch" << self.arch end + if ENV["COVERAGE_PATH_EQUIVALENCE"] + llvm_cov_args << "-path-equivalence=#{ENV["COVERAGE_PATH_EQUIVALENCE"]}" + end # POSIX systems have an ARG_MAX for the maximum total length of the command line, so the command may fail with an error message of "Argument list too long". # Using the xargs command we can break the list of source_files into sublists small enough to be acceptable. From be06263ffa69ee538958a384c427916f3fa97cf4 Mon Sep 17 00:00:00 2001 From: Grigory Entin Date: Tue, 10 Oct 2023 09:19:11 +0200 Subject: [PATCH 2/2] Fixed support for sources that are actually recompiled. --- lib/slather/coverage_info.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/slather/coverage_info.rb b/lib/slather/coverage_info.rb index 0a4d9005..85c963f9 100644 --- a/lib/slather/coverage_info.rb +++ b/lib/slather/coverage_info.rb @@ -72,8 +72,12 @@ def rate_branches_tested def source_file_pathname_relative_to_repo_root test_path=source_file_pathname - if ENV["COVERAGE_PATH_EQUIVALENCE"] - test_path=Pathname("." + "#{source_file_pathname}".delete_prefix(ENV["COVERAGE_PATH_EQUIVALENCE"].delete_suffix(",."))) + equivalence=ENV["COVERAGE_PATH_EQUIVALENCE"] + if equivalence + orig_prefix=equivalence.delete_suffix(",.") + if "#{source_file_pathname}".start_with?(orig_prefix) + test_path=Pathname("." + "#{source_file_pathname}".delete_prefix(orig_prefix)) + end end test_path.realpath.relative_path_from(Pathname("./").realpath) end