Merge branch 'bugfix/cmake_extra_component_dirs_v3.2' into 'release/v3.2'

ci: additional Cmake tests for EXTRA_COMPONENT_DIRS (backport v3.2)

See merge request espressif/esp-idf!5492
This commit is contained in:
Angus Gratton 2019-08-07 16:05:29 +08:00
commit ff772e91e8
2 changed files with 66 additions and 33 deletions

View file

@ -258,6 +258,41 @@ EOF
|| failure "Custom bootloader source files should be built instead of the original's"
rm -rf components
print_status "Empty directory not treated as a component"
clean_build_dir
mkdir -p components/esp32 && idf.py reconfigure
! grep "$PWD/components/esp32" $PWD/build/project_description.json || failure "Failed to build with empty esp32 directory in components"
rm -rf components
print_status "If a component directory is added to COMPONENT_DIRS, its subdirectories are not added"
clean_build_dir
mkdir -p main/test
echo "register_component()" > main/test/CMakeLists.txt
idf.py reconfigure
! grep "$PWD/main/test" $PWD/build/project_description.json || failure "COMPONENT_DIRS has added component subdirectory to the build"
grep "$PWD/main" $PWD/build/project_description.json || failure "COMPONENT_DIRS parent component directory should be included in the build"
rm -rf main/test
print_status "If a component directory is added to COMPONENT_DIRS, its sibling directories are not added"
clean_build_dir
mkdir -p mycomponents/mycomponent
echo "register_component()" > mycomponents/mycomponent/CMakeLists.txt
# first test by adding single component directory to EXTRA_COMPONENT_DIRS
mkdir -p mycomponents/esp32
echo "register_component()" > mycomponents/esp32/CMakeLists.txt
idf.py reconfigure -DEXTRA_COMPONENT_DIRS=$PWD/mycomponents/mycomponent
! grep "$PWD/mycomponents/esp32" $PWD/build/project_description.json || failure "EXTRA_COMPONENT_DIRS has added a sibling directory"
grep "$PWD/mycomponents/mycomponent" $PWD/build/project_description.json || failure "EXTRA_COMPONENT_DIRS valid sibling directory should be in the build"
rm -rf mycomponents/esp32
# now the same thing, but add a components directory
mkdir -p esp32
echo "register_component()" > esp32/CMakeLists.txt
idf.py reconfigure -DEXTRA_COMPONENT_DIRS=$PWD/mycomponents
! grep "$PWD/esp32" $PWD/build/project_description.json || failure "EXTRA_COMPONENT_DIRS has added a sibling directory"
grep "$PWD/mycomponents/mycomponent" $PWD/build/project_description.json || failure "EXTRA_COMPONENT_DIRS valid sibling directory should be in the build"
rm -rf esp32
rm -rf mycomponents
print_status "All tests completed"
if [ -n "${FAILURES}" ]; then
echo "Some failures were detected:"

View file

@ -102,51 +102,49 @@ endfunction()
# earlier in the component_dirs list take precedence.
function(components_find_all component_dirs component_paths component_names test_component_names)
# component_dirs entries can be files or lists of files
set(paths "")
set(names "")
set(test_names "")
set(_paths "")
set(_names "")
set(_test_names "")
# start by expanding the component_dirs list with all subdirectories
foreach(dir ${component_dirs})
# Iterate any subdirectories for values
file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*")
foreach(subdir ${subdirs})
set(component_dirs "${component_dirs};${subdir}")
endforeach()
endforeach()
# Look for a component in each component_dirs entry
foreach(dir ${component_dirs})
debug("Looking for CMakeLists.txt in ${dir}")
file(GLOB component "${dir}/CMakeLists.txt")
if(component)
debug("CMakeLists.txt file ${component}")
get_filename_component(component "${component}" DIRECTORY)
get_filename_component(name "${component}" NAME)
if(EXISTS ${dir}/CMakeLists.txt)
get_filename_component(_path "${dir}" ABSOLUTE)
get_filename_component(_name "${_path}" NAME)
if(NOT name IN_LIST names)
list(APPEND names "${name}")
list(APPEND paths "${component}")
# Look for test component directory
file(GLOB test "${component}/test/CMakeLists.txt")
if(test)
list(APPEND test_names "${name}")
endif()
list(APPEND _names "${_name}")
list(APPEND _paths "${_path}")
endif()
else() # no CMakeLists.txt file
# test for legacy component.mk and warn
file(GLOB legacy_component "${dir}/component.mk")
if(legacy_component)
if(EXISTS "${_path}/test/CMakeLists.txt")
list(APPEND _test_names "${_name}")
endif()
else()
if(EXISTS ${dir}/component.mk)
get_filename_component(legacy_component "${legacy_component}" DIRECTORY)
message(WARNING "Component ${legacy_component} contains old-style component.mk but no CMakeLists.txt. "
"Component will be skipped.")
else()
if(NOT __recursing) # recurse only once
file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*")
set(__recursing 1)
components_find_all("${subdirs}" __paths __names __test_names)
set(__recursing 0)
if(__paths)
list(APPEND _paths "${__paths}")
list(APPEND _names "${__names}")
list(APPEND _test_names "${__test_names}")
endif()
endif()
endif()
endif()
endforeach()
set(${component_paths} ${paths} PARENT_SCOPE)
set(${component_names} ${names} PARENT_SCOPE)
set(${test_component_names} ${test_names} PARENT_SCOPE)
set(${test_component_names} "${_test_names}" PARENT_SCOPE)
set(${component_paths} "${_paths}" PARENT_SCOPE)
set(${component_names} "${_names}" PARENT_SCOPE)
endfunction()