fix: properly resolve component dependencies

There is currently a bug in the __build_resolve_and_add_req function in
tools/cmake/build.cmake where the check for registered component
requirements is incorrectly applied to the component itself rather than
its dependencies. This issue likely originated from a typo, using
component_target instead of _component_target. To prevent further
confusion, _component_target has been renamed to _req_target.

Fixing this revealed multiple incorrect dependencies for the Linux
target, which have now been resolved by explicitly specifying the
dependencies for the Linux target.

Closes https://github.com/espressif/esp-idf/issues/13447

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata 2024-04-08 14:08:23 +02:00 committed by BOT
parent cb81d1a4f9
commit fbe8bf89ee
30 changed files with 210 additions and 41 deletions

View File

@ -7,8 +7,10 @@ set(srcs "commands.c"
if(${target} STREQUAL "linux")
list(APPEND srcs "esp_console_repl_linux.c")
set(requires "")
else()
list(APPEND srcs "esp_console_repl_chip.c")
set(requires vfs esp_vfs_console)
endif()
set(argtable_srcs argtable3/arg_cmd.c
@ -31,7 +33,7 @@ idf_component_register(SRCS ${srcs}
${argtable_srcs}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
PRIV_INCLUDE_DIRS private_include
REQUIRES vfs esp_vfs_console
REQUIRES "${requires}"
PRIV_REQUIRES esp_driver_uart
esp_driver_usb_serial_jtag
)

View File

@ -35,8 +35,13 @@ if(BOOTLOADER_BUILD)
PRIV_INCLUDE_DIRS "${private_include}")
else()
list(APPEND srcs "src/esp_efuse_startup.c")
if(${target} STREQUAL "linux")
set(priv_requires soc spi_flash esp_system esp_partition)
else()
set(priv_requires bootloader_support soc spi_flash esp_system esp_partition esp_app_format)
endif()
idf_component_register(SRCS "${srcs}"
PRIV_REQUIRES bootloader_support soc spi_flash esp_system esp_partition esp_app_format
PRIV_REQUIRES "${priv_requires}"
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS "${private_include}")
if(NOT ${target} STREQUAL "linux")

View File

@ -14,5 +14,5 @@ set(src_dirs "." "${dir}")
idf_component_register(SRC_DIRS "${src_dirs}"
PRIV_INCLUDE_DIRS "." "${dir}/include" "../../private_include" "../../${target}/private_include"
PRIV_REQUIRES cmock efuse bootloader_support esp_timer
PRIV_REQUIRES cmock efuse esp_timer
WHOLE_ARCHIVE)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
# Analog comparator related source files
@ -8,8 +10,14 @@ if(CONFIG_SOC_ANA_CMPR_SUPPORTED)
endif()
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS "include"
PRIV_REQUIRES esp_pm esp_driver_gpio
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs "esp_cam_ctlr.c")
set(include "include" "interface")
@ -7,7 +9,13 @@ if(CONFIG_SOC_MIPI_CSI_SUPPORTED)
list(APPEND include "csi/include")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_mm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include}
PRIV_REQUIRES esp_mm
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,6 +1,9 @@
idf_build_get_property(target IDF_TARGET)
if(${target} STREQUAL "linux")
# TODO: Remove this once all components have their requirements explicitly defined
# and using set(COMPONENTS main).
idf_component_register()
return() # This component is not supported by the POSIX/Linux simulator
endif()

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_GPTIMER_SUPPORTED)
@ -9,8 +11,14 @@ if(CONFIG_SOC_TIMER_SUPPORT_ETM)
list(APPEND srcs "src/gptimer_etm.c")
endif()
if(${target} STREQUAL "linux")
set(requires "")
else()
set(requires esp_pm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
REQUIRES "esp_pm"
REQUIRES "${requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(include "include")
@ -13,8 +15,14 @@ if(CONFIG_SOC_I2C_SUPPORTED)
endif()
if(${target} STREQUAL "linux")
set(priv_requires esp_ringbuf)
else()
set(priv_requires esp_driver_gpio esp_pm esp_ringbuf)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include}
PRIV_REQUIRES esp_driver_gpio esp_pm esp_ringbuf
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
@ -21,7 +23,13 @@ if(CONFIG_SOC_JPEG_CODEC_SUPPORTED)
endif()
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_mm esp_pm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_mm" "esp_pm"
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,3 +1,4 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
@ -6,9 +7,15 @@ if(CONFIG_SOC_LEDC_SUPPORTED)
list(APPEND srcs "src/ledc.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio)
endif()
idf_component_register(
SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_MCPWM_SUPPORTED)
@ -14,8 +16,14 @@ if(CONFIG_SOC_MCPWM_SUPPORTED)
endif()
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_PARLIO_SUPPORTED)
@ -6,7 +8,13 @@ if(CONFIG_SOC_PARLIO_SUPPORTED)
"src/parlio_rx.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio esp_mm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio" "esp_mm"
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,11 +1,19 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_PCNT_SUPPORTED)
list(APPEND srcs "src/pulse_cnt.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_PPA_SUPPORTED)
@ -7,7 +9,14 @@ if(CONFIG_SOC_PPA_SUPPORTED)
"src/ppa_fill.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_mm esp_pm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES esp_mm esp_pm
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_RMT_SUPPORTED)
@ -7,8 +9,14 @@ if(CONFIG_SOC_RMT_SUPPORTED)
"src/rmt_tx.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio esp_mm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio" "esp_mm"
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
@ -7,7 +9,13 @@ if(CONFIG_SOC_SDIO_SLAVE_SUPPORTED)
list(APPEND srcs "src/sdio_slave.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires esp_ringbuf)
else()
set(priv_requires esp_driver_gpio esp_ringbuf)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES esp_driver_gpio esp_ringbuf
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,11 +1,19 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_SDM_SUPPORTED)
list(APPEND srcs "src/sdm.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires "")
else()
set(priv_requires esp_pm esp_driver_gpio)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
@ -8,8 +10,16 @@ if(CONFIG_SOC_SDMMC_HOST_SUPPORTED)
"src/sdmmc_host.c")
endif()
if(${target} STREQUAL "linux")
set(requires "")
set(priv_requires esp_timer)
else()
set(requires sdmmc esp_driver_gpio)
set(priv_requires esp_timer esp_pm esp_mm)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
REQUIRES sdmmc esp_driver_gpio
PRIV_REQUIRES esp_timer esp_pm esp_mm
REQUIRES "${requires}"
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
@ -8,8 +10,16 @@ if(CONFIG_SOC_GPSPI_SUPPORTED)
"src/sdspi_transaction.c")
endif()
if(${target} STREQUAL "linux")
set(requires "")
set(priv_requires esp_timer)
else()
set(requires sdmmc esp_driver_spi esp_driver_gpio)
set(priv_requires esp_timer)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
REQUIRES sdmmc esp_driver_spi esp_driver_gpio
PRIV_REQUIRES esp_timer
REQUIRES "${requires}"
PRIV_REQUIRES "${priv_requires}"
)

View File

@ -1,13 +1,21 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(public_include "include")
if(CONFIG_SOC_UART_SUPPORTED)
list(APPEND srcs "src/uart.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires esp_ringbuf)
else()
set(priv_requires esp_pm esp_driver_gpio esp_ringbuf)
endif()
idf_component_register(
SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES esp_pm esp_driver_gpio esp_ringbuf
PRIV_REQUIRES "${priv_requires}"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)
set(srcs)
set(include "include")
@ -7,9 +9,15 @@ if(CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED)
"src/usb_serial_jtag_connection_monitor.c")
endif()
if(${target} STREQUAL "linux")
set(priv_requires esp_ringbuf esp_timer)
else()
set(priv_requires esp_driver_gpio esp_ringbuf esp_pm esp_timer)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include}
PRIV_REQUIRES esp_driver_gpio esp_ringbuf esp_pm esp_timer
PRIV_REQUIRES "${priv_requires}"
)
if(CONFIG_VFS_SUPPORT_IO AND CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED)

View File

@ -6,6 +6,7 @@ endif()
if(IDF_TARGET STREQUAL "esp32p4" OR IDF_TARGET STREQUAL "esp32c61")
# TODO: IDF-7460, IDF-8851, IDF-9553
idf_component_register()
return()
endif()

View File

@ -14,9 +14,16 @@ set(srcs "src/nvs_api.cpp"
"src/nvs_types.cpp"
"src/nvs_platform.cpp")
set(requires esp_partition)
if(${target} STREQUAL "linux")
set(priv_requires spi_flash)
else()
set(priv_requires spi_flash newlib)
endif()
idf_component_register(SRCS "${srcs}"
REQUIRES "esp_partition"
PRIV_REQUIRES spi_flash newlib
REQUIRES "${requires}"
PRIV_REQUIRES "${priv_requires}"
INCLUDE_DIRS "include"
"../spi_flash/include"
PRIV_INCLUDE_DIRS "private_include")

View File

@ -1,2 +1,3 @@
idf_component_register(SRCS "hello_world_main.c"
PRIV_REQUIRES spi_flash
INCLUDE_DIRS "")

View File

@ -2,4 +2,5 @@
#
# (If this was a component, we would set COMPONENT_EMBED_TXTFILES here.)
idf_component_register(SRCS "https_mbedtls_example_main.c"
PRIV_REQUIRES esp_event nvs_flash esp_netif mbedtls
INCLUDE_DIRS ".")

View File

@ -262,13 +262,14 @@ endfunction()
# Resolve the requirement component to the component target created for that component.
#
function(__build_resolve_and_add_req var component_target req type)
__component_get_target(_component_target ${req})
__component_get_property(_component_registered ${component_target} __COMPONENT_REGISTERED)
if(NOT _component_target OR NOT _component_registered)
message(FATAL_ERROR "Failed to resolve component '${req}'.")
__component_get_target(_req_target ${req})
__component_get_property(_req_registered ${_req_target} __COMPONENT_REGISTERED)
if(NOT _req_target OR NOT _req_registered)
__component_get_property(_component_name ${component_target} COMPONENT_NAME)
message(FATAL_ERROR "Failed to resolve component '${req}' required by component '${_component_name}'.")
endif()
__component_set_property(${component_target} ${type} ${_component_target} APPEND)
set(${var} ${_component_target} PARENT_SCOPE)
__component_set_property(${component_target} ${type} ${_req_target} APPEND)
set(${var} ${_req_target} PARENT_SCOPE)
endfunction()
#
@ -449,7 +450,7 @@ endfunction()
# if PROJECT_DIR is set and CMAKE_SOURCE_DIR/sdkconfig if not
# @param[in, optional] SDKCONFIG_DEFAULTS (single value) config defaults file to use for the build; defaults
# to none (Kconfig defaults or previously generated config are used)
# @param[in, optional] BUILD_DIR (single value) directory for build artifacts; defautls to CMAKE_BINARY_DIR
# @param[in, optional] BUILD_DIR (single value) directory for build artifacts; defaults to CMAKE_BINARY_DIR
# @param[in, optional] COMPONENTS (multivalue) select components to process among the components
# known by the build system
# (added via `idf_build_component`). This argument is used to trim the build.

View File

@ -216,7 +216,7 @@
-
re: "Failed to resolve component '(?!esp_ipc)(\\w+)'"
hint: "The component {} could not be found. This could be because: component name was misspelled, the component was not added to the build, the component has been moved to the IDF component manager or has been removed and refactored into some other component.\nPlease look out for component in 'https://components.espressif.com' and add using 'idf.py add-dependency' command.\nRefer to the migration guide for more details about moved components.\nRefer to the build-system guide for more details about how components are found and included in the build."
hint: "The component {} could not be found. This could be because: component name was misspelled, the component was not added to the build, the component has been moved to the IDF component manager, the component has been removed and refactored into some other component or the component may not be supported by the selected target.\nPlease look out for component in 'https://components.espressif.com' and add using 'idf.py add-dependency' command.\nRefer to the migration guide for more details about moved components.\nRefer to the build-system guide for more details about how components are found and included in the build."
match_to_output: True
-

View File

@ -87,21 +87,21 @@ def test_component_properties_are_set(idf_py: IdfPyFunc, test_app_copy: Path) ->
assert 'SRCS:{}'.format((test_app_copy / 'main' / 'build_test_app.c').as_posix()) in ret.stdout, 'Component properties should be set'
def test_component_overriden_dir(idf_py: IdfPyFunc, test_app_copy: Path, default_idf_env: EnvDict) -> None:
logging.info('Getting component overriden dir')
def test_component_overridden_dir(idf_py: IdfPyFunc, test_app_copy: Path, default_idf_env: EnvDict) -> None:
logging.info('Getting component overridden dir')
(test_app_copy / 'components' / 'hal').mkdir(parents=True)
(test_app_copy / 'components' / 'hal' / 'CMakeLists.txt').write_text('\n'.join([
'idf_component_get_property(overriden_dir ${COMPONENT_NAME} COMPONENT_OVERRIDEN_DIR)',
'message(STATUS overriden_dir:${overriden_dir})']))
'idf_component_get_property(overridden_dir ${COMPONENT_NAME} COMPONENT_OVERRIDEN_DIR)',
'message(STATUS overridden_dir:${overridden_dir})', 'idf_component_register()']))
ret = idf_py('reconfigure')
idf_path = Path(default_idf_env.get('IDF_PATH'))
# no registration, overrides registration as well
assert 'overriden_dir:{}'.format((idf_path / 'components' / 'hal').as_posix()) in ret.stdout, 'Failed to get overriden dir'
assert 'overridden_dir:{}'.format((idf_path / 'components' / 'hal').as_posix()) in ret.stdout, 'Failed to get overridden dir'
append_to_file((test_app_copy / 'components' / 'hal' / 'CMakeLists.txt'), '\n'.join([
'',
'idf_component_register(KCONFIG ${overriden_dir}/Kconfig)',
'idf_component_register(KCONFIG ${overridden_dir}/Kconfig)',
'idf_component_get_property(kconfig ${COMPONENT_NAME} KCONFIG)',
'message(STATUS kconfig:${overriden_dir}/Kconfig)']))
'message(STATUS kconfig:${overridden_dir}/Kconfig)']))
ret = idf_py('reconfigure', check=False)
assert 'kconfig:{}'.format((idf_path / 'components' / 'hal').as_posix()) in ret.stdout, 'Failed to verify original `main` directory'

View File

@ -47,7 +47,7 @@
"HINT: The struct 'esp_tls_t' has now been made private - its elements can be only be accessed/modified through respective getter/setter functions. Please refer to the migration guide for more information."
"Failed to resolve component 'component'\n":
"HINT: The component component could not be found. This could be because: component name was misspelled, the component was not added to the build, the component has been moved to the IDF component manager or has been removed and refactored into some other component.\nPlease look out for component in 'https://components.espressif.com' and add using 'idf.py add-dependency' command.\nRefer to the migration guide for more details about moved components.\nRefer to the build-system guide for more details about how components are found and included in the build."
"HINT: The component component could not be found. This could be because: component name was misspelled, the component was not added to the build, the component has been moved to the IDF component manager, the component has been removed and refactored into some other component or the component may not be supported by the selected target.\nPlease look out for component in 'https://components.espressif.com' and add using 'idf.py add-dependency' command.\nRefer to the migration guide for more details about moved components.\nRefer to the build-system guide for more details about how components are found and included in the build."
'fatal error: tmp/atca_mbedtls_wrap.h: No such file or directory\n':
"HINT: To use CONFIG_ESP_TLS_USE_SECURE_ELEMENT option, please install `esp-cryptoauthlib` using 'idf.py add-dependency espressif/esp-cryptoauthlib'"

View File

@ -1,3 +1,5 @@
idf_build_get_property(arch IDF_TARGET_ARCH)
set(srcs "memory_checks.c"
"test_runner.c"
"test_utils.c")
@ -13,8 +15,14 @@ else()
list(APPEND srcs "ref_clock_impl_timergroup.c")
endif()
if("${arch}" STREQUAL "xtensa")
set(priv_requires perfmon esp_driver_pcnt esp_driver_gptimer esp_driver_rmt esp_netif)
else()
set(priv_requires esp_driver_pcnt esp_driver_gptimer esp_driver_rmt esp_netif)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS include
REQUIRES esp_partition idf_test cmock
PRIV_REQUIRES perfmon esp_driver_pcnt esp_driver_gptimer esp_driver_rmt esp_netif)
PRIV_REQUIRES "${priv_requires}")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")