Skip to content

Commit 7ca8a45

Browse files
committed
autogen: Generalize exceptions for macro patterns
Rather than hardcoding certain macro patterns `MLK_FOO_BAR_XXX` as acceptable, detect them and check that there exists at least one macro following the provided pattern (i.e., for `MLK_FOO_BAR_XXX`, exist that there is at least one macro starting with `MLK_FOO_BAR_`). Signed-off-by: Hanno Becker <[email protected]>
1 parent 58da580 commit 7ca8a45

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

scripts/autogen

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,13 +1572,28 @@ def get_config_options():
15721572
"MLK_BREAK_PCT", # Use in PCT breakage test]
15731573
"MLK_CONFIG_NO_ASM_VALUE_BARRIER", # TODO: Add to config?
15741574
"MLK_CHECK_APIS",
1575-
"MLK_CONFIG_API_XXX",
1576-
"MLK_USE_NATIVE_XXX",
15771575
]
15781576

15791577
return configs
15801578

15811579

1580+
def is_macro_pattern(m):
1581+
if not m.endswith("_XXX"):
1582+
return None
1583+
return m[:-4]
1584+
1585+
1586+
def is_valid_macro_pattern(m, macros):
1587+
pattern = is_macro_pattern(m)
1588+
if pattern is None:
1589+
return False
1590+
# Check that there is at least one macro following the pattern
1591+
for mp in macros:
1592+
if mp.startswith(pattern):
1593+
return True
1594+
return False
1595+
1596+
15821597
def check_macro_typos_in_file(filename, macro_check):
15831598
"""Checks for typos in MLK_XXX and MLKEM_XXX identifiers."""
15841599
status_update("check-macros", filename)
@@ -1591,9 +1606,14 @@ def check_macro_typos_in_file(filename, macro_check):
15911606
rest = m.group(2)
15921607
if macro_check(txt, rest, filename) is False:
15931608
line_no = content[: m.start()].count("\n") + 1
1594-
raise Exception(
1595-
f"Likely typo {txt} in {filename}:{line_no}? Not a defined macro."
1596-
)
1609+
if is_macro_pattern(txt):
1610+
raise Exception(
1611+
f"Likely typo {txt} in {filename}:{line_no}? No macro following the pattern exists"
1612+
)
1613+
else:
1614+
raise Exception(
1615+
f"Likely typo {txt} in {filename}:{line_no}? Not a defined macro nor valid pattern"
1616+
)
15971617

15981618

15991619
def get_syscaps():
@@ -1610,7 +1630,7 @@ def check_macro_typos():
16101630
macros.update(get_config_options())
16111631

16121632
def macro_check(m, rest, filename):
1613-
if m in macros:
1633+
if m in macros or is_valid_macro_pattern(m, macros):
16141634
return True
16151635

16161636
is_autogen = filename == "scripts/autogen"
@@ -1638,12 +1658,7 @@ def check_macro_typos():
16381658
if filename.endswith(".ml"):
16391659
return True
16401660

1641-
# 4. Exclude regexp patterns in `autogen`
1642-
if is_autogen:
1643-
if rest.startswith("\\") or m in ["MLK_XXX", "MLK_SOURCE_XXX"]:
1644-
return True
1645-
1646-
# 5. AWS-LC importer patch
1661+
# 4. AWS-LC importer patch
16471662
if is_autogen or filename == "integration/awslc/awslc.patch":
16481663
return True
16491664

0 commit comments

Comments
 (0)