Cross compile source files into bytecode using mpy-cross.

This commit is contained in:
Himadri Bhattacharjee
2023-03-24 12:32:31 +05:30
parent fa77e4391e
commit 7d8e407d88
12 changed files with 36 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
amora/lib/*
build
*.uf2
mpy-cross*

34
build.py Normal file
View File

@@ -0,0 +1,34 @@
import glob
from subprocess import PIPE, Popen
from os import listdir, makedirs
from os.path import join, splitext, isfile
from shutil import copytree, copy
SRC = 'src'
OUT = 'build'
def lib_files(s: str):
name, ext = splitext(s)
if name not in ("code", "boot") and ext == ".py" and isfile(s):
return name
return None
makedirs(OUT, exist_ok=True)
for entry in listdir(SRC):
if name := lib_files(entry):
Popen([
join(".", glob.glob("mpy-cross.static*")[0]),
join(SRC, entry),
"-o",
join(OUT, f'{name}.mpy')
],
stdout=PIPE
).communicate()
elif isfile(join(SRC, entry)):
copy(join(SRC, entry),
join(OUT, entry))
else:
copytree(join(SRC, entry),
join(OUT, entry))