-
Notifications
You must be signed in to change notification settings - Fork 8.3k
cmake: modules: dts: make Device Tree error messages more visible #76472
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: modules: dts: make Device Tree error messages more visible #76472
Conversation
cmake/modules/dts.cmake
Outdated
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.
let's just print all knowledge we have whenever there is a failure.
| if (stderr) | |
| message(FATAL_ERROR "gen_defines.py failed due to ${stderr}") | |
| else() | |
| message(FATAL_ERROR "gen_defines.py failed with return code: ${ret}") | |
| endif() | |
| message(FATAL_ERROR "gen_defines.py failed with return code: ${ret}\nstderr: ${stderr}") |
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 do you think about the following?
It avoids printing the stderr:\n when there's nothing in stderr (which, arguably, should never happen...)
| if (stderr) | |
| message(FATAL_ERROR "gen_defines.py failed due to ${stderr}") | |
| else() | |
| message(FATAL_ERROR "gen_defines.py failed with return code: ${ret}") | |
| endif() | |
| if (stderr) | |
| set(stderr "\nScript stderr: ${stderr}") | |
| endif() | |
| message(FATAL_ERROR "gen_defines.py failed with return code: ${ret}${stderr}") |
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.
It avoids printing the
stderr:\nwhen there's nothing instderr
I actually think that a stderr: with no content actually indicates to users that there actually was no error message, which can also be useful information.
If not, then users would actually need to know that stderr is only missing if it is empty, something they can only know if they look in the CMake file.
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.
I see your point. However, I think an empty stderr: could be confusing.
Would displaying stderr: <empty> instead be fine by you?
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.
Would displaying
stderr: <empty>instead be fine by you?
yes, that's a clear indication to the user that an error ocured, but that there were no messages printed to stderr.
508aa8e to
e8e5e6d
Compare
|
Changelog:
N.B.: I assumed that |
e8e5e6d to
222697d
Compare
|
Oops, I forgot to check-in the modified code before pushing... 🤦♂️ |
This commit modifies the DTS cmake module to capture `stderr` output of the `gen_defines.py` script and `dtc` program during their execution. The messages can then be printed as CMake `message`s, which improves QoL when debugging device tree errors, and reduces the risk of introducing malformed DTS, as the warning/error messages are made much more visible. Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
222697d to
c865cd2
Compare
|
Changelog:
The error logs now look like what follows (truncated):
|
Ever since 059aae7 (cmake: modules: dts: make Device Tree error messages more visible, PR zephyrproject-rtos#76472), warnings generated by gen_defines.py got only printed when the exit code signaled an error. Without this patch, the warning gets swallowed and the build continues: ``` $ west build --pristine --board nrf54l15pdk/nrf54l15/cpuapp \ samples/userspace/hello_world_user <snip> -- Found BOARD.dts: <snip>/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.dts -- Generated zephyr.dts: <snip>/build/zephyr/zephyr.dts <snip> ``` With this patch, the behavior is back to how it was before 059aae7: ``` $ west build --pristine --board nrf54l15pdk/nrf54l15/cpuapp \ samples/userspace/hello_world_user <snip> -- Found BOARD.dts: <snip>/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.dts unit address and first address in 'reg' (0x5004c000) don't match for /soc/peripheral@50000000/vpr@4c000/mailbox@1 -- Generated zephyr.dts: <snip>zephyr/build/zephyr/zephyr.dts <snip> ``` Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
Ever since 059aae7 (cmake: modules: dts: make Device Tree error messages more visible, PR #76472), warnings generated by gen_defines.py got only printed when the exit code signaled an error. Without this patch, the warning gets swallowed and the build continues: ``` $ west build --pristine --board nrf54l15pdk/nrf54l15/cpuapp \ samples/userspace/hello_world_user <snip> -- Found BOARD.dts: <snip>/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.dts -- Generated zephyr.dts: <snip>/build/zephyr/zephyr.dts <snip> ``` With this patch, the behavior is back to how it was before 059aae7: ``` $ west build --pristine --board nrf54l15pdk/nrf54l15/cpuapp \ samples/userspace/hello_world_user <snip> -- Found BOARD.dts: <snip>/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.dts unit address and first address in 'reg' (0x5004c000) don't match for /soc/peripheral@50000000/vpr@4c000/mailbox@1 -- Generated zephyr.dts: <snip>zephyr/build/zephyr/zephyr.dts <snip> ``` Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
This PR modifies the DTS CMake module to capture
stderroutput of thegen_defines.pyscript and print it as part of the CMake FATAL_ERROR message in case of failure. With this, the usual "devicetree error" message is no longer buried in the build log, which is a huge quality-of-life improvement when debugging DT errors.Example output log before PR: (note how line 2 is the one containing useful information)
(N.B.: the log has been slightly modified to be able to highlight the error message in red using the
diffsyntax, as CMake would be doing in a real terminal. Note also that GitHub does not wrap lines unlike (some) terminal emulators, which makes this even more unreadable)Example log after PR:
The message
gen_defines.py failed due to ${stderr}is chosen becausegen_definesmay only print one of these messages tostderr(seesys.exitcalls):devicetree error: {e}ERROR: Duplicate 'zephyr,memory-region' ({region}) properties between {regions[region].path} and {node.path}