Skip to content

Commit abe7147

Browse files
authored
check for requirements match of already installed tools (#166)
1 parent 22ebc7b commit abe7147

File tree

2 files changed

+83
-12
lines changed

2 files changed

+83
-12
lines changed

platform.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,35 @@
5757
"type": "toolchain",
5858
"optional": true,
5959
"owner": "pioarduino",
60+
"package-version": "13.2.0+20240530",
6061
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/xtensa-esp-elf-13.2.0_20240530.zip"
6162
},
6263
"toolchain-riscv32-esp": {
6364
"type": "toolchain",
6465
"optional": true,
6566
"owner": "pioarduino",
67+
"package-version": "13.2.0+20240530",
6668
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/riscv32-esp-elf-13.2.0_20240530.zip"
6769
},
6870
"toolchain-esp32ulp": {
6971
"type": "toolchain",
7072
"optional": true,
7173
"owner": "pioarduino",
74+
"package-version": "2.38.0+20240113",
7275
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/esp32ulp-elf-2.38_20240113.zip"
7376
},
7477
"tool-xtensa-esp-elf-gdb": {
7578
"type": "debugger",
7679
"optional": true,
7780
"owner": "pioarduino",
81+
"package-version": "16.2.0+20250324",
7882
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/xtensa-esp-gdb-v16.2_20250324.zip"
7983
},
8084
"tool-riscv32-esp-elf-gdb": {
8185
"type": "debugger",
8286
"optional": true,
8387
"owner": "pioarduino",
88+
"package-version": "16.2.0+20250324",
8489
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/riscv32-esp-gdb-v16.2_20250324.zip"
8590
},
8691
"tool-esptoolpy": {
@@ -99,72 +104,91 @@
99104
"type": "uploader",
100105
"optional": true,
101106
"owner": "pioarduino",
107+
"package-version": "1.11.0",
102108
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/dfuutil-arduino-v1.11.0.zip"
103109
},
104110
"tool-openocd-esp32": {
105111
"type": "debugger",
106112
"optional": true,
107113
"owner": "pioarduino",
114+
"package-version": "2.1200.20250226",
108115
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/openocd-v0.12.0-esp32-20250226.zip"
109116
},
110117
"tool-mklittlefs": {
111118
"type": "uploader",
112119
"optional": true,
113120
"owner": "pioarduino",
121+
"package-version": "3.2.0",
114122
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/mklittlefs-3.2.0.zip"
115123
},
116-
"tool-mkfatfs": {
124+
"tool-mklittlefs-4.0.0": {
117125
"type": "uploader",
118126
"optional": true,
119127
"owner": "pioarduino",
120-
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/mkfatfs-v2.0.1.zip"
128+
"package-version": "4.0.0",
129+
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/mklittlefs-4.0.0.zip"
121130
},
122131
"tool-mkspiffs": {
123132
"type": "uploader",
124133
"optional": true,
125134
"owner": "pioarduino",
135+
"package-version": "2.230.0",
126136
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/mkspiffs-v2.230.0.zip"
137+
},
138+
"tool-mkfatfs": {
139+
"type": "uploader",
140+
"optional": true,
141+
"owner": "pioarduino",
142+
"package-version": "2.0.1",
143+
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/mkfatfs-v2.0.1.zip"
127144
},
128145
"tool-cppcheck": {
129146
"type": "tool",
130147
"optional": true,
131148
"owner": "pioarduino",
149+
"package-version": "2.11.0+230717",
132150
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/cppcheck-v2.11.0-230717.zip"
133151
},
134152
"tool-clangtidy": {
135153
"type": "tool",
136154
"optional": true,
137155
"owner": "pioarduino",
156+
"package-version": "18.1.1",
138157
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/clangtidy-v18.1.1.zip"
139158
},
140159
"tool-pvs-studio": {
141160
"type": "tool",
142161
"optional": true,
143162
"owner": "pioarduino",
144-
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/pvs-studio-v7.18.zip"
163+
"package-version": "7.36.91321",
164+
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/pvs-studio-v7.36.91321.zip"
145165
},
146166
"tool-cmake": {
147167
"type": "tool",
148168
"optional": true,
149169
"owner": "pioarduino",
170+
"package-version": "3.30.2",
150171
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/cmake-3.30.2.zip"
151172
},
152173
"tool-esp-rom-elfs": {
153174
"type": "tool",
154175
"optional": true,
155176
"owner": "pioarduino",
177+
"package-version": "2024.10.11",
156178
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/esp-rom-elfs-20241011.zip"
157179
},
158180
"tool-ninja": {
159181
"type": "tool",
160182
"optional": true,
161183
"owner": "pioarduino",
184+
"package-version": "1.10.2",
162185
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/ninja-1.10.2.zip"
163186
},
164187
"tool-scons": {
165188
"type": "tool",
166189
"optional": true,
167190
"owner": "pioarduino",
191+
"package-version": "4.40801.0",
168192
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/scons-4.8.1.zip"
169193
}
170194
}

platform.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import requests
17+
import json
1718
import subprocess
1819
import sys
1920
import shutil
@@ -45,7 +46,7 @@ def configure_default_packages(self, variables, targets):
4546
board_sdkconfig = variables.get("board_espidf.custom_sdkconfig", board_config.get("espidf.custom_sdkconfig", ""))
4647
frameworks = variables.get("pioframework", [])
4748

48-
def install_tool(TOOL):
49+
def install_tool(TOOL, retry_count=0):
4950
self.packages[TOOL]["optional"] = False
5051
TOOL_PATH = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), TOOL)
5152
TOOL_PACKAGE_PATH = os.path.join(TOOL_PATH, "package.json")
@@ -81,13 +82,37 @@ def install_tool(TOOL):
8182
try:
8283
shutil.rmtree(TOOL_PATH)
8384
except Exception as e:
84-
print(f"Error while removing the tool folder: {e}")
85+
print(f"Error while removing the tool folder: {e}")
8586
pm.install(tl_path)
8687
# tool is already installed, just activate it
8788
if tl_flag and pio_flag and not json_flag:
88-
self.packages[TOOL]["version"] = TOOL_PATH
89-
self.packages[TOOL]["optional"] = False
90-
89+
with open(TOOL_PACKAGE_PATH, "r") as file:
90+
package_data = json.load(file)
91+
# check installed tool version against listed in platforms.json
92+
if "package-version" in self.packages[TOOL] \
93+
and "version" in package_data \
94+
and self.packages[TOOL]["package-version"] == package_data["version"]:
95+
self.packages[TOOL]["version"] = TOOL_PATH
96+
self.packages[TOOL]["optional"] = False
97+
elif "package-version" not in self.packages[TOOL]:
98+
# No version check needed, just use the installed tool
99+
self.packages[TOOL]["version"] = TOOL_PATH
100+
self.packages[TOOL]["optional"] = False
101+
elif "version" not in package_data:
102+
print(f"Warning: Cannot determine installed version for {TOOL}. Reinstalling...")
103+
else: # Installed version does not match required version, deinstall existing and install needed
104+
self.packages.pop(TOOL, None)
105+
if os.path.exists(TOOL_PATH) and os.path.isdir(TOOL_PATH):
106+
try:
107+
shutil.rmtree(TOOL_PATH)
108+
except Exception as e:
109+
print(f"Error while removing the tool folder: {e}")
110+
if retry_count >= 3: # Limit to 3 retries
111+
print(f"Failed to install {TOOL} after multiple attempts. Please check your network connection and try again manually.")
112+
return
113+
print(f"Wrong version for {TOOL}. Installing needed version...")
114+
install_tool(TOOL, retry_count + 1)
115+
91116
return
92117

93118
# Installer only needed for setup, deactivate when installed
@@ -129,7 +154,6 @@ def install_tool(TOOL):
129154
# Set mandatory toolchains
130155
for toolchain in toolchain_data["toolchains"]:
131156
install_tool(toolchain)
132-
133157
# Set ULP toolchain if applicable
134158
ulp_toolchain = toolchain_data.get("ulp_toolchain")
135159
if ulp_toolchain and os.path.isdir("ulp"):
@@ -168,6 +192,13 @@ def install_tool(TOOL):
168192
if "buildfs" in targets:
169193
filesystem = variables.get("board_build.filesystem", "littlefs")
170194
if filesystem == "littlefs":
195+
# ensure use of mklittlefs 3.2.0
196+
piopm_path = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tool-mklittlefs", ".piopm")
197+
if os.path.exists(piopm_path):
198+
with open(piopm_path, "r") as file:
199+
package_data = json.load(file)
200+
if package_data['version'] == "4.0.0":
201+
os.remove(piopm_path)
171202
install_tool("tool-mklittlefs")
172203
elif filesystem == "fatfs":
173204
install_tool("tool-mkfatfs")
@@ -178,9 +209,25 @@ def install_tool(TOOL):
178209
filesystem = variables.get("board_build.filesystem", "littlefs")
179210
if filesystem == "littlefs":
180211
# Use Tasmota mklittlefs v4.0.0 to unpack, older version is incompatible
181-
self.packages["tool-mklittlefs"]["version"] = "https://github.com/pioarduino/registry/releases/download/0.0.1/mklittlefs-4.0.0.zip"
182-
self.packages["tool-mklittlefs"]["optional"] = False
183-
install_tool("tool-mklittlefs")
212+
# make sure mklittlefs 3.2.0 is installed
213+
mklittlefs_dir = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tool-mklittlefs")
214+
if not os.path.exists(mklittlefs_dir):
215+
install_tool("tool-mklittlefs")
216+
if os.path.exists(os.path.join(mklittlefs_dir, "tools.json")):
217+
install_tool("tool-mklittlefs")
218+
mklittlefs400_dir = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tool-mklittlefs-4.0.0")
219+
if not os.path.exists(mklittlefs400_dir):
220+
# install mklittlefs 4.0.0
221+
install_tool("tool-mklittlefs-4.0.0")
222+
if os.path.exists(os.path.join(mklittlefs400_dir, "tools.json")):
223+
install_tool("tool-mklittlefs-4.0.0")
224+
# use mklittlefs 4.0.0 instead of 3.2.0 by copying over
225+
if os.path.exists(mklittlefs400_dir):
226+
shutil.copyfile(
227+
os.path.join(mklittlefs_dir, "package.json"),
228+
os.path.join(mklittlefs400_dir, "package.json"),
229+
)
230+
shutil.copytree(mklittlefs400_dir, mklittlefs_dir, dirs_exist_ok=True)
184231

185232
# Currently only Arduino Nano ESP32 uses the dfuutil tool as uploader
186233
if variables.get("board") == "arduino_nano_esp32":

0 commit comments

Comments
 (0)