From 71050870b81a8dbf3c3fac93bd2d86f0ff9a37d2 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 28 Sep 2022 01:04:05 +1000 Subject: [PATCH] mpy-cross/mpy_cross: Fix default path to mpy-cross binary. Needed to be updated to use build/mpy-cross. Also fixes some other issues in the Python wrapper: - Rename find_mpy_cross_binary to _find_mpy_cross_binary - Fix passing of -march arg. - Decode stdout from subprocess. - Print stdout from mpy-cross in __main__.py. Signed-off-by: Jim Mussared --- mpy-cross/mpy_cross/__init__.py | 12 +++++++----- mpy-cross/mpy_cross/__main__.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mpy-cross/mpy_cross/__init__.py b/mpy-cross/mpy_cross/__init__.py index d4c0930bb9..235271d2ce 100644 --- a/mpy-cross/mpy_cross/__init__.py +++ b/mpy-cross/mpy_cross/__init__.py @@ -62,9 +62,11 @@ class CrossCompileError(Exception): def find_mpy_cross_binary(mpy_cross): + +def _find_mpy_cross_binary(mpy_cross): if mpy_cross: return mpy_cross - return os.path.abspath(os.path.join(os.path.dirname(__file__), "../mpy-cross")) + return os.path.abspath(os.path.join(os.path.dirname(__file__), "../build/mpy-cross")) def compile(src, dest=None, src_path=None, opt=None, march=None, mpy_cross=None, extra_args=None): @@ -82,7 +84,7 @@ def compile(src, dest=None, src_path=None, opt=None, march=None, mpy_cross=None, args += ["-o", dest] if march: - args += ["-march", march] + args += ["-march=" + march] if opt is not None: args += ["-O{}".format(opt)] @@ -96,7 +98,7 @@ def compile(src, dest=None, src_path=None, opt=None, march=None, mpy_cross=None, def run(args, mpy_cross=None): - mpy_cross = find_mpy_cross_binary(mpy_cross) + mpy_cross = _find_mpy_cross_binary(mpy_cross) if not os.path.exists(mpy_cross): raise CrossCompileError("mpy-cross binary not found at {}.".format(mpy_cross)) @@ -108,6 +110,6 @@ def run(args, mpy_cross=None): pass try: - subprocess.check_output([mpy_cross] + args, stderr=subprocess.STDOUT) + return subprocess.check_output([mpy_cross] + args, stderr=subprocess.STDOUT).decode() except subprocess.CalledProcessError as er: - raise CrossCompileError(er.output) + raise CrossCompileError(er.output.decode()) diff --git a/mpy-cross/mpy_cross/__main__.py b/mpy-cross/mpy_cross/__main__.py index 9d957bca02..2b6b81c333 100644 --- a/mpy-cross/mpy_cross/__main__.py +++ b/mpy-cross/mpy_cross/__main__.py @@ -32,7 +32,7 @@ import sys from . import run, CrossCompileError try: - run(sys.argv[1:]) + print(run(sys.argv[1:])) except CrossCompileError as er: print(er.args[0], file=sys.stderr) raise SystemExit(1)