mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-29 12:15:39 +00:00
Merge pull request #10942 from mashingaan/fix/import-audit-bare-filenames
fix(tools): reject bare module filename aliases
This commit is contained in:
2 files changed
+33
-5
No files matched your search
@@ -687,9 +687,8 @@ def module_stem(name, fold):
|
||||
name = name.lower()
|
||||
for suffix in MODULE_FILE_SUFFIXES:
|
||||
if len(name) > len(suffix) and name.endswith(suffix):
|
||||
name = name[:-len(suffix)]
|
||||
break
|
||||
return name
|
||||
return name[:-len(suffix)]
|
||||
return None
|
||||
|
||||
|
||||
class ModuleNames(set):
|
||||
@@ -699,10 +698,14 @@ class ModuleNames(set):
|
||||
def __init__(self, names=(), fold=False):
|
||||
super().__init__(names)
|
||||
self.fold = fold
|
||||
self.stems = {module_stem(name, fold) for name in self}
|
||||
self.files = {name.lower() if fold else name for name in self}
|
||||
self.stems = {stem for name in self if (stem := module_stem(name, fold)) is not None}
|
||||
|
||||
def __contains__(self, library):
|
||||
return isinstance(library, str) and module_stem(library, self.fold) in self.stems
|
||||
if not isinstance(library, str):
|
||||
return False
|
||||
filename = library.lower() if self.fold else library
|
||||
return filename in self.files or module_stem(library, self.fold) in self.stems
|
||||
|
||||
|
||||
def classify(nid, library, providers, stubs, modules, partial=frozenset()):
|
||||
|
||||
@@ -781,6 +781,31 @@ class ImportAuditTests(unittest.TestCase):
|
||||
record = next(record for record in data["imports"] if record["library"] == "shipping.debug_prx")
|
||||
self.assertEqual(record["class"], "module")
|
||||
|
||||
def test_module_suffix_aliases_require_suffixes_on_both_filenames(self):
|
||||
work = self.work
|
||||
registry, report = work.root / "game.registry.json", work.root / "audit.json"
|
||||
cases = (("shipping.prx", "shipping"), ("shipping", "shipping.prx"),
|
||||
("shipping.data", "shipping.data.prx"), (".prx", ".sprx"))
|
||||
for windows in (False, True):
|
||||
(work.libs / "libc.prx").write_bytes(build_pe([]) if windows else exporting())
|
||||
for filename, alias in cases:
|
||||
module = work.modules / filename
|
||||
module.write_bytes(exporting("AAAAAAAAAAA"))
|
||||
try:
|
||||
for needed in (filename, alias):
|
||||
with self.subTest(windows=windows, filename=filename, needed=needed):
|
||||
write_registry(registry, [("AAAAAAAAAAA", needed)])
|
||||
import_audit.needed_registry_path(registry).write_text(json.dumps([needed]), encoding="utf-8")
|
||||
code, _, err = work.run(registry, "--json", str(report))
|
||||
exact = needed == filename
|
||||
self.assertEqual((code, err), (0 if exact else 1, ""))
|
||||
data = json.loads(report.read_text(encoding="utf-8"))
|
||||
self.assertEqual(data["missing_libraries"], {} if exact else {needed: 1})
|
||||
self.assertEqual(data["imports"][0]["class"], "module" if exact else "absent")
|
||||
self.assertEqual(data["references"], 1)
|
||||
finally:
|
||||
module.unlink()
|
||||
|
||||
def test_module_names_ignore_case_for_windows_output_only(self):
|
||||
imports = [("AAAAAAAAAAA", "SDK-Shipping.debug_prx", False)]
|
||||
records, missing = import_audit.audit(imports, {}, {}, set(), import_audit.ModuleNames({"sdk-shipping.prx"}, fold=True))
|
||||
|
||||
Reference in new issue
Block a user