From e1b2f2e078727999148a71ab969c1685173d25c0 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Fri, 18 Oct 2024 12:08:11 +0300 Subject: tools/mpy-tool.py: Add support for self-hosting of mpy-tool. This allows running mpy-tool using MicroPython itself. An appropriate test is added to CI to make sure it continues to work. Signed-off-by: Volodymyr Shymanskyy Signed-off-by: Angus Gratton --- tools/ci.sh | 10 ++++++++++ tools/mpy-tool.py | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/ci.sh b/tools/ci.sh index 5b108d6202..682c3ae507 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -118,9 +118,19 @@ function ci_mpy_format_test { python2.7 ./tools/mpy-tool.py -xd tests/frozen/frozentest.mpy python3 ./tools/mpy-tool.py -xd tests/frozen/frozentest.mpy + # Build MicroPython + ci_unix_standard_build + micropython=./ports/unix/build-standard/micropython + $micropython -m mip install --target . argparse __future__ + export MICROPYPATH=. + + # Test mpy-tool.py running under MicroPython + $micropython ./tools/mpy-tool.py -x -d tests/frozen/frozentest.mpy + # Test mpy-tool.py dump feature on native code make -C examples/natmod/features1 ./tools/mpy-tool.py -xd examples/natmod/features1/features1.mpy + $micropython ./tools/mpy-tool.py -x -d examples/natmod/features1/features1.mpy } ######################################################################################## diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index cdceae3746..0094c12177 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -24,11 +24,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Python 2/3 compatibility code +# Python 2/3/MicroPython compatibility code from __future__ import print_function -import platform +import sys -if platform.python_version_tuple()[0] == "2": +if sys.version_info[0] == 2: from binascii import hexlify as hexlify_py2 str_cons = lambda val, enc=None: str(val) @@ -41,7 +41,7 @@ if platform.python_version_tuple()[0] == "2": x = hexlify_py2(b) return ":".join(x[i : i + 2] for i in range(0, len(x), 2)) -else: +elif sys.version_info[0] == 3: # Also handles MicroPython from binascii import hexlify str_cons = str -- cgit v1.2.3