py/makemoduledefs.py: Allow multiple ways to register a module.

For example, ussl can come from axtls or mbedtls. If neither are enabled
then don't try and set an empty definition twice, and only include it
once in MICROPY_REGISTERED_MODULES.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2022-04-20 16:05:44 +10:00
parent bc42db4496
commit 469450171f
1 changed files with 7 additions and 4 deletions

View File

@ -59,18 +59,21 @@ def generate_module_table_header(modules):
"""
# Print header file for all external modules.
mod_defs = []
mod_defs = set()
print("// Automatically generated by makemoduledefs.py.\n")
for module_name, obj_module, enabled_define in modules:
mod_def = "MODULE_DEF_{}".format(module_name.upper())
mod_defs.append(mod_def)
mod_defs.add(mod_def)
print(
(
"#if ({enabled_define})\n"
" extern const struct _mp_obj_module_t {obj_module};\n"
" #undef {mod_def}\n"
" #define {mod_def} {{ MP_ROM_QSTR({module_name}), MP_ROM_PTR(&{obj_module}) }},\n"
"#else\n"
" #define {mod_def}\n"
" #ifndef {mod_def}\n"
" #define {mod_def}\n"
" #endif\n"
"#endif\n"
).format(
module_name=module_name,
@ -82,7 +85,7 @@ def generate_module_table_header(modules):
print("\n#define MICROPY_REGISTERED_MODULES \\")
for mod_def in mod_defs:
for mod_def in sorted(mod_defs):
print(" {mod_def} \\".format(mod_def=mod_def))
print("// MICROPY_REGISTERED_MODULES")