diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-01-20 11:52:12 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-01-20 11:52:12 +0200 |
commit | 640e0b221e972f9a2da2d870bf3fc5a93c18f0ec (patch) | |
tree | 0af9af3d5d8b1bcca3bcbae917e19e8a03a5a82c /tools | |
parent | 438b3d26b5337493dfe345495605fe08ea306bf9 (diff) | |
download | micropython-640e0b221e972f9a2da2d870bf3fc5a93c18f0ec.tar.gz micropython-640e0b221e972f9a2da2d870bf3fc5a93c18f0ec.zip |
py: Implement very simple frozen modules support.
Only modules (not packages) supported now. Source modules can be converted
to frozen module structures using tools/make-frozen.py script.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/make-frozen.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/make-frozen.py b/tools/make-frozen.py new file mode 100755 index 0000000000..b053afa08e --- /dev/null +++ b/tools/make-frozen.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# +# Create frozen modules structure for MicroPython. +# +# Usage: +# +# Have a directory with modules to be frozen (only modules, not packages +# supported so far): +# +# frozen/foo.py +# frozen/bar.py +# +# Run script, passing path to the directory above: +# +# ./make-frozen.py frozen > frozen.c +# +# Include frozen.c in your build, having defined MICROPY_MODULE_FROZEN in +# config. +# +import sys +import os + + +def module_name(f): + return f[:-len(".py")] + +modules = [] + +for dirpath, dirnames, filenames in os.walk(sys.argv[1]): + for f in filenames: + st = os.stat(dirpath + "/" + f) + modules.append((f, st)) + +print("#include <stdint.h>") +print("const uint16_t mp_frozen_sizes[] = {") + +for f, st in modules: + print("%d," % st.st_size) + +print("0};") + +print("const char mp_frozen_content[] = {") +for f, st in modules: + m = module_name(f) + print('"%s\\0"' % m) + data = open(sys.argv[1] + "/" + f).read() + data = repr(data)[1:-1] + data = data.replace('"', '\\"') + print('"%s"' % data) +print("};") |