Skip to content

Commit 9d5cc62

Browse files
committed
Dynamically detect the main component name // Resolve platformio#330
CMake uses the folder name as component target
1 parent ddc18c0 commit 9d5cc62

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

builder/frameworks/espidf.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,21 +865,22 @@ def find_default_component(target_configs):
865865

866866
sdk_config = get_sdk_configuration()
867867

868-
if all(t in target_configs for t in ("__idf_src", "__idf_main")):
868+
869+
project_target_name = "__idf_%s" % basename(env.subst("$PROJECT_SRC_DIR"))
870+
if project_target_name not in target_configs:
871+
sys.stderr.write("Error: Couldn't find the main target of the project!\n")
872+
env.Exit(1)
873+
874+
if all(t in target_configs for t in (project_target_name, "__idf_main")):
869875
sys.stderr.write(
870876
(
871877
"Warning! Detected two different targets with project sources. Please use "
872-
"either 'src' or specify 'main' folder in 'platformio.ini' file.\n"
878+
"either %s or specify 'main' folder in 'platformio.ini' file.\n"
879+
% project_target_name
873880
)
874881
)
875882
env.Exit(1)
876883

877-
878-
project_target_name = "__idf_main" if "__idf_main" in target_configs else "__idf_src"
879-
if project_target_name not in target_configs:
880-
sys.stderr.write("Error: Couldn't find the main target of the project!\n")
881-
env.Exit(1)
882-
883884
project_ld_scipt = generate_project_ld_script(
884885
sdk_config, [project_target_name, "__pio_env"])
885886
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", project_ld_scipt)

0 commit comments

Comments
 (0)