8000 tools/manifestfile.py: Add a library for working with manifests. by jimmo · Pull Request #8914 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

tools/manifestfile.py: Add a library for working with manifests. #8914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions mpy-cross/mpy_cross/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env python3
#
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright (c) 2022 Andrew Leech
# Copyright (c) 2022 Jim Mussared
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from __future__ import print_function
import os
import stat
import subprocess

NATIVE_ARCH_X86 = "x86"
NATIVE_ARCH_X64 = "x64"
NATIVE_ARCH_ARMV6 = "armv6"
NATIVE_ARCH_ARMV6M = "armv6m"
NATIVE_ARCH_ARMV7M = "armv7m"
NATIVE_ARCH_ARMV7EM = "armv7em"
NATIVE_ARCH_ARMV7EMSP = "armv7emsp"
NATIVE_ARCH_ARMV7EMDP = "armv7emdp"
NATIVE_ARCH_XTENSA = "xtensa"
NATIVE_ARCH_XTENSAWIN = "xtensawin"

NATIVE_ARCHS = [
NATIVE_ARCH_X86,
NATIVE_ARCH_X64,
NATIVE_ARCH_ARMV6,
NATIVE_ARCH_ARMV6M,
NATIVE_ARCH_ARMV7M,
NATIVE_ARCH_ARMV7EM,
NATIVE_ARCH_ARMV7EMSP,
NATIVE_ARCH_ARMV7EMDP,
NATIVE_ARCH_XTENSA,
NATIVE_ARCH_XTENSAWIN,
]

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


class CrossCompileError(Exception):
pass


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"))


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")
if not os.path.exists(src):
raise CrossCompileError("Input .py file not found: {}.".format(src_py))

args = []

if src_path:
args += ["-s", src_path]

if dest:
args += ["-o", dest]

if march:
args += ["-march", march]

if opt is not None:
args += ["-O{}".format(opt)]

if extra_args:
args += extra_args

args += [src]

run(args, mpy_cross)


def run(args, mpy_cross=None):
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))

try:
st = os.stat(mpy_cross)
os.chmod(mpy_cross, st.st_mode | stat.S_IEXEC)
except OSError:
pass

try:
subprocess.check_output([mpy_cross] + args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as er:
raise CrossCompileError(er.output)
38 changes: 38 additions & 0 deletions mpy-cross/mpy_cross/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
#
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright (c) 2022 Andrew Leech
# Copyright (c) 2022 Jim Mussared
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from __future__ import print_function
import argparse
import sys

from . import run, CrossCompileError

try:
run(sys.argv[1:])
except CrossCompileError as er:
print(er.args[0], file=sys.stderr)
raise SystemExit(1)
18 changes: 8 additions & 10 deletions ports/esp8266/boards/GENERIC/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# drivers
freeze("$(MPY_DIR)/drivers/display", "ssd1306.py")

# Libraries from micropython-lib, include only if the library directory exists
if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
# file utilities
freeze("$(MPY_LIB_DIR)/micropython/upysh", "upysh.py")
# micropython-lib: file utilities
freeze("$(MPY_LIB_DIR)/micropython/upysh", "upysh.py")

# requests
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
freeze("$(MPY_LIB_DIR)/micropython/urllib.urequest", "urllib/urequest.py")
# micropython-lib: requests
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
freeze("$(MPY_LIB_DIR)/micropython/urllib.urequest", "urllib/urequest.py")

# umqtt
freeze("$(MPY_LIB_DIR)/micropython/umqtt.simple", "umqtt/simple.py")
freeze("$(MPY_LIB_DIR)/micropython/umqtt.robust", "umqtt/robust.py")
# micropython-lib: umqtt
freeze("$(MPY_LIB_DIR)/micropython/umqtt.simple", "umqtt/simple.py")
freeze("$(MPY_LIB_DIR)/micropython/umqtt.robust", "umqtt/robust.py")
3 changes: 1 addition & 2 deletions ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
l2cap=True,
security=True,
)
if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
3 changes: 1 addition & 2 deletions ports/rp2/boards/PICO_W/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
freeze("$(MPY_DIR)/tools", "upip_utarfile.py")
freeze("$(MPY_DIR)/extmod", "ntptime.py")

if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
Loading
0