Skip to content

Commit 47f22c6

Browse files
libretroadminLibretroAdmin
authored andcommitted
tools/settings_migrate_group: keep trailing reference rows literal
A table can mix rows of its own with rows whose token strings are already owned by another def file; the owned rows keep their literal descriptor after the generated include, preserving order, and only trailing reference rows are supported - anything else still fails with the owner named. The audio skew group references the microphone block frames setting and surfaced the class.
1 parent 11cc9fe commit 47f22c6

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

tools/settings_migrate_group.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ def guard_of(text, pat):
146146
assert rows and len(rows) == len(re.findall(r'SDESC_\w+_ROW(?:_P|_DS|_EX)?\(', tm.group(1))), (len(rows), tm.group(1)[:200])
147147

148148
us = open('intl/msg_hash_us.h').read()
149+
ref_tokens = set()
149150
usval, ussub, usspan, uscmt = {}, {}, [], {}
150151
for k, f, T, a in rows:
151152
m = re.search(r'MSG_HASH\(\s*(/\*.*?\*/)?\s*\n?\s*MENU_ENUM_LABEL_VALUE_%s,\s*\n?\s*(%s)\s*\n?\s*\)\n?' % (T, CSTR), us)
152153
if not m:
153154
_own = run("grep -lE 'S_\\w*\\((\\w+, *)?%s,' settings/*.h" % T).stdout.strip()
154-
assert not _own, ('token %s strings are owned by %s; this table only '
155-
'references it and needs no migration' % (T, _own))
155+
if _own:
156+
ref_tokens.add(T)
157+
continue
156158
assert m, ('VALUE', T)
157159
usval[T] = re.sub(r'\s*\n\s*', ' ', m.group(2)); usspan.append((m.start(), m.end()))
158160
if m.group(1):
@@ -162,6 +164,21 @@ def guard_of(text, pat):
162164
ussub[T] = re.sub(r'\s*\n\s*', ' ', m.group(2)); usspan.append((m.start(), m.end()))
163165
if m.group(1):
164166
uscmt[T] = (uscmt.get(T, '') + ' ' + m.group(1)).strip()
167+
if ref_tokens:
168+
_tail = [r for r in rows if r[2] in ref_tokens]
169+
assert rows[len(rows)-len(_tail):] == _tail, 'reference rows must trail the table'
170+
_ref_literals = []
171+
for _k3, _f3, _t3, _a3 in _tail:
172+
_rm3 = re.search(r'[ \t]*SDESC_\w+_ROW(?:_P|_DS|_EX)?\(\s*%s,\s*%s,(?:[^()]|\([^()]*\))*\),?' % (_f3, _t3), body)
173+
assert _rm3, _t3
174+
_rl3 = _rm3.group(0).strip()
175+
for _g3 in reversed(guards.get(_f3 or _t3, ())):
176+
_rl3 = _g3 + '\n ' + _rl3 + '\n#endif'
177+
_ref_literals.append(_rl3)
178+
rows = [r for r in rows if r[2] not in ref_tokens]
179+
print(' note: %d reference row(s) stay literal after the include' % len(_ref_literals))
180+
else:
181+
_ref_literals = []
165182
lblstr = open('msg_hash_lbl_str.h').read()
166183
names, lblstr_span = {}, []
167184
for k, f, T, a in rows:
@@ -373,6 +390,8 @@ def _cond(g):
373390
mk_menu = lambda b, _s: ' \\\n ' + MENU_EMIT[b]
374391
new_body = ('/* GENERATED: rows come from %s in order. */\n' % DEF
375392
+ defs(mk_menu) + '\n#include "../settings/%s"\n' % DEF + UNDEFS)
393+
if _ref_literals:
394+
new_body += '\n' + '\n'.join(' ' + _r for _r in _ref_literals)
376395
ms = ms[:tm.start(1)] + new_body + ms[tm.end(1):]
377396
open('menu/menu_setting.c','w').write(ms)
378397
print("surgeries ok")

0 commit comments

Comments
 (0)