summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-02-17 10:08:01 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-02-17 10:54:14 +1000
commite5d8af9711516385f8346c9e077692b29c914478 (patch)
treee04c69ff1e4475b8eec302cce583b310ce327f04 /scripts
parentff19ac58e14e319afbc33aa485af4b4370b2af2e (diff)
scripts: make sure all "Use: XK_Foo" comments point to existing symbols
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/keysym-generator.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/scripts/keysym-generator.py b/scripts/keysym-generator.py
index c21ba0e..e0db965 100755
--- a/scripts/keysym-generator.py
+++ b/scripts/keysym-generator.py
@@ -31,6 +31,22 @@ def die(msg):
sys.exit(1)
+def all_keysyms(directory):
+ """
+ Extract the key names for all keysyms we have in our repo and return
+ them as list.
+ """
+ keysym_names = []
+ pattern = re.compile(r"^#define\s+(?P<name>\w+)\s+(0x[0-9A-Fa-f]+)")
+ for path in directory.glob("*keysym*.h"):
+ with open(path) as fd:
+ for line in fd:
+ match = re.match(pattern, line)
+ if match:
+ keysym_names.append(match.group("name"))
+ return keysym_names
+
+
class Kernel(object):
"""
Wrapper around the kernel git tree to simplify searching for when a
@@ -158,7 +174,7 @@ def verify(ns):
)
# This is the comment pattern we expect
expected_comment_pattern = re.compile(
- r"/\* Use: \w+\t+_EVDEVK\(0x(?P<value>[0-9A-F]{3})\)\t+ (v[2-6]\.[0-9]+(\.[0-9]+)?)? +KEY_\w+ \*/"
+ r"/\* Use: (?P<name>\w+)\t+_EVDEVK\(0x(?P<value>[0-9A-F]{3})\)\t+ (v[2-6]\.[0-9]+(\.[0-9]+)?)? +KEY_\w+ \*/"
)
# Some patterns to spot specific errors, just so we can print useful errors
@@ -175,6 +191,8 @@ def verify(ns):
all_defines = []
+ all_keysym_names = all_keysyms(ns.header.parent)
+
class ParserError(Exception):
pass
@@ -216,6 +234,10 @@ def verify(ns):
if keycode == last_keycode:
error("Duplicate keycode", line)
last_keycode = keycode
+
+ name = match.group("name")
+ if name not in all_keysym_names:
+ error(f"Unknown keysym {name}", line)
elif re.match(hex_pattern, line):
logger.warning(f"Unexpected hex code in {line}")
continue
@@ -417,6 +439,8 @@ def main():
if not ns.header:
ns.header = find_xf86keysym_header()
+ else:
+ ns.header = Path(ns.header)
if ns.command is None:
parser.error("Invalid or missing command")