Skip to content

Commit 80ad341

Browse files
committed
[nrf fromlist] 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 Upstream PR #: 81340 Signed-off-by: Jamie McCrae <[email protected]>
1 parent dab9c11 commit 80ad341

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
@@ -321,17 +321,26 @@ endif()
321321
#
322322
# Run GEN_DTS_CMAKE_SCRIPT.
323323
#
324+
# A temporary file is used copied to the original file if it differs, this prevents issue such as
325+
# a cycle when sysbuild is used of configuring and building multiple times due to the dts.cmake
326+
# file of images having a newer modification time than the sysbuild build.ninja file, despite the
327+
# output having not changed
328+
#
329+
set(dts_cmake_tmp ${DTS_CMAKE}.new)
324330

325331
execute_process(
326332
COMMAND ${PYTHON_EXECUTABLE} ${GEN_DTS_CMAKE_SCRIPT}
327333
--edt-pickle ${EDT_PICKLE}
328-
--cmake-out ${DTS_CMAKE}
334+
--cmake-out ${dts_cmake_tmp}
329335
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
330336
RESULT_VARIABLE ret
331337
)
332338
if(NOT "${ret}" STREQUAL "0")
333339
message(FATAL_ERROR "gen_dts_cmake.py failed with return code: ${ret}")
334340
else()
341+
zephyr_file_copy(${dts_cmake_tmp} ${DTS_CMAKE} ONLY_IF_DIFFERENT)
342+
file(REMOVE ${dts_cmake_tmp})
343+
set(dts_cmake_tmp)
335344
message(STATUS "Including generated dts.cmake file: ${DTS_CMAKE}")
336345
include(${DTS_CMAKE})
337346
endif()

0 commit comments

Comments
 (0)