Skip to content
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

Print & color build script warnings, even when build script panics #3672

Closed
mystor opened this issue Feb 8, 2017 · 7 comments · Fixed by #8017
Closed

Print & color build script warnings, even when build script panics #3672

mystor opened this issue Feb 8, 2017 · 7 comments · Fixed by #8017
Labels
A-build-scripts Area: build.rs scripts A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@mystor
Copy link

mystor commented Feb 8, 2017

Currently, when the build script panics, the stdout of the build script is written out to show what happened. However, this means that any warnings emitted during the build script (using cargo:warning= from #2630) won't be printed nicely like they are when the build script succeeds.

It would be nice if these warnings could be printed prettily even when the build script fails to execute due to a panic.

@alexcrichton
Copy link
Member

Seems reasonable to me! Do you have a preference either before or after the standard error output?

@mystor
Copy link
Author

mystor commented Feb 9, 2017

I feel like putting the warning before the panic dump is a good idea, because conceptually the warnings were "emitted" by the build script before the build script "emitted" the panic. I'm open to other options though.

@alexcrichton
Copy link
Member

Seems reasonable to me. Unfortunately I probably won't have time to implement this in the near future, but I believe the relevant loop is this one. We likely just need to listen for more messages coming on self.rx and print them out in the same fashion.

@carols10cents carols10cents added A-build-scripts Area: build.rs scripts A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Sep 29, 2017
@aleksator
Copy link
Contributor

I did some investigation on this and here's what I've found:

The warnings get printed in emit_warnings() from build_script_outputs variable, but when build script panics it is empty. Since it does not contain warnings or anything else, nothing gets printed at this point.

As to why that happens:
build_script_outputs gets filled in build_work() function, but when a panic happens an error is thrown in exec_with_streaming(), so build_work() quits early on question mark here and filling of build_script_outputs isn't reached.

The output with warnings is still contained inside the error returned by exec_with_streaming() and is printed later in stack trace in a raw form of --- stdout cargo:warning=*warning from build script*.

At this point I would like to get the team's input on what would be the cleanest way to push warnings into build_script_outputs in unhappy path, and whether we would need to solve the resulting duplication of warnings in colored and raw forms.

@ehuss
Copy link
Contributor

ehuss commented Mar 14, 2020

Yea, that's a little awkward. I think what I would do is inside the stdout callback, check for lines that start with cargo:warning= and stash the line into a Vec of warnings. If exec_with_streaming returns an error, it can take those warnings and generate an empty BuildOutput, and set the warnings field and insert the BuildOutput into the map. I think that should then get picked up by emit_warnings, but not interfere with anything else.

Also, an unrelated thing: it might be nice for build script warnings to be prefixed with the package name/version (the same way it is prefixed with -vv). I notice that the warning doesn't indicate where it comes from, so that might be useful.

@aleksator
Copy link
Contributor

@ehuss I've done the suggested implementation

Also, an unrelated thing: it might be nice for build script warnings to be prefixed with the package name/version (the same way it is prefixed with -vv). I notice that the warning doesn't indicate where it comes from, so that might be useful.

Maybe worth creating a separate issue for this?

@ehuss
Copy link
Contributor

ehuss commented Mar 18, 2020

Maybe worth creating a separate issue for this?

Sure, posted #8018.

bors added a commit that referenced this issue Mar 18, 2020
…anic, r=ehuss

Print colored warnings when build script panics

Fixes #3672
@bors bors closed this as completed in 590c803 Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants