@@ -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" , "" ))
@@ -164,10 +209,7 @@ def configure_default_packages(self, variables, targets):
164209 del self .packages ["tool-mkspiffs" ]
165210
166211 if variables .get ("upload_protocol" ):
167- self .packages ["tool-openocd" ]["optional" ] = False
168- self .packages ["tool-openocd" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-openocd" )
169- else :
170- del self .packages ["tool-openocd" ]
212+ install_tool ("tool-openocd-esp32" )
171213
172214 if "downloadfs" in targets :
173215 filesystem = variables .get ("board_build.filesystem" , "littlefs" )
@@ -293,7 +335,7 @@ def _add_dynamic_options(self, board):
293335
294336 debug ["tools" ][link ] = {
295337 "server" : {
296- "package" : "tool-openocd" ,
338+ "package" : "tool-openocd-esp32 " ,
297339 "executable" : "bin/openocd" ,
298340 "arguments" : server_args ,
299341 },
0 commit comments