summaryrefslogtreecommitdiffstatshomepage
path: root/py/makeqstrdefs.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-05-31 17:10:14 +1000
committerDamien George <damien@micropython.org>2022-06-02 16:29:53 +1000
commit47f634300c5572571816817f16836113c98814ae (patch)
treec8ca63093fd20744f2596e81e706443cbcd32fd8 /py/makeqstrdefs.py
parent340872cfdd724b7acc6768a22d90a84834b0e7b5 (diff)
downloadmicropython-47f634300c5572571816817f16836113c98814ae.tar.gz
micropython-47f634300c5572571816817f16836113c98814ae.zip
py: Change makemoduledefs process so it uses output of qstr extraction.
This cleans up the parsing of MP_REGISTER_MODULE() and generation of genhdr/moduledefs.h so that it uses the same process as compressed error string messages, using the output of qstr extraction. This makes sure all MP_REGISTER_MODULE()'s that are part of the build are correctly picked up. Previously the extraction would miss some (eg if you had a mod.c file in the board directory for an stm32 board). Build speed is more or less unchanged. Thanks to @stinos for the ports/windows/msvc/genhdr.targets changes. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/makeqstrdefs.py')
-rw-r--r--py/makeqstrdefs.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py
index 1a63bd39a9..85e04b9449 100644
--- a/py/makeqstrdefs.py
+++ b/py/makeqstrdefs.py
@@ -21,6 +21,9 @@ _MODE_QSTR = "qstr"
# Extract MP_COMPRESSED_ROM_TEXT("") macros. (Which come from MP_ERROR_TEXT)
_MODE_COMPRESS = "compress"
+# Extract MP_REGISTER_MODULE(...) macros.
+_MODE_MODULE = "module"
+
def is_c_source(fname):
return os.path.splitext(fname)[1] in [".c"]
@@ -85,6 +88,8 @@ def process_file(f):
re_match = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+")
elif args.mode == _MODE_COMPRESS:
re_match = re.compile(r'MP_COMPRESSED_ROM_TEXT\("([^"]*)"\)')
+ elif args.mode == _MODE_MODULE:
+ re_match = re.compile(r"MP_REGISTER_MODULE\(.*?,\s*.*?,\s*.*?\);")
output = []
last_fname = None
for line in f:
@@ -106,7 +111,7 @@ def process_file(f):
if args.mode == _MODE_QSTR:
name = match.replace("MP_QSTR_", "")
output.append("Q(" + name + ")")
- elif args.mode == _MODE_COMPRESS:
+ elif args.mode in (_MODE_COMPRESS, _MODE_MODULE):
output.append(match)
if last_fname:
@@ -141,6 +146,8 @@ def cat_together():
mode_full = "QSTR"
if args.mode == _MODE_COMPRESS:
mode_full = "Compressed data"
+ elif args.mode == _MODE_MODULE:
+ mode_full = "Module registrations"
if old_hash != new_hash:
print(mode_full, "updated")
try:
@@ -201,7 +208,7 @@ if __name__ == "__main__":
args.output_dir = sys.argv[4]
args.output_file = None if len(sys.argv) == 5 else sys.argv[5] # Unused for command=split
- if args.mode not in (_MODE_QSTR, _MODE_COMPRESS):
+ if args.mode not in (_MODE_QSTR, _MODE_COMPRESS, _MODE_MODULE):
print("error: mode %s unrecognised" % sys.argv[2])
sys.exit(2)