14
14
15
15
import os
16
16
import subprocess
17
- import urllib
18
17
import sys
19
- import json
20
- import re
21
- import requests
22
18
import shutil
23
- from os .path import isfile , isdir , join
19
+ from os .path import isfile , join
24
20
25
21
from platformio .public import PlatformBase , to_unix_path
26
22
from platformio .proc import get_pythonexe_path
23
+ from platformio .package .manager .tool import ToolPackageManager
27
24
28
25
python_exe = get_pythonexe_path ()
26
+ pm = ToolPackageManager ()
29
27
IS_WINDOWS = sys .platform .startswith ("win" )
30
28
IDF_TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".espressif" )
31
- IDF_TOOLS = os .path .join (os .path .expanduser ("~" ), ".platformio" , "packages" , "tl-install" , "tools" , "idf_tools.py" )
29
+ try :
30
+ tl_path = pm .get_package ("tl-install" ).path
31
+ IDF_TOOLS = os .path .join (tl_path , "tools" , "idf_tools.py" )
32
+ except :
33
+ IDF_TOOLS = ""
32
34
IDF_TOOLS_FLAG = ["install" ]
33
35
IDF_TOOLS_CMD = [python_exe , IDF_TOOLS ] + IDF_TOOLS_FLAG
34
36
@@ -41,16 +43,20 @@ def configure_default_packages(self, variables, targets):
41
43
board_config = self .board_config (variables .get ("board" ))
42
44
mcu = variables .get ("board_build.mcu" , board_config .get ("build.mcu" , "esp32" ))
43
45
frameworks = variables .get ("pioframework" , [])
46
+ try :
47
+ tl_flag = bool (pm .get_package ("tl-install" ).path )
48
+ except :
49
+ tl_flag = False
44
50
45
51
# IDF Install is needed only one time
46
- if not os .path .exists (join (IDF_TOOLS_PATH_DEFAULT , "tools" )) and os . path . exists ( IDF_TOOLS ) :
52
+ if not os .path .exists (join (IDF_TOOLS_PATH_DEFAULT , "tools" )) and tl_flag :
47
53
rc = subprocess .call (IDF_TOOLS_CMD )
48
54
if rc != 0 :
49
55
sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install' \n " )
50
56
else :
51
57
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 )
52
58
53
- if os . path . exists ( IDF_TOOLS ) :
59
+ if tl_flag :
54
60
# Install all tools and toolchains
55
61
self .packages ["tl-install" ]["optional" ] = True
56
62
for p in self .packages :
@@ -62,6 +68,17 @@ def configure_default_packages(self, variables, targets):
62
68
for p in self .packages :
63
69
if p in ("tool-cmake" , "tool-ninja" , "tc-ulp" ):
64
70
self .packages [p ]["optional" ] = False if "espidf" in frameworks else True
71
+ # Enabling of following tools is not needed, installing is enough
72
+ for p in self .packages :
73
+ if p in ("contrib-pioremote" , "contrib-piohome" , "tool-scons" ):
74
+ try :
75
+ pkg_dir = pm .get_package (p ).path
76
+ # When package is not found an execption happens -> install is forced
77
+ # else the are removed from current env
78
+ self .packages [p ]["optional" ] = True
79
+ except :
80
+ pass
81
+
65
82
66
83
# Enable debug tool gdb only when build debug is enabled
67
84
if variables .get ("build_type" ) or "debug" in "" .join (targets ):
@@ -71,7 +88,7 @@ def configure_default_packages(self, variables, targets):
71
88
self .packages ["tl-rv-gdb" ]["optional" ] = True
72
89
self .packages ["tl-xt-gdb" ]["optional" ] = True
73
90
74
- # Enable check tools only when "check_tool" is set in platformio.ini
91
+ # Enable check tools only when "check_tool" is enabled
75
92
for p in self .packages :
76
93
if p in ("tool-cppcheck" , "tool-clangtidy" , "tool-pvs-studio" ):
77
94
self .packages [p ]["optional" ] = False if str (variables .get ("check_tool" )).strip ("['']" ) in p else True
@@ -123,7 +140,7 @@ def configure_default_packages(self, variables, targets):
123
140
124
141
# Enable needed toolchains
125
142
for available_mcu in ("esp32" , "esp32s2" , "esp32s3" ):
126
- if available_mcu == mcu and os . path . exists ( IDF_TOOLS ) :
143
+ if available_mcu == mcu and tl_flag :
127
144
tc_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tc-xt-%s" % mcu )
128
145
self .packages ["tc-xt-%s" % mcu ]["optional" ] = False
129
146
self .packages ["tc-xt-%s" % mcu ]["version" ] = tc_path
@@ -134,7 +151,7 @@ def configure_default_packages(self, variables, targets):
134
151
if mcu in ("esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ):
135
152
del self .packages ["tc-ulp" ]
136
153
# RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
137
- if os . path . exists ( IDF_TOOLS ) :
154
+ if tl_flag :
138
155
self .packages ["tc-rv32" ]["optional" ] = False
139
156
140
157
return super ().configure_default_packages (variables , targets )
0 commit comments