Skip to content

Commit 205cdf3

Browse files
authored
temporary fix for OpenOCD until complete refactoring of tl-install for all components (#157)
1 parent c99d03e commit 205cdf3

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

builder/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def check_lib_archive_exists():
547547
f.replace(
548548
"$PACKAGE_DIR",
549549
_to_unix_slashes(
550-
platform.get_package_dir("tool-openocd") or ""))
550+
platform.get_package_dir("tool-openocd-esp32") or ""))
551551
for f in openocd_args
552552
]
553553
env.Replace(

platform.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@
115115
"owner": "",
116116
"version": ""
117117
},
118-
"tool-openocd": {
118+
"tool-openocd-esp32": {
119119
"type": "debugger",
120120
"optional": true,
121-
"owner": "",
122-
"version": ""
121+
"owner": "pioarduino",
122+
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/openocd-v0.12.0-esp32-20250226.zip"
123123
},
124124
"tool-esp-rom-elfs": {
125125
"optional": true,

platform.py

+48-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_tool_version_from_platform_json(tool_name):
7070
sys.stderr.write("Error: Couldn't execute 'idf_tools.py install'\n")
7171
else:
7272
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)
73-
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"):
73+
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"):
7474
tl_path = "file://" + join(IDF_TOOLS_PATH_DEFAULT, "tools", p)
7575
pm.install(tl_path)
7676

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

82+
def install_tool(TOOL):
83+
self.packages[TOOL]["optional"] = False
84+
TOOL_PATH = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), TOOL)
85+
TOOL_PACKAGE_PATH = os.path.join(TOOL_PATH, "package.json")
86+
TOOLS_PATH_DEFAULT = os.path.join(os.path.expanduser("~"), ".espressif")
87+
IDF_TOOLS = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tl-install", "tools", "idf_tools.py")
88+
TOOLS_JSON_PATH = os.path.join(TOOL_PATH, "tools.json")
89+
TOOLS_PIO_PATH = os.path.join(TOOL_PATH, ".piopm")
90+
IDF_TOOLS_CMD = (
91+
python_exe,
92+
IDF_TOOLS,
93+
"--quiet",
94+
"--non-interactive",
95+
"--tools-json",
96+
TOOLS_JSON_PATH,
97+
"install"
98+
)
99+
100+
tl_flag = bool(os.path.exists(IDF_TOOLS))
101+
json_flag = bool(os.path.exists(TOOLS_JSON_PATH))
102+
pio_flag = bool(os.path.exists(TOOLS_PIO_PATH))
103+
if tl_flag and json_flag:
104+
rc = subprocess.run(IDF_TOOLS_CMD).returncode
105+
if rc != 0:
106+
sys.stderr.write("Error: Couldn't execute 'idf_tools.py install'\n")
107+
else:
108+
tl_path = "file://" + join(TOOLS_PATH_DEFAULT, "tools", TOOL)
109+
try:
110+
shutil.copyfile(TOOL_PACKAGE_PATH, join(TOOLS_PATH_DEFAULT, "tools", TOOL, "package.json"))
111+
except FileNotFoundError as e:
112+
sys.stderr.write(f"Error copying tool package file: {e}\n")
113+
self.packages.pop(TOOL, None)
114+
if os.path.exists(TOOL_PATH) and os.path.isdir(TOOL_PATH):
115+
try:
116+
shutil.rmtree(TOOL_PATH)
117+
except Exception as e:
118+
print(f"Error while removing the tool folder: {e}")
119+
pm.install(tl_path)
120+
# tool is already installed, just activate it
121+
if tl_flag and pio_flag and not json_flag:
122+
self.packages[TOOL]["version"] = TOOL_PATH
123+
self.packages[TOOL]["optional"] = False
124+
125+
return
126+
82127
board_config = self.board_config(variables.get("board"))
83128
mcu = variables.get("board_build.mcu", board_config.get("build.mcu", "esp32"))
84129
board_sdkconfig = variables.get("board_espidf.custom_sdkconfig", board_config.get("espidf.custom_sdkconfig", ""))
@@ -168,10 +213,7 @@ def configure_default_packages(self, variables, targets):
168213
del self.packages["tool-mkspiffs"]
169214

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

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

298340
debug["tools"][link] = {
299341
"server": {
300-
"package": "tool-openocd",
342+
"package": "tool-openocd-esp32",
301343
"executable": "bin/openocd",
302344
"arguments": server_args,
303345
},

0 commit comments

Comments
 (0)