27
27
IS_WINDOWS = sys .platform .startswith ("win" )
28
28
# Set Platformio env var to use windows_amd64 for all windows architectures
29
29
# only windows_amd64 native espressif toolchains are available
30
- # needs platformio core >= 6.1.16b2 or pioarduino core 6.1.16+test
30
+ # needs platformio/pioarduino core >= 6.1.17
31
31
if IS_WINDOWS :
32
32
os .environ ["PLATFORMIO_SYSTEM_TYPE" ] = "windows_amd64"
33
33
34
34
python_exe = get_pythonexe_path ()
35
35
pm = ToolPackageManager ()
36
36
37
- def install_tool (TOOL ):
38
- TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".platformio" )
39
- IDF_TOOLS = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tl-install" , "tools" , "idf_tools.py" )
40
- TOOLS_JSON_PATH = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), TOOL , "tools.json" )
41
- TOOLS_PACK_PATH = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), TOOL , "package.json" )
42
- IDF_TOOLS_CMD = (
43
- python_exe ,
44
- IDF_TOOLS ,
45
- "--quiet" ,
46
- "--non-interactive" ,
47
- "--tools-json" ,
48
- TOOLS_JSON_PATH ,
49
- "install"
50
- )
51
-
52
- tl_flag = bool (os .path .exists (IDF_TOOLS ))
53
- json_flag = bool (os .path .exists (TOOLS_JSON_PATH ))
54
- if tl_flag and json_flag :
55
- rc = subprocess .call (IDF_TOOLS_CMD )
56
- if rc != 0 :
57
- sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install'\n " )
58
- else :
59
- tl_path = "file://" + join (TOOLS_PATH_DEFAULT , "tools" , TOOL )
60
- if not os .path .exists (join (TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" )):
61
- shutil .copyfile (TOOLS_PACK_PATH , join (TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" ))
62
- pm .install (tl_path )
63
- return
64
-
65
-
66
37
class Espressif32Platform (PlatformBase ):
67
38
def configure_default_packages (self , variables , targets ):
68
39
if not variables .get ("board" ):
@@ -76,11 +47,45 @@ def configure_default_packages(self, variables, targets):
76
47
core_variant_build = ('' .join (variables .get ("build_flags" , []))).replace ("-D" , " " )
77
48
frameworks = variables .get ("pioframework" , [])
78
49
50
+ def install_tool (TOOL ):
51
+ INSTALL_TOOL = "install-" + TOOL .split ('-' , 1 )[- 1 ]
52
+ INSTALL_TOOL_PATH = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), INSTALL_TOOL )
53
+ TOOL_PATH = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), TOOL )
54
+ TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".platformio" )
55
+ IDF_TOOLS = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tl-install" , "tools" , "idf_tools.py" )
56
+ TOOLS_JSON_PATH = os .path .join (INSTALL_TOOL_PATH , "tools.json" )
57
+ TOOLS_PACK_PATH = os .path .join (INSTALL_TOOL_PATH , "package.json" )
58
+ IDF_TOOLS_CMD = (
59
+ python_exe ,
60
+ IDF_TOOLS ,
61
+ "--quiet" ,
62
+ "--non-interactive" ,
63
+ "--tools-json" ,
64
+ TOOLS_JSON_PATH ,
65
+ "install"
66
+ )
67
+
68
+ tl_flag = bool (os .path .exists (IDF_TOOLS ))
69
+ json_flag = bool (os .path .exists (TOOLS_JSON_PATH ))
70
+ tool_flag = bool (os .path .exists (TOOL_PATH ))
71
+ if tl_flag and json_flag and not tool_flag :
72
+ rc = subprocess .call (IDF_TOOLS_CMD )
73
+ if rc != 0 :
74
+ sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install'\n " )
75
+ else :
76
+ tl_path = "file://" + join (TOOLS_PATH_DEFAULT , "tools" , TOOL )
77
+ if not os .path .exists (join (TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" )):
78
+ shutil .copyfile (TOOLS_PACK_PATH , join (TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" ))
79
+ pm .install (tl_path )
80
+ # tool is already installed, just activate it
81
+ self .packages [TOOL ]["version" ] = TOOL_PATH
82
+ self .packages [TOOL ]["optional" ] = False
83
+ self .packages .pop (INSTALL_TOOL , None )
84
+ return
85
+
79
86
# Installer only needed for setup, deactivate when installed
80
87
if bool (os .path .exists (os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tl-install" , "tools" , "idf_tools.py" ))):
81
88
self .packages ["tl-install" ]["optional" ] = True
82
- # Installed not from pio registry, deactivate until needed
83
- self .packages ["tool-openocd-esp32" ]["optional" ] = True
84
89
85
90
if "arduino" in frameworks :
86
91
self .packages ["framework-arduinoespressif32" ]["optional" ] = False
@@ -129,14 +134,13 @@ def configure_default_packages(self, variables, targets):
129
134
else :
130
135
del self .packages ["tool-dfuutil-arduino" ]
131
136
132
- # Starting from v12, Espressif's toolchains are shipped without
133
- # bundled GDB. Instead, it's distributed as separate packages for Xtensa
134
- # and RISC-V targets.
137
+ # install GDB and OpenOCD when debug mode or upload_protocol is set
135
138
if (variables .get ("build_type" ) or "debug" in "" .join (targets )) or variables .get ("upload_protocol" ):
136
139
for gdb_package in ("tool-xtensa-esp-elf-gdb" , "tool-riscv32-esp-elf-gdb" ):
137
140
self .packages [gdb_package ]["optional" ] = False
138
141
install_tool ("tool-openocd-esp32" )
139
- self .packages ["tool-openocd-esp32" ]["optional" ] = False
142
+ else :
143
+ self .packages ["install-openocd-esp32" ]["optional" ] = True
140
144
141
145
# Common packages for IDF and mixed Arduino+IDF projects
142
146
if "espidf" in frameworks :
0 commit comments