12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import json
15
16
import os
16
17
import subprocess
17
18
import sys
24
25
from platformio .project .config import ProjectConfig
25
26
from platformio .package .manager .tool import ToolPackageManager
26
27
28
+ def get_tool_version_from_platform_json (tool_name ):
29
+ platform_json_path = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "platforms_dir" ), "espressif32" , "platform.json" )
30
+ with open (platform_json_path , "r" , encoding = "utf-8" ) as file :
31
+ platform_data = json .load (file )
32
+ packages = platform_data .get ("packages" , {})
33
+ tool_info = packages [tool_name ]
34
+ version = tool_info .get ("version" , "" ) # version is an URL!
35
+ return version
36
+
27
37
IS_WINDOWS = sys .platform .startswith ("win" )
28
38
# Set Platformio env var to use windows_amd64 for all windows architectures
29
39
# only windows_amd64 native espressif toolchains are available
34
44
python_exe = get_pythonexe_path ()
35
45
pm = ToolPackageManager ()
36
46
47
+ if not os .path .exists (os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tool-scons" )):
48
+ scons_uri = get_tool_version_from_platform_json ("tool-scons" )
49
+ if scons_uri is not None :
50
+ pm .install (scons_uri )
51
+
52
+ if not os .path .exists (os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tool-esp-rom-elfs" )):
53
+ rom_uri = get_tool_version_from_platform_json ("tool-esp-rom-elfs" )
54
+ if rom_uri is not None :
55
+ pm .install (rom_uri )
56
+
37
57
IDF_TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".espressif" )
38
58
IDF_TOOLS = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tl-install" , "tools" , "idf_tools.py" )
39
59
IDF_TOOLS_CMD = (
53
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" ):
54
74
tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , p )
55
75
pm .install (tl_path )
56
- pm .install ("tool-scons" )
57
76
58
77
class Espressif32Platform (PlatformBase ):
59
78
def configure_default_packages (self , variables , targets ):
@@ -68,6 +87,13 @@ def configure_default_packages(self, variables, targets):
68
87
core_variant_build = ('' .join (variables .get ("build_flags" , []))).replace ("-D" , " " )
69
88
frameworks = variables .get ("pioframework" , [])
70
89
90
+ if variables .get ("custom_sdkconfig" ) is not None :
91
+ frameworks .append ("espidf" )
92
+
93
+ if variables .get ("custom_sdkconfig" ) is not None or len (str (board_sdkconfig )) > 3 :
94
+ frameworks .append ("espidf" )
95
+ self .packages ["framework-espidf" ]["optional" ] = False
96
+
71
97
# Enable debug tool gdb only when build debug is enabled
72
98
if (variables .get ("build_type" ) or "debug" in "" .join (targets )) and tl_flag :
73
99
self .packages ["riscv32-esp-elf-gdb" ]["optional" ] = False if mcu in ["esp32c2" , "esp32c3" , "esp32c5" , "esp32c6" , "esp32h2" , "esp32p4" ] else True
@@ -98,10 +124,10 @@ def configure_default_packages(self, variables, targets):
98
124
self .packages ["framework-arduinoespressif32-libs" ]["version" ] = dyn_lib_url
99
125
100
126
if variables .get ("custom_sdkconfig" ) is not None or len (str (board_sdkconfig )) > 3 :
101
- frameworks .append ("espidf" )
102
- self .packages ["framework-espidf" ]["optional" ] = False
103
127
if mcu == "esp32c2" :
104
128
self .packages ["framework-arduino-c2-skeleton-lib" ]["optional" ] = False
129
+ frameworks .append ("espidf" )
130
+ self .packages ["framework-espidf" ]["optional" ] = False
105
131
106
132
# packages for IDF and mixed Arduino+IDF projects
107
133
if tl_flag and "espidf" in frameworks :
@@ -114,7 +140,7 @@ def configure_default_packages(self, variables, targets):
114
140
):
115
141
self .packages [p ]["optional" ] = False
116
142
117
- if "" .join (targets ) in ("upload" , "buildfs" , "uploadfs" ):
143
+ if tl_flag and ( "" .join (targets ) in ("upload" , "buildfs" , "uploadfs" ) or variables . get ( "custom_files_upload" ) is not None ):
118
144
filesystem = variables .get ("board_build.filesystem" , "littlefs" )
119
145
if filesystem == "littlefs" :
120
146
# Use mklittlefs v3.2.0 to generate FS
0 commit comments