13
13
# limitations under the License.
14
14
15
15
import os
16
- import urllib
16
+ import subprocess
17
17
import sys
18
- import json
19
- import re
20
- import requests
18
+ import shutil
19
+ from os .path import join
21
20
22
21
from platformio .public import PlatformBase , to_unix_path
22
+ from platformio .proc import get_pythonexe_path
23
+ from platformio .project .config import ProjectConfig
24
+ from platformio .package .manager .tool import ToolPackageManager
23
25
24
26
25
27
IS_WINDOWS = sys .platform .startswith ("win" )
29
31
if IS_WINDOWS :
30
32
os .environ ["PLATFORMIO_SYSTEM_TYPE" ] = "windows_amd64"
31
33
34
+ python_exe = get_pythonexe_path ()
35
+ pm = ToolPackageManager ()
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
+ shutil .copyfile (TOOLS_PACK_PATH , join (TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" ))
61
+ pm .install (tl_path )
62
+ return
63
+
32
64
33
65
class Espressif32Platform (PlatformBase ):
34
66
def configure_default_packages (self , variables , targets ):
@@ -43,7 +75,12 @@ def configure_default_packages(self, variables, targets):
43
75
core_variant_build = ('' .join (variables .get ("build_flags" , []))).replace ("-D" , " " )
44
76
frameworks = variables .get ("pioframework" , [])
45
77
46
- if "arduino" in frameworks :
78
+ # Installer only needed for setup, deactivate
79
+ self .packages ["tl-install" ]["optional" ] = True
80
+ # Installed not from pio registry, deactivate until needed
81
+ self .packages ["tool-openocd-esp32" ]["optional" ] = True
82
+
83
+ if "arduino" in frameworks and variables .get ("custom_sdkconfig" ) is None and len (str (board_sdkconfig )) < 3 :
47
84
self .packages ["framework-arduinoespressif32" ]["optional" ] = False
48
85
self .packages ["framework-arduinoespressif32-libs" ]["optional" ] = False
49
86
# use matching espressif Arduino libs
@@ -93,21 +130,20 @@ def configure_default_packages(self, variables, targets):
93
130
# Starting from v12, Espressif's toolchains are shipped without
94
131
# bundled GDB. Instead, it's distributed as separate packages for Xtensa
95
132
# and RISC-V targets.
96
- for gdb_package in ("tool-xtensa-esp-elf-gdb" , "tool-riscv32-esp-elf-gdb" ):
97
- self .packages [gdb_package ]["optional" ] = False
98
- # if IS_WINDOWS:
99
- # Note: On Windows GDB v12 is not able to
100
- # launch a GDB server in pipe mode while v11 works fine
101
- # self.packages[gdb_package]["version"] = "~11.2.0"
133
+ if (variables .get ("build_type" ) or "debug" in "" .join (targets )) or variables .get ("upload_protocol" ):
134
+ for gdb_package in ("tool-xtensa-esp-elf-gdb" , "tool-riscv32-esp-elf-gdb" ):
135
+ self .packages [gdb_package ]["optional" ] = False
136
+ install_tool ("tool-openocd-esp32" )
137
+ self .packages ["tool-openocd-esp32" ]["optional" ] = False
102
138
103
139
# Common packages for IDF and mixed Arduino+IDF projects
104
140
if "espidf" in frameworks :
105
141
self .packages ["toolchain-esp32ulp" ]["optional" ] = False
106
142
for p in self .packages :
107
143
if p in (
108
- "tool-scons" ,
109
144
"tool-cmake" ,
110
145
"tool-ninja" ,
146
+ "tool-scons" ,
111
147
"tool-esp-rom-elfs" ,
112
148
):
113
149
self .packages [p ]["optional" ] = False
@@ -119,8 +155,8 @@ def configure_default_packages(self, variables, targets):
119
155
else :
120
156
self .packages .pop ("toolchain-xtensa-esp-elf" , None )
121
157
122
- if mcu in ("esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" , "esp32p4" ):
123
- if mcu in ("esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" , "esp32p4" ):
158
+ if mcu in ("esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c5" , " esp32c6" , "esp32h2" , "esp32p4" ):
159
+ if mcu in ("esp32c2" , "esp32c3" , "esp32c5" , " esp32c6" , "esp32h2" , "esp32p4" ):
124
160
self .packages .pop ("toolchain-esp32ulp" , None )
125
161
# RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
126
162
self .packages ["toolchain-riscv32-esp" ]["optional" ] = False
0 commit comments