mpy-cross/mpy_cross: Add a way to query the mpy version.
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>
This commit is contained in:
parent
71050870b8
commit
ee1b4a2026
@ -27,6 +27,7 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
|
||||
@ -54,14 +55,15 @@ NATIVE_ARCHS = [
|
||||
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:
|
||||
@ -69,6 +71,16 @@ def _find_mpy_cross_binary(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")
|
||||
|
Loading…
Reference in New Issue
Block a user