From e6c46258ddcbd227c621c4ffc99de21968f600fc Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Wed, 8 Oct 2025 17:42:42 +0200 Subject: [PATCH] fix(cmakev2): Add workaround in idf_build_component for duplicate managed component This commit adds a workaround in idf_build_component shim to avoid initialization of a duplicate managed component. The component manager when running on a Windows system returns duplicate managed components upon successive invocations. --- tools/cmakev2/compat.cmake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/cmakev2/compat.cmake b/tools/cmakev2/compat.cmake index 983d0f3b7d6..57f04002bad 100644 --- a/tools/cmakev2/compat.cmake +++ b/tools/cmakev2/compat.cmake @@ -533,6 +533,28 @@ function(idf_build_component component_dir) set(component_source ${ARGV1}) endif() + # Get the component name and check if it's already initialized + get_filename_component(component_name "${component_dir}" NAME) + __get_component_interface(COMPONENT "${component_name}" OUTPUT existing_interface) + + if(existing_interface) + # Component already exists, check if it's from the same directory and source + idf_component_get_property(existing_dir "${existing_interface}" COMPONENT_DIR) + idf_component_get_property(existing_source "${existing_interface}" COMPONENT_SOURCE) + + # If same directory and same source, skip re-initialization + # This handles the case where component manager may output the same component + # multiple times due to path separator issues on Windows. + # TODO: Remove this workaround once idf-component-manager is fixed (IDF-14260) + if("${component_dir}" STREQUAL "${existing_dir}" AND + "${component_source}" STREQUAL "${existing_source}") + # Component already initialized from the same location, skip duplicate + return() + endif() + + # Different directory or source, let __init_component handle the priority logic + endif() + idf_build_get_property(component_prefix PREFIX) __init_component(DIRECTORY "${component_dir}" PREFIX "${component_prefix}"