Fix build script file copying issue.

This commit is contained in:
Himadri Bhattacharjee
2023-03-24 14:06:26 +05:30
parent 14660ce237
commit 5b3c4dde21

View File

@@ -1,34 +1,44 @@
import glob
from subprocess import PIPE, Popen
from os import listdir, makedirs
from os.path import join, splitext, isfile
from os.path import join, splitext
from shutil import copytree, copy
from errno import ENOTDIR
SRC = 'src'
DST = 'build'
def lib_files(s: str):
def cp(src, dst):
try:
copytree(src, dst)
except OSError as exc:
if exc.errno == ENOTDIR:
copy(src, dst)
else:
raise
def to_compile(s: str):
name, ext = splitext(s)
if name not in ("code", "boot") and ext == ".py" and isfile(s):
if name not in ("code", "boot") and ext == ".py":
return name
return None
makedirs(DST, exist_ok=True)
mpy_cross_bin = join(".", glob.glob("mpy-cross.static*")[0])
for entry in listdir(SRC):
src_path = join(SRC, entry)
if name := lib_files(entry):
if name := to_compile(entry):
Popen([
join(".", glob.glob("mpy-cross.static*")[0]),
src_path, "-o",
join(DST, f'{name}.mpy')
mpy_cross_bin,
"-o",
join(DST, f'{name}.mpy'),
src_path,
],
stdout=PIPE
stdout=PIPE,
).communicate()
else:
dst_path = join(DST, entry)
if isfile(join(SRC, entry)):
copy(src_path, dst_path)
else:
copytree(src_path, dst_path)
cp(src_path, dst_path)