Skip to content

Commit

Permalink
mpy-cross/mpy_cross: Add a way to query the mpy version.
Browse files Browse the repository at this point in the history
This returns the mpy version and sub-version for files compiled with this
mpy-cross binary.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
  • Loading branch information
jimmo committed Sep 28, 2022
1 parent 7105087 commit ee1b4a2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mpy-cross/mpy_cross/__init__.py
Expand Up @@ -27,6 +27,7 @@

from __future__ import print_function
import os
import re
import stat
import subprocess

Expand Down Expand Up @@ -54,21 +55,32 @@
NATIVE_ARCH_XTENSAWIN,
]

__all__ = ["compile", "run", "CrossCompileError"]
__all__ = ["version", "compile", "run", "CrossCompileError"]


class CrossCompileError(Exception):
pass


def find_mpy_cross_binary(mpy_cross):
_VERSION_RE = re.compile("mpy-cross emitting mpy v([0-9]+)(?:.([0-9]+))?")


def _find_mpy_cross_binary(mpy_cross):
if mpy_cross:
return mpy_cross
return os.path.abspath(os.path.join(os.path.dirname(__file__), "../build/mpy-cross"))


def mpy_version(mpy_cross=None):
version_info = run(["--version"], mpy_cross=mpy_cross)
match = re.search(_VERSION_RE, version_info)
mpy_version, mpy_sub_version = int(match.group(1)), int(match.group(2) or "0")
return (
mpy_version,
mpy_sub_version,
)


def compile(src, dest=None, src_path=None, opt=None, march=None, mpy_cross=None, extra_args=None):
if not src:
raise ValueError("src is required")
Expand Down

0 comments on commit ee1b4a2

Please sign in to comment.