summaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
authorVolodymyr Shymanskyy <vshymanskyi@gmail.com>2024-10-18 12:08:11 +0300
committerDamien George <damien@micropython.org>2025-03-05 16:01:12 +1100
commite1b2f2e078727999148a71ab969c1685173d25c0 (patch)
tree136b2df79bf94009c147c19b541bdc4319e5c13e /tools
parentfc71f7832f202acf8ab45ab36ebffd706cb0ab59 (diff)
downloadmicropython-e1b2f2e078727999148a71ab969c1685173d25c0.tar.gz
micropython-e1b2f2e078727999148a71ab969c1685173d25c0.zip
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 <vshymanskyi@gmail.com> Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ci.sh10
-rwxr-xr-xtools/mpy-tool.py8
2 files changed, 14 insertions, 4 deletions
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