From 048bc429422eb7d0d6c0c4e691a205355c3a178c Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 13 Jul 2021 19:14:53 +1000 Subject: [PATCH] tools/normalise_mpconfigport.py: Add script to normalise config. Signed-off-by: Damien George --- tools/normalise_mpconfigport.py | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tools/normalise_mpconfigport.py diff --git a/tools/normalise_mpconfigport.py b/tools/normalise_mpconfigport.py new file mode 100644 index 0000000000000..9439d229b4daa --- /dev/null +++ b/tools/normalise_mpconfigport.py @@ -0,0 +1,75 @@ +""" +Normalise an mpconfigport.h file by ordering config options, and removing any +that are the defaults. The standard order and defaults come from py/mpconfig.h. + +Run from the root of the repository. + +Example usage: + + python3 tools/normalise_mpconfigport.py ports/stm32/mpconfigport.h + +""" + +import collections, re, sys + + +regexs = ( + ("define", re.compile(r"#define (MICROPY_[A-Z0-9_]+) +(.+)")), + ("comment", re.compile(r"// (Extended modules)")), + ("comment_strip", re.compile(r"/\* (.+) \*/")), +) + + +def match_line(line): + for kind, regex in regexs: + m = regex.match(line) + if m: + return kind, m + return None, None + + +def parse_config(filename, parse_section_names=False): + config = collections.OrderedDict() + section_num = 0 + section_comment = None + with open(filename) as f: + for line in f: + kind, match = match_line(line) + if kind == "define": + if section_comment: + if parse_section_names: + config[f"_section{section_num}"] = section_comment + section_num += 1 + section_comment = None + config[match.group(1)] = match.group(2) + elif kind == "comment": + section_comment = match.group(1) + elif kind == "comment_strip": + section_comment = match.group(1).strip() + + return config + + +def main(): + defaults = parse_config("py/mpconfig.h", True) + port = parse_config(sys.argv[1]) + + # Print out the standard config options in order. + for k, v in defaults.items(): + if k.startswith("_section"): + print() + print(f"// {v}") + continue + if k in port: + if port[k] != v: + print("#define {:40}{}".format(k, port[k])) + del port[k] + + # Print out any remaining config options that are not standard ones. + if port: + print() + for k, v in port.items(): + print("#define {:40}{}".format(k, v)) + + +main() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy