Skip to content

Commit 537ced1

Browse files
committed
Improve handling project source files for ESP-IDF
Use AddBuildMiddleware helper instead of overriding SRC_FILTER
1 parent 844b756 commit 537ced1

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

builder/frameworks/espidf.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,13 @@ def _extract_flags(config):
343343
flags = {}
344344
for cg in config["compileGroups"]:
345345
flags[cg["language"]] = []
346-
for ccfragment in cg["compileCommandFragments"]:
347-
fragment = ccfragment.get("fragment", "")
348-
if not fragment.strip() or fragment.startswith("-D"):
349-
continue
346+
for ccfragment in cg["compileCommandFragments"]:
347+
fragment = ccfragment.get("fragment", "")
348+
if not fragment.strip() or fragment.startswith("-D"):
349+
continue
350350
flags[cg["language"]].extend(
351-
click.parser.split_arg_string(fragment.strip())
352-
)
351+
click.parser.split_arg_string(fragment.strip())
352+
)
353353

354354
return flags
355355

@@ -391,7 +391,7 @@ def find_framework_service_files(search_path, sdk_config):
391391
result["kconfig_files"].append(join(search_path, d, f))
392392

393393
result["lf_files"].extend([
394-
join(FRAMEWORK_DIR, "components", "esp32", "ld", "esp32_fragments.lf"),
394+
join(FRAMEWORK_DIR, "components", "esp32", "ld", "esp32_fragments.lf"),
395395
join(FRAMEWORK_DIR, "components", "newlib", "newlib.lf")
396396
])
397397

@@ -794,13 +794,12 @@ def find_default_component(target_configs):
794794

795795

796796
if env.subst("$SRC_FILTER"):
797-
sys.stderr.write(
797+
print(
798798
(
799-
"Error: the 'src_filter' option cannot be used with ESP-IDF. Select source "
799+
"Warning: the 'src_filter' option cannot be used with ESP-IDF. Select source "
800800
"files to build in the project CMakeLists.txt file.\n"
801801
)
802802
)
803-
env.Exit(1)
804803

805804
if isfile(join(env.subst("$PROJECT_SRC_DIR"), "sdkconfig.h")):
806805
print(
@@ -921,22 +920,47 @@ def find_default_component(target_configs):
921920
except:
922921
print("Warning! Couldn't find the main linker script in the CMake code model.")
923922

924-
envsafe = env.Clone()
925-
if project_target_name != "__idf_main":
926-
# Manually add dependencies to CPPPATH since ESP-IDF build system doesn't generate
927-
# this info if the folder with sources is not named 'main'
928-
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#rename-main
929-
envsafe.AppendUnique(CPPPATH=app_includes["plain_includes"])
923+
#
924+
# Process project sources
925+
#
926+
927+
# Remove project source files from following build stages as they're
928+
# built as part of the framework
929+
def _skip_prj_source_files(node):
930+
if (
931+
node.srcnode()
932+
.get_path()
933+
.lower()
934+
.startswith(env.subst("$PROJECT_SRC_DIR").lower())
935+
):
936+
return None
937+
return node
938+
939+
940+
env.AddBuildMiddleware(_skip_prj_source_files)
941+
942+
# Project files should be compiled only when a special
943+
# option is enabled when running 'test' command
944+
if "__test" not in COMMAND_LINE_TARGETS or env.GetProjectOption(
945+
"test_build_project_src"
946+
):
947+
project_env = env.Clone()
948+
if project_target_name != "__idf_main":
949+
# Manually add dependencies to CPPPATH since ESP-IDF build system doesn't generate
950+
# this info if the folder with sources is not named 'main'
951+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#rename-main
952+
project_env.AppendUnique(CPPPATH=app_includes["plain_includes"])
930953

931954
# Add default include dirs to global CPPPATH so they're visible to PIOBUILDFILES
932955
envsafe.Append(CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR"])
933956

934-
env.Replace(SRC_FILTER="-<*>")
935-
env.Append(
936-
PIOBUILDFILES=compile_source_files(
937-
target_configs.get(project_target_name), envsafe, envsafe.subst("$PROJECT_DIR")
957+
env.Append(
958+
PIOBUILDFILES=compile_source_files(
959+
target_configs.get(project_target_name),
960+
project_env,
961+
project_env.subst("$PROJECT_DIR"),
962+
)
938963
)
939-
)
940964

941965
project_flags.update(link_args)
942966
env.MergeFlags(project_flags)

0 commit comments

Comments
 (0)