From 617f40c00b9df4f461e1ab77f8d625e9c9fbce6c Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:15:13 -0400 Subject: [PATCH] build(homebrew): normalize remapped LCOV source paths Updates `lcov_for_source_file_record` to normalize `SF:` paths with `Pathname.cleanpath` and correctly handle Homebrew/LLVM remapped relative paths (including `build/tests/src/...` and already-relative `src/...` entries). It now rewrites valid source paths to `src/...` and skips non-source records. Adds coverage assertions in the formula test to verify remapped, compile-dir-relative, relative, absolute, and excluded test paths are handled correctly. --- packaging/sunshine.rb | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/packaging/sunshine.rb b/packaging/sunshine.rb index 0b8d43c9231..4e7678ac615 100644 --- a/packaging/sunshine.rb +++ b/packaging/sunshine.rb @@ -367,11 +367,20 @@ def relative_lcov_record(record, source_prefixes) source_index = lines.index { |line| line.start_with?("SF:") } return unless source_index - source_path = lines[source_index].delete_prefix("SF:").strip - source_prefix = source_prefixes.find { |prefix| source_path.start_with?(prefix) } - return unless source_prefix + source_path = Pathname.new(lines[source_index].delete_prefix("SF:").strip).cleanpath.to_s + # Homebrew remaps the formula build path to ".". LLVM may then resolve that + # relative path from CMake's compilation directory at "build/tests". + relative_source_path = if source_path.start_with?("build/tests/src/") + source_path.delete_prefix("build/tests/") + elsif source_path.start_with?("src/") + source_path + else + source_prefix = source_prefixes.find { |prefix| source_path.start_with?(prefix) } + "src/#{source_path.delete_prefix(source_prefix)}" if source_prefix + end + return unless relative_source_path - lines[source_index] = "SF:src/#{source_path.delete_prefix(source_prefix)}\n" + lines[source_index] = "SF:#{relative_source_path}\n" "#{lines.join}end_of_record\n" end @@ -476,6 +485,42 @@ def caveats run_test_suite testpath generate_coverage_report testpath, ENV.fetch("HOMEBREW_BUILDPATH", "") end + + lcov = <<~LCOV + SF:./src/remapped.cpp + DA:1,1 + end_of_record + SF:build/tests/src/remapped_from_compile_dir.cpp + DA:1,1 + end_of_record + SF:src/relative.cpp + DA:1,1 + end_of_record + SF:#{testpath}/src/absolute.cpp + DA:1,1 + end_of_record + SF:./tests/excluded.cpp + DA:1,1 + end_of_record + SF:build/tests/tests/excluded_from_compile_dir.cpp + DA:1,1 + end_of_record + LCOV + expected_lcov = <<~LCOV + SF:src/remapped.cpp + DA:1,1 + end_of_record + SF:src/remapped_from_compile_dir.cpp + DA:1,1 + end_of_record + SF:src/relative.cpp + DA:1,1 + end_of_record + SF:src/absolute.cpp + DA:1,1 + end_of_record + LCOV + assert_equal expected_lcov, lcov_for_source_files(lcov, testpath) end end end