From f8488618e413b2809c0d56d51d4baf6c68b33d4e Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 11 Sep 2018 14:15:59 +1000 Subject: [PATCH 1/2] cmodules: update cmodules.h generation When building module list for header, scan files for existing module definitions for use in preference to generating one automatically. --- tools/gen-cmodules.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/gen-cmodules.py b/tools/gen-cmodules.py index 524e3c03d3335..83ba36fd6b2ce 100755 --- a/tools/gen-cmodules.py +++ b/tools/gen-cmodules.py @@ -6,6 +6,7 @@ import sys import os +import re from glob import glob def update_modules(path): @@ -13,15 +14,26 @@ def update_modules(path): for module in sorted(os.listdir(path)): if not os.path.isfile('%s/%s/micropython.mk' % (path, module)): continue # not a module - modules.append(module) + + defined = False + for (root, dirs, files) in os.walk(os.path.join(path, module)): + for f in files: + with open(os.path.join(root, f), 'r') as modfile: + for line in modfile: + for module in re.findall(r' mp_obj_module_t (\S+?)_(\S+) ', line): + defined = True + modules.append(module) + + if not defined: + modules.append((module, 'user_cmodule')) # Print header file for all external modules. print('// Automatically generated by genmodules.py.\n') for module in modules: - print('extern const struct _mp_obj_module_t %s_user_cmodule;' % module) + print('extern const struct _mp_obj_module_t %s_%s;' % module) print('\n#define MICROPY_EXTRA_BUILTIN_MODULES \\') for module in modules: - print(' { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_PTR(&%s_user_cmodule) }, \\' % (module, module)) + print(' { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_PTR(& %s_%s) }, \\' % (module[0], module[0], module[1])) print() if __name__ == '__main__': From d35dca92929147ce6fd3f26f29d9862d4f27ebbd Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 11 Sep 2018 14:19:11 +1000 Subject: [PATCH 2/2] cmodules: remove the need to link c files into build folder Linking the c files in to build folder complicates compilation and breaks debugging on windows. --- py/mkenv.mk | 1 - py/mkrules.mk | 4 ---- py/py.mk | 3 +-- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/py/mkenv.mk b/py/mkenv.mk index 49697d4068df2..9217172a3a977 100644 --- a/py/mkenv.mk +++ b/py/mkenv.mk @@ -41,7 +41,6 @@ RM = rm ECHO = @echo CP = cp MKDIR = mkdir -LN = ln SED = sed PYTHON = python diff --git a/py/mkrules.mk b/py/mkrules.mk index 0a5b0085690dd..07a250a2f46e2 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -128,10 +128,6 @@ $(BUILD)/genhdr/cmodules.h: | $(HEADER_BUILD)/mpversion.h @$(ECHO) "GEN $@" $(Q)$(GEN_CMODULES) $(USER_C_MODULES) > $@ -# make sure C modules are put in the build directory -$(BUILD)/cmodules: - @$(LN) -sf "$(realpath $(USER_C_MODULES))" $(BUILD)/cmodules - ifneq ($(PROG),) # Build a standalone executable (unix does this) diff --git a/py/py.mk b/py/py.mk index 3b2bc587a5bcc..8616d6b78b5d9 100644 --- a/py/py.mk +++ b/py/py.mk @@ -107,8 +107,7 @@ endif ifneq ($(USER_C_MODULES),) CFLAGS_MOD += -DMICROPY_CMODULES_INCLUDE_H='"genhdr/cmodules.h"' include $(USER_C_MODULES)/*/micropython.mk -SRC_MOD += $(addprefix $(BUILD)/cmodules/, $(SRC_USERMOD)) -$(SRC_MOD) : | $(BUILD)/cmodules +SRC_MOD += $(addprefix $(USER_C_MODULES)/, $(SRC_USERMOD)) SRC_QSTR += $(BUILD)/genhdr/cmodules.h endif