Skip to content

Commit dcdd24b

Browse files
committed
cmake: dts: Use temporary file for dts.cmake
Uses a temporary file for dts output then uses CMake to copy to the correct file if it has changed. This prevents a ping-pong issue when sysbuild is used of configuring and building cycle when nothing has changed and there is sysbuild code which loads in the devicetree data from an image Signed-off-by: Jamie McCrae <[email protected]>
1 parent 049b243 commit dcdd24b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmake/modules/dts.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,26 @@ endif()
349349
#
350350
# Run GEN_DTS_CMAKE_SCRIPT.
351351
#
352+
# A temporary file is copied to the original file if it differs. This prevents issue such as a
353+
# cycle when sysbuild is used of configuring and building multiple times due to the dts.cmake file
354+
# of images having a newer modification time than the sysbuild build.ninja file, despite the
355+
# output having not changed
356+
#
357+
set(dts_cmake_tmp ${DTS_CMAKE}.new)
352358

353359
execute_process(
354360
COMMAND ${PYTHON_EXECUTABLE} ${GEN_DTS_CMAKE_SCRIPT}
355361
--edt-pickle ${EDT_PICKLE}
356-
--cmake-out ${DTS_CMAKE}
362+
--cmake-out ${dts_cmake_tmp}
357363
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
358364
RESULT_VARIABLE ret
359365
)
360366
if(NOT "${ret}" STREQUAL "0")
361367
message(FATAL_ERROR "gen_dts_cmake.py failed with return code: ${ret}")
362368
else()
369+
zephyr_file_copy(${dts_cmake_tmp} ${DTS_CMAKE} ONLY_IF_DIFFERENT)
370+
file(REMOVE ${dts_cmake_tmp})
371+
set(dts_cmake_tmp)
363372
message(STATUS "Including generated dts.cmake file: ${DTS_CMAKE}")
364373
include(${DTS_CMAKE})
365374
endif()

0 commit comments

Comments
 (0)