30
30
from os .path import join
31
31
32
32
from SCons .Script import COMMAND_LINE_TARGETS , DefaultEnvironment , SConscript
33
+ from platformio import fs
33
34
from platformio .package .version import pepver_to_semver
34
35
from platformio .project .config import ProjectConfig
35
36
from platformio .package .manager .tool import ToolPackageManager
55
56
framework_reinstall = False
56
57
flag_any_custom_sdkconfig = False
57
58
59
+ FRAMEWORK_LIB_DIR = platform .get_package_dir ("framework-arduinoespressif32-libs" )
60
+
58
61
SConscript ("_embed_files.py" , exports = "env" )
59
62
60
63
flag_any_custom_sdkconfig = os .path .exists (join (platform .get_package_dir ("framework-arduinoespressif32-libs" ),"sdkconfig" ))
@@ -171,6 +174,59 @@ def check_reinstall_frwrk():
171
174
framework_reinstall = True
172
175
return framework_reinstall
173
176
177
+
178
+ FRAMEWORK_SDK_DIR = fs .to_unix_path (
179
+ os .path .join (
180
+ FRAMEWORK_LIB_DIR ,
181
+ mcu ,
182
+ "include" ,
183
+ )
184
+ )
185
+
186
+ IS_INTEGRATION_DUMP = env .IsIntegrationDump ()
187
+
188
+
189
+ def is_framework_subfolder (potential_subfolder ):
190
+ if not os .path .isabs (potential_subfolder ):
191
+ return False
192
+ if (
193
+ os .path .splitdrive (FRAMEWORK_SDK_DIR )[0 ]
194
+ != os .path .splitdrive (potential_subfolder )[0 ]
195
+ ):
196
+ return False
197
+ return os .path .commonpath ([FRAMEWORK_SDK_DIR ]) == os .path .commonpath (
198
+ [FRAMEWORK_SDK_DIR , potential_subfolder ]
199
+ )
200
+
201
+
202
+ def shorthen_includes (env , node ):
203
+ if IS_INTEGRATION_DUMP :
204
+ # Don't shorten include paths for IDE integrations
205
+ return node
206
+
207
+ includes = [fs .to_unix_path (inc ) for inc in env .get ("CPPPATH" , [])]
208
+ shortened_includes = []
209
+ generic_includes = []
210
+ for inc in includes :
211
+ if is_framework_subfolder (inc ):
212
+ shortened_includes .append (
213
+ "-iwithprefix/"
214
+ + fs .to_unix_path (os .path .relpath (inc , FRAMEWORK_SDK_DIR ))
215
+ )
216
+ else :
217
+ generic_includes .append (inc )
218
+
219
+ return env .Object (
220
+ node ,
221
+ CPPPATH = generic_includes ,
222
+ CCFLAGS = env ["CCFLAGS" ]
223
+ + ["-iprefix" , FRAMEWORK_SDK_DIR ]
224
+ + shortened_includes ,
225
+ ASFLAGS = env ["ASFLAGS" ]
226
+ + ["-iprefix" , FRAMEWORK_SDK_DIR ]
227
+ + shortened_includes ,
228
+ )
229
+
174
230
def call_compile_libs ():
175
231
if mcu == "esp32c2" :
176
232
ARDUINO_FRMWRK_C2_LIB_DIR = join (platform .get_package_dir ("framework-arduinoespressif32-libs" ),mcu )
@@ -192,11 +248,10 @@ def call_compile_libs():
192
248
call_compile_libs ()
193
249
194
250
if "arduino" in env .subst ("$PIOFRAMEWORK" ) and "espidf" not in env .subst ("$PIOFRAMEWORK" ) and env .subst ("$ARDUINO_LIB_COMPILE_FLAG" ) in ("Inactive" , "True" ):
251
+ env .AddBuildMiddleware (shorthen_includes )
195
252
if os .path .exists (join (platform .get_package_dir (
196
253
"framework-arduinoespressif32" ), "tools" , "platformio-build.py" )):
197
254
PIO_BUILD = "platformio-build.py"
198
255
else :
199
256
PIO_BUILD = "pioarduino-build.py"
200
- SConscript (
201
- join (DefaultEnvironment ().PioPlatform ().get_package_dir (
202
- "framework-arduinoespressif32" ), "tools" , PIO_BUILD ))
257
+ SConscript (join (platform .get_package_dir ("framework-arduinoespressif32" ), "tools" , PIO_BUILD ))
0 commit comments