fix(tools): strip _nid_disambig before hashing the export name
This commit is contained in:
1 parent
9a0d098f73
commit
c4563f10df
2 files changed
+39
No files matched your search
@@ -16,6 +16,7 @@ import nid_names
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
PRX = ROOT / "core" / "libs" / "prx"
|
||||
POSTFIXES = ("_nid_postfix", "_nid_no_patch_cut", "_nid_no_patch")
|
||||
DISAMBIG = "_nid_disambig"
|
||||
NID_PATTERN = "[A-Za-z0-9+\\-]{11}"
|
||||
VABI = re.compile(r"\bAPS5_VABI\s+(\w+)\s*\(")
|
||||
TABLE_ENTRY = re.compile(r"sprx_dlsym\s*\(\s*__handle\s*,\s*\"(" + NID_PATTERN + r")\"")
|
||||
@@ -117,6 +118,16 @@ def base_of(name):
|
||||
return name, None
|
||||
|
||||
|
||||
def strip_disambig(name):
|
||||
pos = name.rfind(DISAMBIG)
|
||||
if pos == -1:
|
||||
return name
|
||||
tail = name[pos + len(DISAMBIG):]
|
||||
if tail and all(char in "0123456789" for char in tail):
|
||||
return name[:pos]
|
||||
return name
|
||||
|
||||
|
||||
def source_texts(module_dir):
|
||||
texts = []
|
||||
for path in sorted(module_dir.rglob("*")):
|
||||
@@ -167,6 +178,7 @@ def collect_provided(module_dir):
|
||||
continue
|
||||
if postfix is not None and postfix != "_nid_postfix":
|
||||
continue
|
||||
base = strip_disambig(base)
|
||||
nid = nid_names.compute_nid(base)
|
||||
if nid not in provided:
|
||||
if postfix is None:
|
||||
@@ -197,6 +209,7 @@ def collect_provided(module_dir):
|
||||
continue
|
||||
if postfix is not None and postfix != "_nid_postfix":
|
||||
continue
|
||||
base = strip_disambig(base)
|
||||
nid = nid_names.compute_nid(base)
|
||||
if nid not in provided:
|
||||
provided[nid] = f"through macro {macro} as {symbol}"
|
||||
|
||||
@@ -121,6 +121,32 @@ class ExportGapTests(unittest.TestCase):
|
||||
def test_postfix_name_provides_hashed_base_nid(self):
|
||||
self.assertTrue(provides("sceExampleBase_nid_postfix", nid_of("sceExampleBase")))
|
||||
|
||||
def test_disambig_postfix_provides_hashed_base_nid(self):
|
||||
self.assertTrue(provides("alias_nid_disambig12_nid_postfix", nid_of("alias")))
|
||||
|
||||
def test_bare_disambig_provides_hashed_base_nid(self):
|
||||
self.assertTrue(provides("foo_nid_disambig1", nid_of("foo")))
|
||||
|
||||
def test_disambig_non_digit_tail_left_alone(self):
|
||||
self.assertFalse(provides("foo_nid_disambigX", nid_of("foo")))
|
||||
self.assertTrue(provides("foo_nid_disambigX", nid_of("foo_nid_disambigX")))
|
||||
|
||||
def test_macro_disambig_postfix_counts_as_provided(self):
|
||||
nid = nid_names.compute_nid("alias")
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root, prx, tables = tree(directory)
|
||||
write_module(prx, MODULE, {"Export.cpp": (
|
||||
"int before(void) { return 0; }\n"
|
||||
"#define EXAMPLE_MACRO(NAME) int APS5_VABI NAME(void) { return 0; }\n"
|
||||
"EXAMPLE_MACRO(alias_nid_disambig12_nid_postfix)\n")})
|
||||
write_table(tables, MODULE, [nid])
|
||||
db = write_db(directory, [(nid, "alias")])
|
||||
out = Path(directory) / "out.txt"
|
||||
code, report = run_tool(root, prx, ["--module", MODULE, "--export-table", str(tables), "--db", str(db), "--out", str(out)])
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(out.read_text(encoding="utf-8"), "")
|
||||
self.assertIn("already provided", report)
|
||||
|
||||
def test_no_patch_cut_base_counts_as_literally_provided(self):
|
||||
base = "sceCutBase1"
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
|
||||
Reference in new issue
Block a user