scripts: Tidy linting tries to reduce filepaths

This CL makes tricium_clang_tidy attempt to find better file paths than
those reported by tidy that correspond to the same file.

BUG=b:241155489
TEST=lint_package --fetch-only

Change-Id: Ic94a3a9badfa8f2a2713dc8a4db78555175d5fea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4819573
Commit-Queue: Ryan Beltran <ryanbeltran@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Ryan Beltran <ryanbeltran@chromium.org>
diff --git a/scripts/lint_package.py b/scripts/lint_package.py
index 106bb07..baa1333 100644
--- a/scripts/lint_package.py
+++ b/scripts/lint_package.py
@@ -16,6 +16,7 @@
 
 from chromite.lib import build_target_lib
 from chromite.lib import commandline
+from chromite.lib import constants
 from chromite.lib import cros_build_lib
 from chromite.lib import portage_util
 from chromite.lib import terminal
@@ -56,6 +57,15 @@
     return package_infos
 
 
+def make_relative_to_cros(file_path: str) -> Path:
+    """removes /mnt/host/source from file_paths if present."""
+    path = Path(file_path)
+    try:
+        return path.relative_to(constants.CHROOT_SOURCE_ROOT)
+    except ValueError:
+        return path
+
+
 def format_lint(lint: toolchain.LinterFinding) -> Text:
     """Formats a lint for human-readable printing.
 
@@ -80,18 +90,19 @@
         background_color=terminal.Color.BLACK,
     )
     for loc in lint.locations:
+        filepath = make_relative_to_cros(loc.filepath)
         if not lines:
             location_prefix = f"\n{linter_prefix} In"
         else:
             location_prefix = "   and in"
         if loc.line_start != loc.line_end:
             lines.append(
-                f"{location_prefix} '{loc.filepath}' "
+                f"{location_prefix} '{filepath}' "
                 f"lines {loc.line_start}-{loc.line_end}:"
             )
         else:
             lines.append(
-                f"{location_prefix} '{loc.filepath}' line {loc.line_start}:"
+                f"{location_prefix} '{filepath}' line {loc.line_start}:"
             )
     message_lines = lint.message.split("\n")
     for line in message_lines: