summaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-05-14 17:51:12 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-05-14 17:51:12 +0300
commit55491031be1f267e07b2495916d4f5ba2735cc00 (patch)
tree76587cf58be75c473edf891f2a5bc93cdb8747a8 /tools
parent0c57979ce28712422d996fb5291de85e8f7f3be8 (diff)
downloadmicropython-55491031be1f267e07b2495916d4f5ba2735cc00.tar.gz
micropython-55491031be1f267e07b2495916d4f5ba2735cc00.zip
tools/mpy_cross_all.py: Helper tool to run mpy-cross on the entire project.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mpy_cross_all.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/mpy_cross_all.py b/tools/mpy_cross_all.py
new file mode 100755
index 0000000000..2bda71e9bc
--- /dev/null
+++ b/tools/mpy_cross_all.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+import argparse
+import os
+import os.path
+
+argparser = argparse.ArgumentParser(description="Compile all .py files to .mpy recursively")
+argparser.add_argument("-o", "--out", help="output directory (default: input dir)")
+argparser.add_argument("--target", help="select MicroPython target config")
+argparser.add_argument("-mcache-lookup-bc", action="store_true", help="cache map lookups in the bytecode")
+argparser.add_argument("dir", help="input directory")
+args = argparser.parse_args()
+
+TARGET_OPTS = {
+ "unix": "-mcache-lookup-bc",
+ "baremetal": "",
+}
+
+args.dir = args.dir.rstrip("/")
+
+if not args.out:
+ args.out = args.dir
+
+path_prefix_len = len(args.dir) + 1
+
+for path, subdirs, files in os.walk(args.dir):
+ for f in files:
+ if f.endswith(".py"):
+ fpath = path + "/" + f
+ #print(fpath)
+ out_fpath = args.out + "/" + fpath[path_prefix_len:-3] + ".mpy"
+ out_dir = os.path.dirname(out_fpath)
+ if not os.path.isdir(out_dir):
+ os.makedirs(out_dir)
+ cmd = "mpy-cross -v -v %s -s %s %s -o %s" % (TARGET_OPTS.get(args.target, ""),
+ fpath[path_prefix_len:], fpath, out_fpath)
+ #print(cmd)
+ res = os.system(cmd)
+ assert res == 0