Skip to content

temporary fix for OpenOCD until complete refactoring of tl-install for all components #157

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 5 commits into from
May 1, 2025
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
2 changes: 1 addition & 1 deletion builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def check_lib_archive_exists():
f.replace(
"$PACKAGE_DIR",
_to_unix_slashes(
platform.get_package_dir("tool-openocd") or ""))
platform.get_package_dir("tool-openocd-esp32") or ""))
for f in openocd_args
]
env.Replace(
Expand Down
6 changes: 3 additions & 3 deletions platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
"owner": "",
"version": ""
},
"tool-openocd": {
"tool-openocd-esp32": {
"type": "debugger",
"optional": true,
"owner": "",
"version": ""
"owner": "pioarduino",
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/openocd-v0.12.0-esp32-20250226.zip"
},
"tool-esp-rom-elfs": {
"optional": true,
Expand Down
54 changes: 48 additions & 6 deletions platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_tool_version_from_platform_json(tool_name):
sys.stderr.write("Error: Couldn't execute 'idf_tools.py install'\n")
else:
shutil.copytree(join(IDF_TOOLS_PATH_DEFAULT, "tools", "tool-packages"), join(IDF_TOOLS_PATH_DEFAULT, "tools"), symlinks=False, ignore=None, ignore_dangling_symlinks=False, dirs_exist_ok=True)
for p in ("tool-mklittlefs", "tool-mkfatfs", "tool-mkspiffs", "tool-dfuutil", "tool-openocd", "tool-cmake", "tool-ninja", "tool-cppcheck", "tool-clangtidy", "tool-pvs-studio", "tc-xt-esp32", "tc-ulp", "tc-rv32", "tl-xt-gdb", "tl-rv-gdb", "contrib-piohome", "contrib-pioremote"):
for p in ("tool-mklittlefs", "tool-mkfatfs", "tool-mkspiffs", "tool-dfuutil", "tool-cmake", "tool-ninja", "tool-cppcheck", "tool-clangtidy", "tool-pvs-studio", "tc-xt-esp32", "tc-ulp", "tc-rv32", "tl-xt-gdb", "tl-rv-gdb", "contrib-piohome", "contrib-pioremote"):
tl_path = "file://" + join(IDF_TOOLS_PATH_DEFAULT, "tools", p)
pm.install(tl_path)

Expand All @@ -79,6 +79,51 @@ def configure_default_packages(self, variables, targets):
if not variables.get("board"):
return super().configure_default_packages(variables, targets)

def install_tool(TOOL):
self.packages[TOOL]["optional"] = False
TOOL_PATH = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), TOOL)
TOOL_PACKAGE_PATH = os.path.join(TOOL_PATH, "package.json")
TOOLS_PATH_DEFAULT = os.path.join(os.path.expanduser("~"), ".espressif")
IDF_TOOLS = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tl-install", "tools", "idf_tools.py")
TOOLS_JSON_PATH = os.path.join(TOOL_PATH, "tools.json")
TOOLS_PIO_PATH = os.path.join(TOOL_PATH, ".piopm")
IDF_TOOLS_CMD = (
python_exe,
IDF_TOOLS,
"--quiet",
"--non-interactive",
"--tools-json",
TOOLS_JSON_PATH,
"install"
)

tl_flag = bool(os.path.exists(IDF_TOOLS))
json_flag = bool(os.path.exists(TOOLS_JSON_PATH))
pio_flag = bool(os.path.exists(TOOLS_PIO_PATH))
if tl_flag and json_flag:
rc = subprocess.run(IDF_TOOLS_CMD).returncode
if rc != 0:
sys.stderr.write("Error: Couldn't execute 'idf_tools.py install'\n")
else:
tl_path = "file://" + join(TOOLS_PATH_DEFAULT, "tools", TOOL)
try:
shutil.copyfile(TOOL_PACKAGE_PATH, join(TOOLS_PATH_DEFAULT, "tools", TOOL, "package.json"))
except FileNotFoundError as e:
sys.stderr.write(f"Error copying tool package file: {e}\n")
self.packages.pop(TOOL, None)
if os.path.exists(TOOL_PATH) and os.path.isdir(TOOL_PATH):
try:
shutil.rmtree(TOOL_PATH)
except Exception as e:
print(f"Error while removing the tool folder: {e}")
pm.install(tl_path)
# tool is already installed, just activate it
if tl_flag and pio_flag and not json_flag:
self.packages[TOOL]["version"] = TOOL_PATH
self.packages[TOOL]["optional"] = False

return

board_config = self.board_config(variables.get("board"))
mcu = variables.get("board_build.mcu", board_config.get("build.mcu", "esp32"))
board_sdkconfig = variables.get("board_espidf.custom_sdkconfig", board_config.get("espidf.custom_sdkconfig", ""))
Expand Down Expand Up @@ -168,10 +213,7 @@ def configure_default_packages(self, variables, targets):
del self.packages["tool-mkspiffs"]

if variables.get("upload_protocol"):
self.packages["tool-openocd"]["optional"] = False
self.packages["tool-openocd"]["version"] = "file://" + join(IDF_TOOLS_PATH_DEFAULT, "tools", "tool-openocd")
else:
del self.packages["tool-openocd"]
install_tool("tool-openocd-esp32")

if "downloadfs" in targets:
filesystem = variables.get("board_build.filesystem", "littlefs")
Expand Down Expand Up @@ -297,7 +339,7 @@ def _add_dynamic_options(self, board):

debug["tools"][link] = {
"server": {
"package": "tool-openocd",
"package": "tool-openocd-esp32",
"executable": "bin/openocd",
"arguments": server_args,
},
Expand Down