@@ -70,7 +70,7 @@ def get_tool_version_from_platform_json(tool_name):
70
70
sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install'\n " )
71
71
else :
72
72
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" ):
74
74
tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , p )
75
75
pm .install (tl_path )
76
76
@@ -79,6 +79,51 @@ def configure_default_packages(self, variables, targets):
79
79
if not variables .get ("board" ):
80
80
return super ().configure_default_packages (variables , targets )
81
81
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
+
82
127
board_config = self .board_config (variables .get ("board" ))
83
128
mcu = variables .get ("board_build.mcu" , board_config .get ("build.mcu" , "esp32" ))
84
129
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):
168
213
del self .packages ["tool-mkspiffs" ]
169
214
170
215
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" )
175
217
176
218
if "downloadfs" in targets :
177
219
filesystem = variables .get ("board_build.filesystem" , "littlefs" )
@@ -297,7 +339,7 @@ def _add_dynamic_options(self, board):
297
339
298
340
debug ["tools" ][link ] = {
299
341
"server" : {
300
- "package" : "tool-openocd" ,
342
+ "package" : "tool-openocd-esp32 " ,
301
343
"executable" : "bin/openocd" ,
302
344
"arguments" : server_args ,
303
345
},
0 commit comments