Shell script to emulate warnings-as-errors?
Posted
by talkaboutquality
on Stack Overflow
See other posts from Stack Overflow
or by talkaboutquality
Published on 2009-04-20T14:07:36Z
Indexed on
2010/03/24
10:03 UTC
Read the original article
Hit count: 465
Some compilers let you set warnings as errors, so that you'll never leave any compiler warnings behind, because if you do, the code won't build. This is a Good Thing.
Unfortunately, some compilers don't have a flag for warnings-as-errors.
I need to write a shell script or wrapper that provides the feature.
Presumably it parses the compilation console output and returns failure if there were any compiler warnings (or errors), and success otherwise. "Failure" also means (I think) that object code should not be produced.
What's the shortest, simplest UNIX/Linux shell script you can write that meets the explicit requirements above, as well as the following implicit requirements of otherwise behaving just like the compiler: - accepts all flags, options, arguments - supports redirection of stdout and stderr - produces object code and links as directed
Key words: elegant, meets all requirements.
Extra credit: easy to incorporate into a GNU make file.
Thanks for your help.
=== Clues === This solution to a different problem, using shell functions (?), Append text to stderr redirects in bash, might figure in. Wonder how to invite litb's friend "who knows bash quite well" to address my question?
=== Answer status ===
Thanks to Charlie Martin for the short answer, but that, unfortunately, is what I started out with. A while back I used that, released it for office use, and, within a few hours, had its most severe drawback pointed out to me: it will PASS a compilation with no warnings, but only errors. That's really bad because then we're delivering object code that the compiler is sure won't work. The simple solution also doesn't meet the other requirements listed.
Thanks to Adam Rosenfield for the shorthand, and Chris Dodd for introducing pipefail to the solution. Chris' answer looks closest, because I think the pipefail should ensure that if compilation actually fails on error, that we'll get failure as we should. Chris, does pipefail work in all shells? And have any ideas on the rest of the implicit requirements listed above?
© Stack Overflow or respective owner