Skip to content

Commit

Permalink
[nrf fromlist] cmake: dts: Use temporary file for dts.cmake with sysb…
Browse files Browse the repository at this point in the history
…uild

Uses a temporary file when sysbuild is being used for images then
uses CMake to copy to the correct file if it has changed. This
prevents a ping-pong 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]>
  • Loading branch information
nordicjm committed Nov 13, 2024
1 parent b524b0e commit 2270c34
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmake/modules/dts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,32 @@ endif()
#
# Run GEN_DTS_CMAKE_SCRIPT.
#
# For sysbuild, use a temp file and copy it to the original file if it differs, this prevents
# a cycle of configuring and building multiple times due to the dts.cmake file of images having a
# newer modification time than the sysbuild build.ninja file, despite the output having not changed
#

if(SYSBUILD)
set(dts_tmp_cmake _tmp)
else()
set(dts_tmp_cmake)
endif()

execute_process(
COMMAND ${PYTHON_EXECUTABLE} ${GEN_DTS_CMAKE_SCRIPT}
--edt-pickle ${EDT_PICKLE}
--cmake-out ${DTS_CMAKE}
--cmake-out ${DTS_CMAKE}${dts_tmp_cmake}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
RESULT_VARIABLE ret
)
if(NOT "${ret}" STREQUAL "0")
message(FATAL_ERROR "gen_dts_cmake.py failed with return code: ${ret}")
else()
if(SYSBUILD)
file(COPY_FILE ${DTS_CMAKE}${dts_tmp_cmake} ${DTS_CMAKE} ONLY_IF_DIFFERENT INPUT_MAY_BE_RECENT)
set(dts_tmp_cmake)
endif()

message(STATUS "Including generated dts.cmake file: ${DTS_CMAKE}")
include(${DTS_CMAKE})
endif()
Expand Down

0 comments on commit 2270c34

Please sign in to comment.