Merge branch 'feat/cmakev2_depgraph' into 'master'

feat(cmakev2/build): add idf_build_generate_depgraph function

Closes IDF-13072

See merge request espressif/esp-idf!43814
This commit is contained in:
Frantisek Hrbata
2025-12-12 11:49:49 +01:00
5 changed files with 84 additions and 3 deletions
+2
View File
@@ -4,6 +4,8 @@ if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
endif()
set(srcs)
if(CONFIG_SOC_PM_SUPPORTED)
list(APPEND srcs "pm_locks.c" "pm_trace.c" "pm_impl.c")
endif()
+69 -3
View File
@@ -703,7 +703,7 @@ endfunction()
.. code-block:: cmake
idf_build_generate_metadata(<binary>
[FILE <file>])
[OUTPUT_FILE <file>])
*binary[in]*
@@ -715,8 +715,8 @@ endfunction()
the default path ``<build>/project_description.json`` is used.
Generate metadata for the specified ``binary`` and store it in the
specified ``FILE``. If no ``FILE`` is provided, the default location
``<build>/project_description.json`` will be used.
specified ``OUTPUT_FILE``. If no ``OUTPUT_FILE`` is provided, the default
location ``<build>/project_description.json`` will be used.
#]]
function(idf_build_generate_metadata binary)
set(options)
@@ -1180,3 +1180,69 @@ function(idf_check_binary_signed binary)
"${binary_path}"
VERBATIM)
endfunction()
#[[
.. cmakev2:function:: idf_build_generate_depgraph
.. code-block:: cmake
idf_build_generate_depgraph(<executable>
[OUTPUT_FILE <file>])
*executable[in]*
Executable target for which to generate a dependency graph.
*OUTPUT_FILE[in,opt]*
Optional output file path for storing the dependency graph. If not
provided, the default path ``<build>/component_deps.dot`` is used.
Generate dependency graph for the specified ``executable`` and store it in
the specified ``OUTPUT_FILE``. If no ``OUTPUT_FILE`` is provided, the
default location ``<build>/component_deps.dot`` will be used.
#]]
function(idf_build_generate_depgraph executable)
set(options)
set(one_value OUTPUT_FILE)
set(multi_value)
cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN})
idf_build_get_property(depgraph_enabled __BUILD_COMPONENT_DEPGRAPH_ENABLED)
if(NOT depgraph_enabled)
return()
endif()
__get_executable_library_or_die(TARGET "${executable}" OUTPUT library)
idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH "")
idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
idf_library_get_property(build_components "${library}" LIBRARY_COMPONENTS_LINKED)
foreach(component_name IN LISTS build_components)
idf_component_get_property(reqs "${component_name}" REQUIRES)
idf_component_get_property(component_format "${component_name}" COMPONENT_FORMAT)
if("${component_format}" STREQUAL "CMAKEV1")
# For cmakev1 components, also include commonly required
# components.
list(APPEND reqs ${common_reqs})
endif()
foreach(req IN LISTS reqs)
depgraph_add_edge(${component_name} ${req} REQUIRES)
endforeach()
idf_component_get_property(priv_reqs "${component_name}" PRIV_REQUIRES)
foreach(priv_req IN LISTS priv_reqs)
depgraph_add_edge(${component_name} ${priv_req} PRIV_REQUIRES)
endforeach()
endforeach()
if(NOT DEFINED ARG_OUTPUT_FILE)
idf_build_get_property(build_dir BUILD_DIR)
set(ARG_OUTPUT_FILE "${build_dir}/component_deps.dot")
endif()
depgraph_generate("${ARG_OUTPUT_FILE}")
endfunction()
+5
View File
@@ -27,6 +27,11 @@ include(${CMAKE_CURRENT_LIST_DIR}/../cmake/gdbinit.cmake)
# project_description.json.
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/openocd.cmake)
# The depgraph.cmake file from cmakev1 contains helper functions for generating
# a component dependency graph. Let's reuse these functions in the
# idf_build_generate_depgraph function.
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/depgraph.cmake)
include(component)
include(build)
include(kconfig)
+2
View File
@@ -770,6 +770,8 @@ function(__project_default)
idf_create_size_report("${executable}_mapfile"
TARGET size)
endif()
idf_build_generate_depgraph("${executable}")
endfunction()
#[[api
+6
View File
@@ -15,6 +15,8 @@ add_custom_target(flash)
idf_project_init()
idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH_ENABLED 1)
# Test component priority
function(test_component_priority)
# Set the idf component to be replaced with a testing component of higher
@@ -232,6 +234,8 @@ function(test_executable)
TARGET menuconfig-fatfs)
idf_build_generate_metadata(fatfs_example_bin
OUTPUT_FILE project_description_fatfs.json)
idf_build_generate_depgraph(fatfs_example
OUTPUT_FILE component_deps_fatfs.dot)
idf_create_confserver(fatfs_example
TARGET confserver-fatfs)
@@ -255,6 +259,8 @@ function(test_executable)
TARGET menuconfig-hello_world)
idf_build_generate_metadata(hello_world_example_bin
OUTPUT_FILE project_description_hello_world.json)
idf_build_generate_depgraph(hello_world_example
OUTPUT_FILE component_deps_hello_world.dot)
idf_create_confserver(hello_world_example
TARGET confserver-hello_world)