From 8e14ed199ed65fc1e43968d1bf1aaf785c0bc7c0 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Thu, 26 Jun 2025 17:45:27 +0200 Subject: [PATCH] test(cmakev2): add testing project CMakeLists.txt This is a basic CMake project that currently includes tests for displaying build and component properties, as well as testing component priority. These tests should be removed once proper CI testing is in place. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/test/CMakeLists.txt | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tools/cmakev2/test/CMakeLists.txt diff --git a/tools/cmakev2/test/CMakeLists.txt b/tools/cmakev2/test/CMakeLists.txt new file mode 100644 index 00000000000..fc3cf158156 --- /dev/null +++ b/tools/cmakev2/test/CMakeLists.txt @@ -0,0 +1,70 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +# Simple project for basic cmakev2 testing +# Run: cmake -S . -B build +cmake_minimum_required(VERSION 3.22) + +include($ENV{IDF_PATH}/tools/cmakev2/idf.cmake) + +project(cmakev2 C) + +# Dump build and component properties +function(test_dump_properties) + __dump_build_properties() + idf_build_get_property(component_names COMPONENTS_DISCOVERED) + __dump_component_properties("${component_names}") +endfunction() + +# Test component priority +function(test_component_priority) + # Set the idf component to be replaced with a testing component of higher + # priority. + set(component_name "esp_system") + + # Check that idf component is between discovered components. + __get_component_interface(COMPONENT "${component_name}" + OUTPUT component_interface) + if("${component_interface}" STREQUAL "NOTFOUND") + idf_die("Component '${component_name}' not found") + endif() + + # Check that idf component has "idf_components" as source. + idf_component_get_property(component_source + ${component_interface} + COMPONENT_SOURCE) + if(NOT "${component_source}" STREQUAL "idf_components") + idf_die("Unexpected idf component '${component_name}' source '${component_source}'") + endif() + + # Create fake component with same name as idf component. + set(component_dir "${CMAKE_CURRENT_BINARY_DIR}/${component_name}") + file(MAKE_DIRECTORY "${component_dir}") + file(TOUCH "${component_dir}/CMakeLists.txt") + + # Initialize fake component with higher "project_components" priority. + idf_build_get_property(component_prefix PREFIX) + __init_component(DIRECTORY "${component_dir}" + PREFIX "${component_prefix}" + SOURCE "project_components") + + # Check that the idf component was replaced with fake component. + idf_component_get_property(component_source + ${component_interface} + COMPONENT_SOURCE) + if(NOT "${component_source}" STREQUAL "project_components") + idf_die("Unexpected fake component '${component_name}' source '${component_source}'") + endif() + + idf_component_get_property(component_dir + ${component_interface} + COMPONENT_DIR) + if(NOT "${component_dir}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${component_name}") + idf_die("Unexpected fake component '${component_name}' directory '${component_dir}'") + endif() + __dump_component_properties("${component_name}") +endfunction() + +# Run tests +test_dump_properties() +test_component_priority()