From c521fcb6fd1e8e00d5d3288804413e6732898ae2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 11 Jul 2024 13:29:51 +0200 Subject: [PATCH] fix(cmake): report correct error on unknown component name Previously the error message was CMake Error at /home/user/esp-idf/tools/cmake/build.cmake:296 (__component_get_property): __component_get_property Function invoked with incorrect arguments for function named: __component_get_property Call Stack (most recent call first): /home/user/esp-idf/tools/cmake/build.cmake:341 (__build_resolve_and_add_req) /home/user/esp-idf/tools/cmake/build.cmake:638 (__build_expand_requirements) /home/user/esp-idf/tools/cmake/project.cmake:710 (idf_build_process) CMakeLists.txt:6 (project) Now it will be: CMake Error at /home/user/esp-idf/tools/cmake/build.cmake:298 (message): Failed to resolve component 'whatever' required by component 'main'. Call Stack (most recent call first): /home/user/esp-idf/tools/cmake/build.cmake:345 (__build_resolve_and_add_req) /home/user/esp-idf/tools/cmake/build.cmake:642 (__build_expand_requirements) /home/user/esp-idf/tools/cmake/project.cmake:710 (idf_build_process) CMakeLists.txt:6 (project) Also improved the hint to show the component name in quotes. --- tools/cmake/build.cmake | 7 +++++-- tools/idf_py_actions/hints.yml | 2 +- tools/test_build_system/test_components.py | 11 +++++++++++ tools/test_idf_py/error_output.yml | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 09c6ac4fd3..e753f80590 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -295,11 +295,14 @@ function(__build_resolve_and_add_req var component_target req type) __component_get_target(_req_target ${req}) __component_get_property(_component_name ${component_target} COMPONENT_NAME) if(NOT _req_target) - message(FATAL_ERROR "Failed to resolve component '${req}' required by component '${_component_name}'.") + message(FATAL_ERROR + "Failed to resolve component '${req}' required by component '${_component_name}': unknown name.") endif() __component_get_property(_req_registered ${_req_target} __COMPONENT_REGISTERED) if(NOT _req_registered) - message(FATAL_ERROR "Failed to resolve component '${req}' required by component '${_component_name}'.") + message(FATAL_ERROR + "Failed to resolve component '${req}' required by component '${_component_name}': " + "component not registered.") endif() __component_set_property(${component_target} ${type} ${_req_target} APPEND) set(${var} ${_req_target} PARENT_SCOPE) diff --git a/tools/idf_py_actions/hints.yml b/tools/idf_py_actions/hints.yml index c7d03cb9d4..e8247351e6 100644 --- a/tools/idf_py_actions/hints.yml +++ b/tools/idf_py_actions/hints.yml @@ -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, 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." + 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 - diff --git a/tools/test_build_system/test_components.py b/tools/test_build_system/test_components.py index 2afc5c5288..e7333c8d45 100644 --- a/tools/test_build_system/test_components.py +++ b/tools/test_build_system/test_components.py @@ -153,3 +153,14 @@ def test_version_in_component_cmakelist(idf_py: IdfPyFunc, test_app_copy: Path) replace_in_file((test_app_copy / 'main' / 'CMakeLists.txt'), '# placeholder_before_idf_component_register', '\n'.join(['if (NOT IDF_VERSION_MAJOR)', ' message(FATAL_ERROR "IDF version not set")', 'endif()'])) idf_py('reconfigure') + + +def test_unknown_component_error(idf_py: IdfPyFunc, test_app_copy: Path) -> None: + logging.info('When unknown component name is specified, correct error is shown') + replace_in_file( + test_app_copy / 'main' / 'CMakeLists.txt', + search='# placeholder_inside_idf_component_register', + replace='REQUIRES unknown', + ) + ret = idf_py('reconfigure', check=False) + assert 'Failed to resolve component \'unknown\' required by component \'main\'' in ret.stderr diff --git a/tools/test_idf_py/error_output.yml b/tools/test_idf_py/error_output.yml index 034e941497..3cc548d0be 100644 --- a/tools/test_idf_py/error_output.yml +++ b/tools/test_idf_py/error_output.yml @@ -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, 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." + "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'"