@@ -131,39 +131,65 @@ ifndef COMPONENT_DIRS
131131EXTRA_COMPONENT_DIRS ?=
132132COMPONENT_DIRS := $(PROJECT_PATH ) /components $(EXTRA_COMPONENT_DIRS ) $(IDF_PATH ) /components $(PROJECT_PATH ) /main
133133endif
134+ # Make sure that every directory in the list is an absolute path without trailing slash.
135+ # This is necessary to split COMPONENT_DIRS into SINGLE_COMPONENT_DIRS and MULTI_COMPONENT_DIRS below.
136+ COMPONENT_DIRS := $(foreach cd,$(COMPONENT_DIRS ) ,$(abspath $(cd ) ) )
134137export COMPONENT_DIRS
135138
136139ifdef SRCDIRS
137140$(warning SRCDIRS variable is deprecated. These paths can be added to EXTRA_COMPONENT_DIRS or COMPONENT_DIRS instead.)
138141COMPONENT_DIRS += $(abspath $(SRCDIRS ) )
139142endif
140143
141- # The project Makefile can define a list of components, but if it does not do this we just take all available components
142- # in the component dirs. A component is COMPONENT_DIRS directory, or immediate subdirectory,
144+ # List of component directories, i.e. directories which contain a component.mk file
145+ SINGLE_COMPONENT_DIRS := $(abspath $(dir $(dir $(foreach cd,$(COMPONENT_DIRS ) ,\
146+ $(wildcard $(cd ) /component.mk) ) ) ) )
147+
148+ # List of components directories, i.e. directories which may contain components
149+ MULTI_COMPONENT_DIRS := $(filter-out $(SINGLE_COMPONENT_DIRS ) ,$(COMPONENT_DIRS ) )
150+
151+ # The project Makefile can define a list of components, but if it does not do this
152+ # we just take all available components in the component dirs.
153+ # A component is COMPONENT_DIRS directory, or immediate subdirectory,
143154# which contains a component.mk file.
144155#
145156# Use the "make list-components" target to debug this step.
146157ifndef COMPONENTS
147158# Find all component names. The component names are the same as the
148159# directories they're in, so /bla/components/mycomponent/component.mk -> mycomponent.
149- COMPONENTS := $(dir $(foreach cd,$(COMPONENT_DIRS ) , \
150- $(wildcard $(cd ) /* /component.mk) $(wildcard $(cd ) /component.mk) \
151- ) )
160+ # We need to do this for MULTI_COMPONENT_DIRS only, since SINGLE_COMPONENT_DIRS
161+ # are already known to contain component.mk.
162+ COMPONENTS := $(dir $(foreach cd,$(MULTI_COMPONENT_DIRS ) ,$(wildcard $(cd ) /* /component.mk) ) ) \
163+ $(SINGLE_COMPONENT_DIRS )
152164COMPONENTS := $(sort $(foreach comp,$(COMPONENTS ) ,$(lastword $(subst /, ,$(comp ) ) ) ) )
153165endif
154- # After a full manifest of component names is determined, subtract the ones explicitly omitted by the project Makefile.
166+ # After a full manifest of component names is determined, subtract the ones explicitly
167+ # omitted by the project Makefile.
168+ EXCLUDE_COMPONENTS ?=
155169ifdef EXCLUDE_COMPONENTS
156- COMPONENTS := $(filter-out $(EXCLUDE_COMPONENTS ) , $(COMPONENTS ) )
170+ COMPONENTS := $(filter-out $(subst ",,$(EXCLUDE_COMPONENTS ) ) , $(COMPONENTS ) )
171+ # to keep syntax highlighters happy: "))
157172endif
158173export COMPONENTS
159174
160175# Resolve all of COMPONENTS into absolute paths in COMPONENT_PATHS.
176+ # For each entry in COMPONENT_DIRS:
177+ # - either this is directory with multiple components, in which case check that
178+ # a subdirectory with component name exists, and it contains a component.mk file.
179+ # - or, this is a directory of a single component, in which case the name of this
180+ # directory has to match the component name
161181#
162182# If a component name exists in multiple COMPONENT_DIRS, we take the first match.
163183#
164184# NOTE: These paths must be generated WITHOUT a trailing / so we
165185# can use $(notdir x) to get the component name.
166- COMPONENT_PATHS := $(foreach comp,$(COMPONENTS ) ,$(firstword $(foreach cd,$(COMPONENT_DIRS ) ,$(wildcard $(dir $(cd ) )$(comp ) $(cd ) /$(comp ) ) ) ) )
186+ COMPONENT_PATHS := $(foreach comp,$(COMPONENTS ) ,\
187+ $(firstword $(foreach cd,$(COMPONENT_DIRS ) ,\
188+ $(if $(findstring $(cd ) ,$(MULTI_COMPONENT_DIRS ) ) ,\
189+ $(abspath $(dir $(wildcard $(cd ) /$(comp ) /component.mk) ) ) ,) \
190+ $(if $(findstring $(cd ) ,$(SINGLE_COMPONENT_DIRS ) ) ,\
191+ $(if $(filter $(comp ) ,$(notdir $(cd ) ) ) ,$(cd ) ,) ,) \
192+ ) ) )
167193export COMPONENT_PATHS
168194
169195TEST_COMPONENTS ?=
0 commit comments