Skip to content

Commit 7a33014

Browse files
authored
check for requirements match of already installed tools (#165)
1 parent f4def7f commit 7a33014

File tree

2 files changed

+85
-13
lines changed

2 files changed

+85
-13
lines changed

platform.json

Lines changed: 28 additions & 4 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": "14.2.0+20241119",
6061
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/xtensa-esp-elf-14.2.0_20241119.zip"
6162
},
6263
"toolchain-riscv32-esp": {
6364
"type": "toolchain",
6465
"optional": true,
6566
"owner": "pioarduino",
67+
"package-version": "14.2.0+20241119",
6668
"version": "https://github.com/pioarduino/registry/releases/download/0.0.1/riscv32-esp-elf-14.2.0_20241119.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
},
74-
"tool-xtensa-esp-elf-gdb": {
77+
"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: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515
import os
16+
import requests
17+
import json
1618
import subprocess
1719
import sys
1820
import shutil
@@ -44,7 +46,7 @@ def configure_default_packages(self, variables, targets):
4446
board_sdkconfig = variables.get("board_espidf.custom_sdkconfig", board_config.get("espidf.custom_sdkconfig", ""))
4547
frameworks = variables.get("pioframework", [])
4648

47-
def install_tool(TOOL):
49+
def install_tool(TOOL, retry_count=0):
4850
self.packages[TOOL]["optional"] = False
4951
TOOL_PATH = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), TOOL)
5052
TOOL_PACKAGE_PATH = os.path.join(TOOL_PATH, "package.json")
@@ -80,13 +82,37 @@ def install_tool(TOOL):
8082
try:
8183
shutil.rmtree(TOOL_PATH)
8284
except Exception as e:
83-
print(f"Error while removing the tool folder: {e}")
85+
print(f"Error while removing the tool folder: {e}")
8486
pm.install(tl_path)
8587
# tool is already installed, just activate it
8688
if tl_flag and pio_flag and not json_flag:
87-
self.packages[TOOL]["version"] = TOOL_PATH
88-
self.packages[TOOL]["optional"] = False
89-
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+
90116
return
91117

92118
# Installer only needed for setup, deactivate when installed
@@ -130,7 +156,6 @@ def install_tool(TOOL):
130156
# Set mandatory toolchains
131157
for toolchain in toolchain_data["toolchains"]:
132158
install_tool(toolchain)
133-
134159
# Set ULP toolchain if applicable
135160
ulp_toolchain = toolchain_data.get("ulp_toolchain")
136161
if ulp_toolchain and os.path.isdir("ulp"):
@@ -169,6 +194,13 @@ def install_tool(TOOL):
169194
if "buildfs" in targets:
170195
filesystem = variables.get("board_build.filesystem", "littlefs")
171196
if filesystem == "littlefs":
197+
# ensure use of mklittlefs 3.2.0
198+
piopm_path = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tool-mklittlefs", ".piopm")
199+
if os.path.exists(piopm_path):
200+
with open(piopm_path, "r") as file:
201+
package_data = json.load(file)
202+
if package_data['version'] == "4.0.0":
203+
os.remove(piopm_path)
172204
install_tool("tool-mklittlefs")
173205
elif filesystem == "fatfs":
174206
install_tool("tool-mkfatfs")
@@ -179,9 +211,25 @@ def install_tool(TOOL):
179211
filesystem = variables.get("board_build.filesystem", "littlefs")
180212
if filesystem == "littlefs":
181213
# Use Tasmota mklittlefs v4.0.0 to unpack, older version is incompatible
182-
self.packages["tool-mklittlefs"]["version"] = "https://github.com/pioarduino/registry/releases/download/0.0.1/mklittlefs-4.0.0.zip"
183-
self.packages["tool-mklittlefs"]["optional"] = False
184-
install_tool("tool-mklittlefs")
214+
# make sure mklittlefs 3.2.0 is installed
215+
mklittlefs_dir = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tool-mklittlefs")
216+
if not os.path.exists(mklittlefs_dir):
217+
install_tool("tool-mklittlefs")
218+
if os.path.exists(os.path.join(mklittlefs_dir, "tools.json")):
219+
install_tool("tool-mklittlefs")
220+
mklittlefs400_dir = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tool-mklittlefs-4.0.0")
221+
if not os.path.exists(mklittlefs400_dir):
222+
# install mklittlefs 4.0.0
223+
install_tool("tool-mklittlefs-4.0.0")
224+
if os.path.exists(os.path.join(mklittlefs400_dir, "tools.json")):
225+
install_tool("tool-mklittlefs-4.0.0")
226+
# use mklittlefs 4.0.0 instead of 3.2.0 by copying over
227+
if os.path.exists(mklittlefs400_dir):
228+
shutil.copyfile(
229+
os.path.join(mklittlefs_dir, "package.json"),
230+
os.path.join(mklittlefs400_dir, "package.json"),
231+
)
232+
shutil.copytree(mklittlefs400_dir, mklittlefs_dir, dirs_exist_ok=True)
185233

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

0 commit comments

Comments
 (0)