From de1b4c4e6a77ba7da12a8224e1741726ee68ab6b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 3 Sep 2026 21:54:47 +0200 Subject: [PATCH] refactor: resolve subproject paths by suffix --- scripts/profile_sync.py | 29 +++++++++++++++++++++++++++-- tests/test_profile_sync.py | 12 ++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index 79eb6ff3..998a4e6d 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -237,6 +237,7 @@ _BINARY_SUFFIXES = ( ".dll", ".exe", ".so", ".dylib", ".apk", ".elf", ".o", ".a", ".jar", ".dex", ) _HEX_ADDRESS_RE = re.compile(r"\b0x[0-9a-fA-F]{2,}") +_VERSION_WORD_RE = re.compile(r"v?\d+(\.\d+)+[\w.-]*") def is_binary_citation(path: str) -> bool: @@ -250,7 +251,9 @@ def is_binary_citation(path: str) -> bool: if _HEX_ADDRESS_RE.search(path): return True if " " not in path: - return False + # A bare `DesktopKinect.dll` names a shipped library, never a source + # file: no directory, no line, only its import table to read. + return "/" not in path and path.lower().endswith(_BINARY_SUFFIXES) head = path.split(" ", 1)[0] if head.lower().endswith(_BINARY_SUFFIXES): return True @@ -268,7 +271,13 @@ def strip_repo_word(path: str, known=frozenset()) -> str: return path head, _, tail = path.partition(" ") if head.lower() in known and tail and "/" not in head and "." not in head: - return tail.strip() + tail = tail.strip() + # `ArcadeFlashWeb v1.0.2 flash/flash.html` names the release the file + # was read from; the version is not part of the path either. + version, _, rest = tail.partition(" ") + if rest and _VERSION_WORD_RE.fullmatch(version): + return rest.strip() + return tail return path @@ -1254,6 +1263,22 @@ def build_report( # 266-line Windows configure.ac cannot carry line 754. if len(matches) <= 4: candidates.extend(m for m in matches if m not in candidates) + elif not any( + upstream.fetch_file(v.repo, sha, path, cache_dir, offline) is not None + for v in views for sha in (v.pin, v.head) + ): + # A path written from a subproject directory of a monorepo: + # `src/main/Main.cc` in emu-ex-plus-alpha is PCE.emu/src/main/Main.cc + # for one profile and C64.emu/src/main/Main.cc for another. The + # tree is searched by suffix and the cited directories decide. + suffix = "/" + path + for view in views: + _, tree = _context_for(view) + matches = [p for p in tree or [] if p.endswith(suffix)] + if len(matches) > 1: + matches = narrow_by_cited(matches, cited_dirs) + if len(matches) <= 4: + candidates.extend(m for m in matches if m not in candidates) def score(lines) -> int: """How well a repository's cited line matches what the ref means. diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index ae882faa..1c0fcd1e 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -472,6 +472,10 @@ class TestBinaryCitation(unittest.TestCase): def test_section_name_is_binary(self): self.assertTrue(profile_sync.is_binary_citation(".rdata dialog filter")) + def test_bare_library_name_is_binary(self): + self.assertTrue(profile_sync.is_binary_citation("DesktopKinect.dll")) + self.assertFalse(profile_sync.is_binary_citation("Makefile")) + def test_a_source_path_is_not_binary(self): for path in ("src/foo.c", "libs/libCg.so", "Source/Core/hook.c", "resources/font.h"): self.assertFalse(profile_sync.is_binary_citation(path), path) @@ -499,6 +503,14 @@ class TestRepoWord(unittest.TestCase): "FPLoader.cpp", ) + def test_release_version_after_the_repository_word_is_dropped(self): + self.assertEqual( + profile_sync.strip_repo_word( + "ArcadeFlashWeb v1.0.2 flash/flash.html", {"arcadeflashweb"} + ), + "flash/flash.html", + ) + def test_undeclared_project_word_stays(self): self.assertEqual( profile_sync.strip_repo_word("munt ROMInfo.cpp", {"bam_fploader"}),