-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake refactoring for system DT #55293
CMake refactoring for system DT #55293
Conversation
4f2f745
to
55792b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look a cleaning up this.
A first look through the changes raised some questions / comments to address.
Will take a 2nd look at some of the specifics later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change request
55792b2
to
b5ae998
Compare
@nordicjm fixed, thanks! |
The name of each commented section should match the name in the "table of contents", for consistency and so people can jump from contents to implementations more easily with their editors' search functions. Signed-off-by: Martí Bolívar <[email protected]>
Due to Hyrum's Law, there are users out in the wild depending on this directory existing to place their own generated files, so it'd break things unnecessarily to not do this if we don't have a DTS, as explained in a source code comment. However, this doesn't really have anything to do with DTS processing, so split it into its own module to separate concerns. This isn't really a CMake module in the usual sense of something that defines functions you can use, and is therefore a form of technical debt. The decision was made to accept this because fixing this is a larger task for the files in cmake/modules/, since there are multiple other examples of this in here. This also paves the way for inserting another module in between the generated_file_directories and dts modules that itself depends on these directories existing. Signed-off-by: Martí Bolívar <[email protected]>
Create a separate module that sets up all our devicetree handling, by setting up common variables that would apply to any and all DT processing. This is then included in the regular dts module that we include in zephyr_default.cmake. The separation of this code from dts.cmake is groundwork for enabling system devicetree in Zephyr, which will need the same definitions included into its scope. Signed-off-by: Martí Bolívar <[email protected]>
When the build system was being split up into modules under cmake/modules, most of the resulting cmake modules had their inputs and outputs documented in top-of-file comments. The dts module is an exception, which makes it harder to use since its contracts aren't defined. Fix this by adding a contract. Signed-off-by: Martí Bolívar <[email protected]>
caf15af
to
668ded1
Compare
This list processing procedure will be useful elsewhere, so prep for not repeating ourselves. Put it in a new zephyr_list() function whose signature has room to grow if we keep adding list processing extensions. Signed-off-by: Martí Bolívar <[email protected]>
Tighten up the interface boundaries by adding an extension function that separates *how* we preprocess the DTS from *what* DTS files we are preprocessing. This involves a functional change to the pre_dt module. This is useful cleanup but is also groundwork for relying on this helper function when adding system devicetree support. Signed-off-by: Martí Bolívar <[email protected]>
cmake/modules/dts.cmake
Outdated
if(i EQUAL 0) | ||
message(STATUS "Found BOARD.dts: ${dts_file}") | ||
else() | ||
if(dts_file MATCHES ".*[.]overlay$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if someone provides a file with a different file extension? What if someone on windows provides a file with the extension in CAPS LOCK mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for a late discovery of changed printing behavior.
I believe it is important to always print dts files that we will be using.
Only printing the files in certain conditions can lead to user confusions / concerns that files are not processed, even though they are.
cmake/modules/dts.cmake
Outdated
if(i EQUAL 0) | ||
message(STATUS "Found BOARD.dts: ${dts_file}") | ||
else() | ||
if(dts_file MATCHES ".*[.]overlay$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually changes printing behavior.
Existing on zephyr/main
, if you specify -DDTS_SOURCE=<path>/foo.dts
, the following is printed:
-- Found BOARD.dts: /<path>/foo.dts
but with those changes, nothing is printed when specifying: -DDTS_SOURCE=
because this line only prints for files ending with .overlay
.
and board file is now printed here when DTS_SOURCE
is not given by caller:
zephyr/cmake/modules/dts.cmake
Line 131 in 668ded1
message(STATUS "Found BOARD.dts: ${DTS_SOURCE}") |
especially is system-dt and sysbuild is expected in future to generate and use DTS_SOURCE
I believe that it is important that the list of dts_files
being used are always printed, as they are today.
Also for the case when the files specified by the caller is not ending in .overlay
cause the files are still used by the build system.
668ded1
to
753c5fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proposal to adjust printing by simply checking dts_file against list content.
This minimize the need for bookeeping and remove the risk of flaws if lists are passed using DTS_SOURCE
.
cmake/modules/dts.cmake
Outdated
set(BOARD_DTS ${BOARD_DIR}/${BOARD}.dts) | ||
set(FOUND_BOARD_DTS FALSE) | ||
set(HAD_DTS_SOURCE FALSE) | ||
if(DEFINED DTS_SOURCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically this changes behavior as it is now possible to pass a list of files and not just a single file.
The old if(EXISTS ...)
code fails if a list is passed as it can only check existence of a single file / folder.
but when looking at our docs then DTS_SOURCE
is not described, so I wonder if this is in something we should worry about.
Do we plan to pass a list of files in future ?
Another thing to notice is that this test later will fail if a list was provided:
zephyr/cmake/modules/dts.cmake
Line 176 in 753c5fd
if(HAD_DTS_SOURCE AND ("${dts_file}" STREQUAL "${ORIGINAL_DTS_SOURCE}")) |
cmake/modules/dts.cmake
Outdated
if(FOUND_BOARD_DTS AND ("${dts_file}" STREQUAL "${BOARD_DTS}")) | ||
continue() # We already printed a message above. | ||
endif() | ||
|
||
math(EXPR i "${i}+1") | ||
if(HAD_DTS_SOURCE AND ("${dts_file}" STREQUAL "${ORIGINAL_DTS_SOURCE}")) | ||
continue() | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know that above code would have printed any file present in DTS_SOURCE
list.
So why not simply skip if the dts_file
is part of that list, and avoid all the other book keeping.
if(FOUND_BOARD_DTS AND ("${dts_file}" STREQUAL "${BOARD_DTS}")) | |
continue() # We already printed a message above. | |
endif() | |
math(EXPR i "${i}+1") | |
if(HAD_DTS_SOURCE AND ("${dts_file}" STREQUAL "${ORIGINAL_DTS_SOURCE}")) | |
continue() | |
endif() | |
if(dts_file IN_LIST DTS_SOURCE) | |
# Any file present in DTS_SOURCE has already be printed above | |
continue() | |
endif |
cmake/modules/dts.cmake
Outdated
if(BOARD_REVISION AND EXISTS ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay) | ||
list(APPEND DTS_SOURCE ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If adding a message print here, then we can remove all the extra book keeping as any file present in DTS_SOURCE
has been print when reaching code below:
if(BOARD_REVISION AND EXISTS ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay) | |
list(APPEND DTS_SOURCE ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay) | |
set(board_rev_overlay ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay) | |
if(BOARD_REVISION AND EXISTS ${board_rev_overlay}) | |
message(STATUS "Found devicetree overlay: ${board_rev_overlay}") | |
list(APPEND DTS_SOURCE ${board_rev_overlay}) |
753c5fd
to
a089d60
Compare
@tejlmand I just dropped the last patch since it's causing controversy. My goal here is just to isolate non-controversial patches that can go in now. We'll deal with printing in the system DT support PRs. |
Nothing in here directly adds system DT support; it's all just cleanups and rearranging things to make adding it easier.
No functional changes expected.