-
Notifications
You must be signed in to change notification settings - Fork 8.3k
cmake: modules: dts: print stderr on failure #79236
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
Conversation
|
Commit body is too long |
059aae7 actually hid error messages completely instead of making them more visible. db7a390 restored that for some processes, but not for dtc itself. Without this patch, a device tree error like a missing `reg` property failed the build without showing the reason. Signed-off-by: Michael Zimmermann <[email protected]>
How can I fix that, given that those are log messages? |
|
Don't put the log messages in, a description of what this is fixing is sufficient |
a1894df to
c1fa610
Compare
I'd put the log msg in the PR (first post) |
|
Fixed, CI passes now. |
good idea, thx. done. |
tejlmand
left a comment
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.
not blocking as this does fix the issue at hand, but I would actually prefer that code is cleaned up.
|
|
||
| if(NOT "${ret}" STREQUAL "0") | ||
| message(FATAL_ERROR "dtc failed with return code: ${ret}") | ||
| message(FATAL_ERROR "dtc failed with return code: ${ret}\n${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.
better to remove all this complex code and instead simply do:
execute_process(
COMMAND ${DTC}
...
${ZEPHYR_DTS}
OUTPUT_QUIET # Discard stdout
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
and then remove the
if(NOT "${ret}" STREQUAL "0")
...
logic below.
See also this comment for details: #78250 (comment)
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.
So with COMMAND_ERROR_IS_FATAL, cmake only prints the output on failure? Or will will always prints the output no matter what with your proposed change?
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 will print any output on standard error regardless of the error code.
Basically:
- COMMAND_ERROR_IS_FATAL: Will fail CMake if return code is different from zero.
Flag has no relation / impact on standard out or standard error. - No
ERROR_OUTPUT, will print any message from standard error in the normal CMake output.
Just like we are doing withmessage(... "... ${stderr}").
See: https://cmake.org/cmake/help/latest/command/execute_process.html
If no OUTPUT_* or ERROR_* options are given the output will be shared with the corresponding pipes of the CMake process itself.
Note: OUTPUT_QUIET discard only standard out, not standard error.
|
While I fully acknowledge that #76472 was flawed, I don't really agree with completely reverting it as is being done with this PR + #78250. (The reason why I didn't bother printing dtc's I must admit that the current state is slightly improved compared to pre-76472... merely because we no longer print the faulty command 😅. The CMake error message is however more confusing, in my opinion: Found BOARD.dts: ~/zephyrproject/zephyr/boards/st/nucleo_f401re/nucleo_f401re.dts
devicetree error: 'reg' appears in /soc/custom-controller@80/child-device@0 in ~/zephyrproject/build/zephyr/zephyr.dts.pre, but is not declared in 'properties:' in ~/zephyrproject/zephyr/dts/bindings/acpi/test_binding_1.yaml
- CMake Error at ~/zephyrproject/zephyr/cmake/modules/dts.cmake:301 (execute_process):
- execute_process failed command indexes:
-
- 1: "Child return code: 1"
-
-Call Stack (most recent call first):
- ~/zephyrproject/zephyr/cmake/modules/zephyr_default.cmake:133 (include)
- ~/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
- ~/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
- CMakeLists.txt:5 (find_package)
Configuring incomplete, errors occurred!For reference, a similar failure would look like this previously: Error message pre-76472 Found BOARD.dts: ~/zephyrproject/zephyr/boards/st/nucleo_f401re/nucleo_f401re.dts
devicetree error: ~/zephyrproject/zephyr/boards/st/nucleo_f401re/nucleo_f401re.dts:27 (column 2): parse error: expected ';', not 'leds'
In: ~/zephyrproject/zephyr/build/zephyr, command: ~/zephyrproject/.venv/bin/python3;~/zephyrproject/zephyr/scripts/dts/gen_defines.py;--dts;~/zephyrproject/zephyr/build/zephyr/zephyr.dts.pre;--dtc-flags;'';--bindings-dirs;~/zephyrproject/zephyr/dts/bindings;--header-out;~/zephyrproject/zephyr/build/zephyr/include/generated/zephyr/devicetree_generated.h.new;--dts-out;~/zephyrproject/zephyr/build/zephyr/zephyr.dts.new;--edt-pickle-out;~/zephyrproject/zephyr/build/zephyr/edt.pickle;--vendor-prefixes;~/zephyrproject/zephyr/dts/bindings/vendor-prefixes.txt
-CMake Error at ~/zephyrproject/zephyr/cmake/modules/dts.cmake:301 (message):
- gen_defines.py failed with return code: 1
- Call Stack (most recent call first):
- ~/zephyrproject/zephyr/cmake/modules/zephyr_default.cmake:132 (include)
- ~/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
- ~/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
- CMakeLists.txt:5 (find_package)
Configuring incomplete, errors occurred!While I understand @tejlmand's point of using I'm not -1'ing because this works, but I think keeping the behavior I tried to introduce with #76472 would be better - maybe a function wrapping Proposal concept# just a toy proposal, so WORKING_DIRECTORY etc not handled...
function(zephyr_execute_process command)
execute_process(COMMAND ${command}
RESULT_VARIABLE status
OUTPUT_QUIET
ERROR_VARIABLE stderr
)
if (NOT "${status}" STREQUAL "0")
# Program failed -> FATAL_ERROR. Print stderr if present, or indicate it was empty.
if (NOT stderr)
set(stderr "<empty stderr>")
endif()
message(FATAL_ERROR "${command} failed with status code ${status}\n${stderr}")
elif(stderr)
message(WARNING "${command} succeeded with non-empty stderr:\n${stderr}")
endif()
endfunction() |
and this to me exactly show why we should keep things simple and let CMake handle stuff in most case because people often fail to realize exactly how those output and error variables work. From CMake docs:
So if you don't specify and is also what you have in your own comment here: #79236 (comment)
@mathieuchopstm The part where I do believe CMake can improve is this part:
But for that I'm not convinced that it's better for us to have our own wrapper function. |
Not exactly. When
Since CMake's error message is ~10 lines while It may be a weak argument, but I find support for my point in #77266, filed merely two weeks after #76472, which reported a
While I agree in principle, this sounds more like wishful thinking that a true solution: the issue is 1 year old and has no activity... and even if we assumed the feature was implemented right now, Zephyr's documentation says that the minimum CMake version is 3.20.5 (~3 years old) - would bumping this requirement to $LATEST be a sound idea (or even feasible)? |
I agree that this is not ideal, but I'm also in favor of two other things, simplicity and consistency. This PR will mean that stderr in sometimes printed before CMake's own message and stack trace, and sometimes as part of the warning / error code from CMake's Perhaps in this case a solution could be to introduce a That will ensure the two points, simplicity and consistency. Thoughts ? |
This is the idea I had in mind, and suggested at the end of #79236 (comment), so +1 from me.
Since this point has been open for a while, I'm fine with using your proposal ( |
|
@M1cha any update on this ? |
|
Superseded by #87303 I believe |
yes |
059aae7 actually hid error messages completely instead of making them more visible.
db7a390 restored that for some processes, but not for dtc itself.
Without this patch, a device tree error like a missing
regpropertyfailed the build without showing the reason:
With it, you can see the cause of the failure like before: