Skip to content

Commit 53f271c

Browse files
committed
tools: extend information in project_description.json
This extends information provided in the project_description.json file. Newly added information can be used in the SBOM generating tool and also to improve hints regarding the the component dependency issues. Added fields version: This adds versioning to the project_description.json file, so it's easy to identify if it contains the required information. project_version: Can be used as a version for the resulting binary e.g. `hello_world.bin`. idf_path: This one is probably not necessary, but it allows tools to run even without esp-idf environment exported(e.g. export.sh). c_compiler: The `CMAKE_C_COMPILER` value with full path to the compiler binary. This can be used to get information about toolchain, which was used to build the project. common_component_reqs: List of common components as presented in cmake's __COMPONENT_REQUIRES_COMMON and set in tools/cmake/build.cmake:__build_init(). build_component_info: Detailed information about components used during build. It's a dictionary with the component name as a key and each component has a dictionary with detailed information. Following is an example for the efuse component. "efuse": { "alias": "idf::efuse", "target": "___idf_efuse", "prefix": "idf", "dir": "/home/fhrbata/work/esp-idf/components/efuse", "type": "LIBRARY", "lib": "__idf_efuse", "reqs": [], "priv_reqs": [ "bootloader_support", "soc", "spi_flash" ], "managed_reqs": [], "managed_priv_reqs": [], "file": "/home/fhrbata/work/blink/build/esp-idf/efuse/libefuse.a", "sources": [ "/home/fhrbata/work/esp-idf/components/efuse/esp32s3/esp_efuse_table.c", ... ], "include_dirs": [ "include", "esp32s3/include" ] } Signed-off-by: Frantisek Hrbata <[email protected]>
1 parent ee505a9 commit 53f271c

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

tools/cmake/project.cmake

+84-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,73 @@ function(__project_get_revision var)
7171
set(${var} "${PROJECT_VER}" PARENT_SCOPE)
7272
endfunction()
7373

74+
function(__component_info components output)
75+
set(components_json "")
76+
foreach(name ${components})
77+
__component_get_target(target ${name})
78+
__component_get_property(alias ${target} COMPONENT_ALIAS)
79+
__component_get_property(prefix ${target} __PREFIX)
80+
__component_get_property(dir ${target} COMPONENT_DIR)
81+
__component_get_property(type ${target} COMPONENT_TYPE)
82+
__component_get_property(lib ${target} COMPONENT_LIB)
83+
__component_get_property(reqs ${target} REQUIRES)
84+
__component_get_property(include_dirs ${target} INCLUDE_DIRS)
85+
__component_get_property(priv_reqs ${target} PRIV_REQUIRES)
86+
__component_get_property(managed_reqs ${target} MANAGED_REQUIRES)
87+
__component_get_property(managed_priv_reqs ${target} MANAGED_PRIV_REQUIRES)
88+
if("${type}" STREQUAL "LIBRARY")
89+
set(file "$<TARGET_LINKER_FILE:${lib}>")
90+
91+
# The idf_component_register function is converting each source file path defined
92+
# in SRCS into absolute one. But source files can be also added with cmake's
93+
# target_sources and have relative paths. This is used for example in log
94+
# component. Let's make sure all source files have absolute path.
95+
set(sources "")
96+
get_target_property(srcs ${lib} SOURCES)
97+
foreach(src ${srcs})
98+
get_filename_component(src "${src}" ABSOLUTE BASE_DIR "${dir}")
99+
list(APPEND sources "${src}")
100+
endforeach()
101+
102+
else()
103+
set(file "")
104+
set(sources "")
105+
endif()
106+
107+
make_json_list("${reqs}" reqs)
108+
make_json_list("${priv_reqs}" priv_reqs)
109+
make_json_list("${managed_reqs}" managed_reqs)
110+
make_json_list("${managed_priv_reqs}" managed_priv_reqs)
111+
make_json_list("${include_dirs}" include_dirs)
112+
make_json_list("${sources}" sources)
113+
114+
string(CONCAT component_json
115+
" \"${name}\": {\n"
116+
" \"alias\": \"${alias}\",\n"
117+
" \"target\": \"${target}\",\n"
118+
" \"prefix\": \"${prefix}\",\n"
119+
" \"dir\": \"${dir}\",\n"
120+
" \"type\": \"${type}\",\n"
121+
" \"lib\": \"${lib}\",\n"
122+
" \"reqs\": ${reqs},\n"
123+
" \"priv_reqs\": ${priv_reqs},\n"
124+
" \"managed_reqs\": ${managed_reqs},\n"
125+
" \"managed_priv_reqs\": ${managed_priv_reqs},\n"
126+
" \"file\": \"${file}\",\n"
127+
" \"sources\": ${sources},\n"
128+
" \"include_dirs\": ${include_dirs}\n"
129+
" }"
130+
)
131+
string(CONFIGURE "${component_json}" component_json)
132+
if(NOT "${components_json}" STREQUAL "")
133+
string(APPEND components_json ",\n")
134+
endif()
135+
string(APPEND components_json "${component_json}")
136+
endforeach()
137+
set(components_json "{\n ${components_json}\n }")
138+
set(${output} "${components_json}" PARENT_SCOPE)
139+
endfunction()
140+
74141
#
75142
# Output the built components to the user. Generates files for invoking idf_monitor.py
76143
# that doubles as an overview of some of the more important build properties.
@@ -107,13 +174,15 @@ function(__project_info test_components)
107174
endforeach()
108175

109176
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
177+
idf_build_get_property(PROJECT_VER PROJECT_VER)
110178
idf_build_get_property(PROJECT_PATH PROJECT_DIR)
111179
idf_build_get_property(BUILD_DIR BUILD_DIR)
112180
idf_build_get_property(SDKCONFIG SDKCONFIG)
113181
idf_build_get_property(SDKCONFIG_DEFAULTS SDKCONFIG_DEFAULTS)
114182
idf_build_get_property(PROJECT_EXECUTABLE EXECUTABLE)
115183
set(PROJECT_BIN ${CMAKE_PROJECT_NAME}.bin)
116184
idf_build_get_property(IDF_VER IDF_VER)
185+
idf_build_get_property(common_component_reqs __COMPONENT_REQUIRES_COMMON)
117186

118187
idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
119188
include(${sdkconfig_cmake})
@@ -124,8 +193,22 @@ function(__project_info test_components)
124193
idf_build_get_property(build_dir BUILD_DIR)
125194
make_json_list("${build_components};${test_components}" build_components_json)
126195
make_json_list("${build_component_paths};${test_component_paths}" build_component_paths_json)
196+
make_json_list("${common_component_reqs}" common_component_reqs_json)
197+
198+
__component_info("${build_components};${test_components}" build_component_info_json)
199+
200+
# The configure_file function doesn't process generator expressions, which are needed
201+
# e.g. to get component target library(TARGET_LINKER_FILE), so the project_description
202+
# file is created in two steps. The first step, with configure_file, creates a temporary
203+
# file with cmake's variables substituted and unprocessed generator expressions. The second
204+
# step, with file(GENERATE), processes the temporary file and substitute generator expression
205+
# into the final project_description.json file.
127206
configure_file("${idf_path}/tools/cmake/project_description.json.in"
128-
"${build_dir}/project_description.json")
207+
"${build_dir}/project_description.json.templ")
208+
file(READ "${build_dir}/project_description.json.templ" project_description_json_templ)
209+
file(REMOVE "${build_dir}/project_description.json.templ")
210+
file(GENERATE OUTPUT "${build_dir}/project_description.json"
211+
CONTENT "${project_description_json_templ}")
129212

130213
# We now have the following component-related variables:
131214
#

tools/cmake/project_description.json.in

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2+
"version": "1",
23
"project_name": "${PROJECT_NAME}",
4+
"project_version": "${PROJECT_VER}",
35
"project_path": "${PROJECT_PATH}",
6+
"idf_path": "${IDF_PATH}",
47
"build_dir": "${BUILD_DIR}",
58
"config_file": "${SDKCONFIG}",
69
"config_defaults": "${SDKCONFIG_DEFAULTS}",
@@ -14,10 +17,13 @@
1417
"phy_data_partition": "${CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION}",
1518
"monitor_baud" : "${CONFIG_ESPTOOLPY_MONITOR_BAUD}",
1619
"monitor_toolprefix": "${CONFIG_SDK_TOOLPREFIX}",
20+
"c_compiler": "${CMAKE_C_COMPILER}",
1721
"config_environment" : {
1822
"COMPONENT_KCONFIGS" : "${COMPONENT_KCONFIGS}",
1923
"COMPONENT_KCONFIGS_PROJBUILD" : "${COMPONENT_KCONFIGS_PROJBUILD}"
2024
},
25+
"common_component_reqs": ${common_component_reqs_json},
2126
"build_components" : ${build_components_json},
22-
"build_component_paths" : ${build_component_paths_json}
27+
"build_component_paths" : ${build_component_paths_json},
28+
"build_component_info" : ${build_component_info_json}
2329
}

0 commit comments

Comments
 (0)