25
25
import subprocess
26
26
import sys
27
27
import os
28
+ import pkg_resources
28
29
29
30
import click
30
31
import semantic_version
49
50
mcu = board .get ("build.mcu" , "esp32" )
50
51
idf_variant = mcu .lower ()
51
52
53
+ # Required until Arduino switches to v5
54
+ IDF5 = platform .get_package_version (
55
+ "framework-espidf" ).split ("." )[1 ].startswith ("5" )
52
56
FRAMEWORK_DIR = platform .get_package_dir ("framework-espidf" )
53
57
TOOLCHAIN_DIR = platform .get_package_dir (
54
58
"toolchain-%s" % ("riscv32-esp" if mcu == "esp32c3" else ("xtensa-%s" % mcu ))
@@ -576,6 +580,16 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
576
580
)
577
581
578
582
583
+ # A temporary workaround to avoid modifying CMake mainly for the "heap" library.
584
+ # The "tlsf.c" source file in this library has an include flag relative
585
+ # to CMAKE_CURRENT_SOURCE_DIR which breaks PlatformIO builds that have a
586
+ # different working directory
587
+ def _fix_component_relative_include (config , build_flags , source_index ):
588
+ source_file_path = config ["sources" ][source_index ]["path" ]
589
+ build_flags = build_flags .replace (".." , os .path .dirname (source_file_path ) + "/.." )
590
+ return build_flags
591
+
592
+
579
593
def prepare_build_envs (config , default_env , debug_allowed = True ):
580
594
build_envs = []
581
595
target_compile_groups = config .get ("compileGroups" )
@@ -597,6 +611,10 @@ def prepare_build_envs(config, default_env, debug_allowed=True):
597
611
for cc in compile_commands :
598
612
build_flags = cc .get ("fragment" )
599
613
if not build_flags .startswith ("-D" ):
614
+ if build_flags .startswith ("-include" ) and ".." in build_flags :
615
+ source_index = cg .get ("sourceIndexes" )[0 ]
616
+ build_flags = _fix_component_relative_include (
617
+ config , build_flags , source_index )
600
618
build_env .AppendUnique (** build_env .ParseFlags (build_flags ))
601
619
build_env .AppendUnique (CPPDEFINES = defines , CPPPATH = includes )
602
620
if sys_includes :
@@ -639,9 +657,17 @@ def compile_source_files(
639
657
else :
640
658
obj_path = os .path .join (obj_path , os .path .basename (src_path ))
641
659
660
+ preserve_source_file_extension = board .get (
661
+ "build.esp-idf.preserve_source_file_extension" , False
662
+ )
663
+
642
664
objects .append (
643
665
build_envs [compile_group_idx ].StaticObject (
644
- target = os .path .splitext (obj_path )[0 ] + ".o" ,
666
+ target = (
667
+ obj_path
668
+ if preserve_source_file_extension
669
+ else os .path .splitext (obj_path )[0 ]
670
+ ) + ".o" ,
645
671
source = os .path .realpath (src_path ),
646
672
)
647
673
)
@@ -1029,7 +1055,14 @@ def _get_installed_pip_packages():
1029
1055
result = {}
1030
1056
packages = {}
1031
1057
pip_output = subprocess .check_output (
1032
- [env .subst ("$PYTHONEXE" ), "-m" , "pip" , "list" , "--format=json" ]
1058
+ [
1059
+ env .subst ("$PYTHONEXE" ),
1060
+ "-m" ,
1061
+ "pip" ,
1062
+ "list" ,
1063
+ "--format=json" ,
1064
+ "--disable-pip-version-check" ,
1065
+ ]
1033
1066
)
1034
1067
try :
1035
1068
packages = json .loads (pip_output )
@@ -1047,15 +1080,19 @@ def _get_installed_pip_packages():
1047
1080
"future" : ">=0.15.2" ,
1048
1081
"pyparsing" : ">=2.0.3,<2.4.0" ,
1049
1082
"kconfiglib" : "==13.7.1" ,
1050
- "idf-component-manager" : "~=1.0"
1083
+ "idf-component-manager" : "~=1.0" ,
1051
1084
}
1052
1085
1086
+ if IDF5 :
1087
+ # Remove specific versions for IDF5 as not required
1088
+ deps = {dep : "" for dep in deps }
1089
+
1053
1090
installed_packages = _get_installed_pip_packages ()
1054
1091
packages_to_install = []
1055
1092
for package , spec in deps .items ():
1056
1093
if package not in installed_packages :
1057
1094
packages_to_install .append (package )
1058
- else :
1095
+ elif spec :
1059
1096
version_spec = semantic_version .Spec (spec )
1060
1097
if not version_spec .match (installed_packages [package ]):
1061
1098
packages_to_install .append (package )
@@ -1064,21 +1101,34 @@ def _get_installed_pip_packages():
1064
1101
env .Execute (
1065
1102
env .VerboseAction (
1066
1103
(
1067
- '"$PYTHONEXE" -m pip install -U --force-reinstall '
1068
- + " " .join (['"%s%s"' % (p , deps [p ]) for p in packages_to_install ])
1104
+ '"$PYTHONEXE" -m pip install -U '
1105
+ + " " .join (
1106
+ [
1107
+ '"%s%s"' % (p , deps [p ])
1108
+ for p in packages_to_install
1109
+ ]
1110
+ )
1069
1111
),
1070
1112
"Installing ESP-IDF's Python dependencies" ,
1071
1113
)
1072
1114
)
1073
1115
1074
- # a special "esp-windows-curses" python package is required on Windows for Menuconfig
1075
- if "windows" in get_systype ():
1076
- import pkg_resources
1116
+ if "windows" in get_systype () and "windows-curses" not in installed_packages :
1117
+ env .Execute (
1118
+ env .VerboseAction (
1119
+ "$PYTHONEXE -m pip install windows-curses" ,
1120
+ "Installing windows-curses package" ,
1121
+ )
1122
+ )
1077
1123
1078
- if "esp-windows-curses" not in {pkg .key for pkg in pkg_resources .working_set }:
1124
+ # A special "esp-windows-curses" python package is required on Windows
1125
+ # for Menuconfig on IDF <5
1126
+ if not IDF5 and "esp-windows-curses" not in {
1127
+ pkg .key for pkg in pkg_resources .working_set
1128
+ }:
1079
1129
env .Execute (
1080
1130
env .VerboseAction (
1081
- '$PYTHONEXE -m pip install "file://%s/tools/kconfig_new/esp-windows-curses" windows-curses '
1131
+ '$PYTHONEXE -m pip install "file://%s/tools/kconfig_new/esp-windows-curses"'
1082
1132
% FRAMEWORK_DIR ,
1083
1133
"Installing windows-curses package" ,
1084
1134
)
@@ -1471,4 +1521,6 @@ def _skip_prj_source_files(node):
1471
1521
)
1472
1522
1473
1523
# Propagate application offset to debug configurations
1474
- env ["INTEGRATION_EXTRA_DATA" ].update ({"application_offset" : env .subst ("$ESP32_APP_OFFSET" )})
1524
+ env ["INTEGRATION_EXTRA_DATA" ].update (
1525
+ {"application_offset" : env .subst ("$ESP32_APP_OFFSET" )}
1526
+ )
0 commit comments