From 209c682ce90ff98b487debcc71c47f64317a845e Mon Sep 17 00:00:00 2001 From: Less/Rikki <86894501+lesshonor@users.noreply.github.com> Date: Tue, 28 Mar 2023 21:51:14 -0400 Subject: [PATCH] [CI] detect clang-formatted VIAL_KEYBOARD_UID (#428) * fix: detect clang-formatted VIAL_KEYBOARD_UIDs * style: match UID output to "About..." in Vial GUI --- util/ci_vial_verify_uid.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/util/ci_vial_verify_uid.py b/util/ci_vial_verify_uid.py index a07cb24de5..5f98be7c2d 100755 --- a/util/ci_vial_verify_uid.py +++ b/util/ci_vial_verify_uid.py @@ -1,33 +1,33 @@ #!/usr/bin/env python3 from glob import glob -import os +from pathlib import Path import re import sys import struct from collections import defaultdict - def main(): + + VIAL_UID_REGEX = re.compile(r"#\s*define\s+VIAL_KEYBOARD_UID\s+(?:\\(?:\n|\r)\s*)*{\s*((?:0(?:x|X)(?:[0-9a-fA-F]){2}\s*,\s*){7}(?:0(?:x|X)(?:[0-9a-fA-F]){2}))\s*}") + error = 0 uid_to_keyboards = defaultdict(set) for filename in glob("keyboards/**/vial.json", recursive=True): keyboard = filename[10:-10].split("/keymaps/")[0] - path = os.path.dirname(filename) + dirname = Path(filename).parents[0] uid = None + while True: - config_h = os.path.join(path, "config.h") - if os.path.exists(config_h): - with open(config_h, "r") as inf: - for line in inf: - uid = re.findall(r"#define.*VIAL_KEYBOARD_UID.*{(.*)}", line) - if uid: - break + config_h = dirname.joinpath("config.h") + if config_h.exists() and config_h.stat().st_size < 100000: + content = config_h.read_text() + uid = VIAL_UID_REGEX.search(content) if uid: break - path = os.path.dirname(path) - if path.endswith("keyboards"): + dirname = dirname.parents[0] + if dirname.match("keyboards"): break if not uid: @@ -35,7 +35,8 @@ def main(): error = 1 continue - uid = uid[0].split(",") + uid = uid[1].split(",") + uid.reverse() uid = [int(x, 16) for x in uid] uid = struct.pack("BBBBBBBB", *uid).hex() uid_to_keyboards[uid].add(keyboard)