-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Is it possible to leave stderr messages from the compiler on stderr and not redirect them to stdout? #1537
Comments
What do you need it for? |
I would like to separate build output into too files: |
You won't know which warning or error belongs to which build output line. What's the reason behind the two files? |
Mostly just warning detection. If there are warnings, they should be either fixed or disabled. The warning usually contains source filename and line number, so there is no need to find corresponding lines of ninja's own output. |
I see. Would #480 be enough for your use-case? The reason I'm asking is: We're trying to keep the number of options as low as possible. |
I'm not sure how that could possibly be the solution for my problem. Probably there may be a very hacky solution with NINJA_STATUS variable, but I can't think of one right now. |
You would run |
But in this case I will not get any ninja's own output. I would like to keep both, but split them. |
Why? |
In current build script I print a dot for every line on stdout and an x for every line on stderr. Saving both stdout and stderr into separate files. This keeps the CI from stopping because of the lack of output, gives a pretty visual output that helps to detect new warnings and errors and provides separate readable build logs with warning descriptions. This works for other build systems, but not for ninja as there is no way to tell if a line came from stderr or stdout. This is how I did it: tpimh/nenuzhnix-build@722ece3 (still to be rewritten properly) |
Set |
Yes, can be done this way. Thanks! |
This is my script for restoring justice over stdout and stderr: filter() {
local l n
while read -r l; do
n=${l#\[ninja\]}
[ "x$l" != "x$n" ] && printf "%s\n" "$n" || printf "%s\n" "$l" >&2
done
}
NINJA_STATUS="[ninja][%f/%t] " ninja | filter It may be a bit slow, but it works for me. Feel free to use and improve. UPD: replaced my obviously shitty code with a much better version by Vladimir Oleynik [email protected] |
For me the way that ninja ignores sfderr causes 'kate' to ignore all warnings/errors, which means that the build plugin doesn't work. |
Same for QtCreator. Just a simple script to wrap ninja with stdout > stderr is enough. But it would be nice if it would work out of the box. |
Can you share what and how you are actually using as the wrpaper? |
I have my own ninja wrapper. It's really bad, but it works. Written in POSIX shell, could be much easier in bash, but it's unfortunately not an option for me. |
|
Is there any chance this might be 'fixed' in ninja itself? If ninja considers all of its output to be errors, then perhaps it should just move to stderr. If it considers some of it to be informational, not indicating warnings/failures, then that part should go to stdout IMO. |
Hello, I am the author of the patch for this issue mentioned in the first comment: https://github.com/dendy/ninja/tree/stderr Patch is currently updated with Linux/Mac/Windows support and rebased onto master branch. I consider this issue as critical. Without separation of the stdout and stderr usage of the ninja is limited mostly to the CLI. IDEs and tools which expect the proper separation of output, like it was in the Makefiles, will not work with ninja at all. Here is the thing. Decision where to put an output should be made by the executing command, not the ninja itself. If some command decides to put portion of output to the stderr, that should be possible and properly pop up at the ninja's end in the stderr. Generally speaking stdout and stderr supposed to be completely independent, and it is up to the command itself to ensure that both streams are contiguous. And whoever is parsing the output should expect that stdout and stderr are not connected together. Now, I understand why ninja is combining both outputs, to keep them in sync with printing the execution command, so it is easier to see whole output in the solid chunk. Although such approach has it is own benefits in some cases, it is not the only one that is used in the build environments. Particularly using ninja from IDE requires to parse stderr. Not combined stdout and stderr, but stderr alone. Each line printed by the executing command into stderr is considered as a separate issue. The executing command arguments usually don't matter in the IDE context, and even if they do there are other ways to connect errors and command line, rather than eliminating the stderr completely. In worst case it will be the same experience as with Makefiles. I strongly believe that this feature is absolutely necessary. It should be up to the user, which method is preferable in particular case. It could be environment variable, command line argument, or some extra parameter in the build.ninja, or combination of those. But user should have control over this, whether output of the stdout and stderr should be merged together or not. For the 5 good years I never use combined output in any of my projects, either they are built from the command line or from IDE. And I am totally happy with the results. |
+1 we have a hundred lines of Python code trying to clean up the ninja output and it is still not right. It messes up downstream things also - e.g. Zephyr is quite broken in terms of what is a warning/error and what is normal behaviour. I wonder if the problem is that this tool came from Windows? Do you have a link to the stdout/stderr patch? We could perhaps just use that. |
@sjg20 You are totally right, this issue should be fixed at the Ninja level. Generally there is no way to process Ninja output in attempt to differentiate between stdout/stderr after outputs were merged. I believe the problem came out because of misunderstanding what outputs really are, and how contract between process output writers are readers should be. Probably in an attempt to solve the messed output because of the single pipe shared across multiple processes, this principle was explicitly highlighted in the Ninja documentation. But it has nothing to do with this issue. Link to the patch is in the initial comment to this ticket, let me know it works for you. |
@dendy OK thank you. I filed https://issuetracker.google.com/187728036 so we'll see what we end up doing. Someone also suggesting switching Cmake to generate plain Makefiles. |
This is a critical problem for me too - since @jhasse seems to refuse to add a simple option for it - where is the ninja fork that DOES implement this currently? Thanks. |
@jhasse can you please explain why do you object to having this as opt-in, as suggested here? This is a real pain to many users. |
I'm no longer maintaining Ninja. |
misclicked, sorry |
Then who can approve this? |
Any update? 🤔 |
@jhasse Do you know who is the current maintainer of the ninja? We are still looking to accept this feature as optional, without changing the default behavior. Who could help to proceed with this? |
No one really.
Well, it can at least discourage the use of stderr by not providing an option to split stdout/stderr. |
Combining stdout with stderr by default and lack of ability to not combine those two streams is really big problem on automatically analysing warnings and errors 😞 |
+1 we need a proper stderr. This is such a pain. Why is this so controversial?? |
@jhasse Ninja is only executing other tools, and behavior of those tools how to produce data for stdout and stderr already well defined. There are billions of those tools, Ninja may not change they behavior. In the case when parser of the Ninja output wants proper separation of stderr — there should be such an option. My proposal above is to add this feature. And keep original behavior (combined output) as default. So everybody will win and be happy. Have to rebase my patch onto recent master branch. Though first I will need your agreement in general to accept this feature. |
Gentle ping .. any update? 🤔 |
https://github.com/jhasse/ninja seems is no longer maintained 🤔 |
@kloczek Look at the veeeery top message, you will find a link to my branch: https://github.com/dendy/ninja/tree/stderr |
Can you resync your fork with ninja master? 🤔 + /usr/lib/rpm/rpmuncompress /home/tkloczko/rpmbuild/SOURCES/ninja-build-Add-option-to-split-stdout-and-stderr.patch
6 out of 8 hunks FAILED -- saving rejects to file src/build.cc.rej
2 out of 3 hunks FAILED -- saving rejects to file src/build.h.rej
1 out of 11 hunks FAILED -- saving rejects to file src/subprocess-posix.cc.rej |
Not really happy with the approach of passing through The problem we have, is that called applications end up assuming that full buffering was permissible, even when it clearly wasn't.
E.g. in this case, the patch with split That's not working properly at all with applications that split time correlated output onto different output streams, such as Doxygen which is splitting progress and warning messages. You still get warning messages completely out-of-sync with the progress messages they should have been embedded in between. Doxygen actually has a
That did do something sensible. Partially. The hack of preloading In case of Doxygen, the actual sane solution is to specifiy |
I just wrote this at the time and never looked back:
This reads from stdin, and fakes being a tty - so that the program that is passed doesn't buffer. I'm using it like this:
from a bash script. |
@kloczek Apologies for the late response, just rebased stderr branch onto recent master. Please check it out. |
I'd like to add a "me too" here as well, the merging of the output streams completely destroys our handling of the output of the applications that ninja is calling. We've now switched back to Make due to this. I'm very sad to read as well that Ninja is no longer being maintained, it was a good build engine for a while. |
I understand that default ninja behavior is to only print to stdout, but I wonder if it's possible to implement this as an option like done in this branch: https://github.com/dendy/ninja/tree/stderr
The text was updated successfully, but these errors were encountered: