Skip to content

Commit

Permalink
stubber: get_frozen > hack to add arduino_lib to the paths to resolve…
Browse files Browse the repository at this point in the history
… manifest imports for some of the ARDUINO boards

fixes #591

Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
  • Loading branch information
Josverl committed Jul 8, 2024
1 parent b76d592 commit 33ffdf6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"justMyCode": true,
"cwd": "${workspaceFolder}",
"args": [
"-VV",
"list",
// "-VV",
"flash",
// "--board",
// "SEEED_WIO_TERMINAL",
// "PICO",
Expand All @@ -40,9 +40,9 @@
"module": "stubber.stubber",
"cwd": "${workspaceFolder}",
"args": [
// "-v",
"get-docstubs",
// "get-frozen",
"-VV",
// "get-mcu-stubs",
"get-frozen",
// "--version",
// "preview",
// "switch",
Expand Down
9 changes: 8 additions & 1 deletion src/stubber/freeze/freeze_manifest_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ def make_path_vars(
raise ValueError("board path not found")

# VARS must be absolute paths
return {
vars = {
"MPY_DIR": mpy_path.absolute().as_posix(),
"MPY_LIB_DIR": mpy_lib_path.absolute().as_posix(),
"PORT_DIR": port_path.absolute().as_posix(),
"BOARD_DIR": board_path.absolute().as_posix(),
}

if board and "ARDUINO" in board:
log.warning(f"HACK- Adding [TOP]/lib/arduino-lib to paths: {board}")
# see micropython/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk
vars["ARDUINO_LIB_DIR"] = (mpy_path / "lib/arduino-lib").absolute().as_posix()

return vars


def freeze_one_manifest_2(
manifest: Path, frozen_stub_path: Path, mpy_path: Path, mpy_lib_path: Path, version: str
Expand Down
14 changes: 14 additions & 0 deletions src/stubber/freeze/get_frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# - 1.11 and older - include content of /port/modules folder if it exists
import os
import shutil # start moving from os & glob to pathlib
import subprocess

from pathlib import Path
from typing import List, Optional

Expand Down Expand Up @@ -59,6 +61,16 @@ def add_comment_to_path(path: Path, comment: str) -> None:
pass


def checkout_arduino_lib(mpy_path: Path):
"""
Checkout the arduino-lib repo if it is not already checked out
"""
# arduino_lib_path = mpy_path / "lib/arduino-lib"
cmd = ["git", "submodule", "update", "--init", "lib/arduino-lib"]
result = subprocess.run(cmd, cwd=mpy_path, check=True)
log.info(f"checkout arduino-lib: {result.returncode}")


def freeze_any(
stub_folder: Optional[Path] = None,
version: str = V_PREVIEW,
Expand All @@ -78,6 +90,8 @@ def freeze_any(
mpy_path = Path(mpy_path).absolute() if mpy_path else CONFIG.mpy_path.absolute()
mpy_lib_path = Path(mpy_lib_path).absolute() if mpy_lib_path else CONFIG.mpy_path.absolute()

if version > "v1.23.0" or version in SET_PREVIEW:
checkout_arduino_lib(mpy_path)
# if old version of micropython, use the old freeze method
if version not in SET_PREVIEW and Version(version) <= Version("1.11"):
frozen_stub_path = get_fsp(version, stub_folder)
Expand Down

0 comments on commit 33ffdf6

Please sign in to comment.