Skip to content

Commit 5e0f9e4

Browse files
committed
Add missing includes from project library for ESP-IDF // Resolve platformio#316
1 parent 537ced1 commit 5e0f9e4

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

builder/frameworks/espidf.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
DefaultEnvironment,
4848
)
4949

50+
from platformio.builder.tools.piolib import ProjectAsLibBuilder
5051
from platformio.fs import to_unix_path
5152
from platformio.proc import exec_command, where_is_program
5253
from platformio.util import get_systype
@@ -93,6 +94,22 @@
9394
CMAKE_API_REPLY_PATH = join(".cmake", "api", "v1", "reply")
9495

9596

97+
def get_project_lib_includes(env):
98+
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
99+
project.search_deps_recursive()
100+
101+
paths = []
102+
for lb in env.GetLibBuilders():
103+
if not lb.dependent:
104+
continue
105+
lb.env.PrependUnique(CPPPATH=lb.get_include_dirs())
106+
paths.extend(lb.env["CPPPATH"])
107+
108+
DefaultEnvironment().Replace(__PIO_LIB_BUILDERS=None)
109+
110+
return paths
111+
112+
96113
def is_cmake_reconfigure_required(cmake_api_reply_dir):
97114
cmake_cache_file = join(BUILD_DIR, "CMakeCache.txt")
98115
cmake_txt_file = join(env.subst("$PROJECT_DIR"), "CMakeLists.txt")
@@ -875,13 +892,12 @@ def find_default_component(target_configs):
875892
env.Depends(project_ld_scipt, component_config["lib"])
876893

877894
project_config = target_configs.get(project_target_name, {})
878-
project_includes = get_app_includes(project_config)
879895
default_config = target_configs.get(default_config_name, {})
880896
project_defines = get_app_defines(project_config)
881897
project_flags = get_app_flags(project_config, default_config)
882898
link_args = extract_link_args(elf_config)
883-
884899
app_includes = get_app_includes(elf_config)
900+
project_lib_includes = get_project_lib_includes(env)
885901

886902
#
887903
# Compile bootloader
@@ -951,8 +967,11 @@ def _skip_prj_source_files(node):
951967
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#rename-main
952968
project_env.AppendUnique(CPPPATH=app_includes["plain_includes"])
953969

954-
# Add default include dirs to global CPPPATH so they're visible to PIOBUILDFILES
955-
envsafe.Append(CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR"])
970+
# Add include dirs from PlatformIO build system to project CPPPATH so
971+
# they're visible to PIOBUILDFILES
972+
project_env.Append(
973+
CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR"] + project_lib_includes
974+
)
956975

957976
env.Append(
958977
PIOBUILDFILES=compile_source_files(

0 commit comments

Comments
 (0)