Turning warning into errors

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Turning warning into errors

Sébastien Hinderer
Dear all,

We recently noticed a few undefined variables in our makefiles.
We would like to use --warn-undefined-variables to track them, e.g. on
our CI infrastructure, but we find it problematic that the warning can
not be turned into an error.

Am I correct that there is currently no way to achieve this and, if so,
am I correct that it is a deliberate choice not to provide this featur?
In that case I'd be curious about why this has been decided.

Is there any other known approach to deal with this?

In particular, has somebody ever tried
https://github.com/mrtazz/checkmake
?

Many thanks in advance for any help,

Sébastien.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Duane Griffin
Hi Sébastien,

I've not heard of that tool, but it sounds useful.

Unfortunately we now use cmake internally, but a while ago I wrote
some GNU makefile code to perform some checks like this for our rather
complex GNU make-based build system of the time. See the attached
file; it should still work and the undefined variables test is
hopefully relatively straight-forward and self-explanatory. You will
obviously need to adjust the targets in the check_undefined_vars
recipe as may be appropriate for your project. Note also the self-test
code, which should verify that the check actually works.

It also does several other checks which are probably not relevant to
you, but which I can explain if you are interested. Otherwise just
delete all the code unrelated to check_undefined_vars.

Cheers,
Duane.

On Fri, May 3, 2019 at 12:18 AM Sébastien Hinderer
<[hidden email]> wrote:

>
> Dear all,
>
> We recently noticed a few undefined variables in our makefiles.
> We would like to use --warn-undefined-variables to track them, e.g. on
> our CI infrastructure, but we find it problematic that the warning can
> not be turned into an error.
>
> Am I correct that there is currently no way to achieve this and, if so,
> am I correct that it is a deliberate choice not to provide this featur?
> In that case I'd be curious about why this has been decided.
>
> Is there any other known approach to deal with this?
>
> In particular, has somebody ever tried
> https://github.com/mrtazz/checkmake
> ?
>
> Many thanks in advance for any help,
>
> Sébastien.
>
> _______________________________________________
> Help-make mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-make


--
"I never could learn to drink that blood and call it wine" - Bob Dylan

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make

Check.mk (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Sébastien Hinderer
Dear Duane,

Many thanks for your response!

You are right, the code is rather straightforward and at the same time I
find it clever! In particular, I like the fact that, because of the
options you are using, you don't need to use grep to figure out whether
there are warnings or not. We would have to work quite a bit to reach
this state but it's interesting to know the trick so I am very grateful
to you that you shared your solution with me!

Best wishes,

Sébastien.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Kaz Kylheku (gmake)
On 2019-05-02 18:31, Sébastien Hinderer wrote:

> Dear Duane,
>
> Many thanks for your response!
>
> You are right, the code is rather straightforward and at the same time
> I
> find it clever! In particular, I like the fact that, because of the
> options you are using, you don't need to use grep to figure out whether
> there are warnings or not. We would have to work quite a bit to reach
> this state but it's interesting to know the trick so I am very grateful
> to you that you shared your solution with me!

Hmm? It seems you don't have to work hard at all; you can just run
your existing Makefile with those same options to get an immediate
benefit:

   make --warn-undefined-variables --silent --dry-run clean ... 2>&1 >
/dev/null

and check that the output is empty.  Duane has just put in a convenience
target to do this via "make check_undefined_vars".

Let's try it in a project of mine:

   ~/txr$ make --warn-undefined-variables --silent --dry-run clean 2>&1  
 > /dev/null
   Makefile:32: warning: undefined variable `CFLAGS'
   Makefile:33: warning: undefined variable `EXTRA_FLAGS'
   Makefile:37: warning: undefined variable `LDFLAGS'
   Makefile:38: warning: undefined variable `EXTRA_LDFLAGS'

Good. These should be undefined; if the user sets these, we use them.
Glad to see there are no others. :)

The "make self_test_check_undefined_vars" target just triggers an
undefined
variable condition (the expression $(nothing at all)) to provide a basic
proof that it's doing something.

This can be integrated in a simpler form without the self-test stuff,
and
you might not be interested in the other kinds of checks that are in
that
file that add to its complexity.


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Sébastien Hinderer
Kaz Kylheku (gmake) (2019/05/02 19:48 -0700):

> On 2019-05-02 18:31, Sébastien Hinderer wrote:
> > Dear Duane,
> >
> > Many thanks for your response!
> >
> > You are right, the code is rather straightforward and at the same time I
> > find it clever! In particular, I like the fact that, because of the
> > options you are using, you don't need to use grep to figure out whether
> > there are warnings or not. We would have to work quite a bit to reach
> > this state but it's interesting to know the trick so I am very grateful
> > to you that you shared your solution with me!
>
> Hmm? It seems you don't have to work hard at all; you can just run
> your existing Makefile with those same options to get an immediate benefit:

No, some commands in our build system do display messages. And, because
our makeifles are not as declarative as they could/should, a dry-run
owuld not work completely.

Sébastien.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Duane Griffin
In reply to this post by Sébastien Hinderer
On Fri, May 3, 2019 at 1:31 PM Sébastien Hinderer
<[hidden email]> wrote:

> Dear Duane,
>
> Many thanks for your response!
>
> You are right, the code is rather straightforward and at the same time I
> find it clever! In particular, I like the fact that, because of the
> options you are using, you don't need to use grep to figure out whether
> there are warnings or not. We would have to work quite a bit to reach
> this state but it's interesting to know the trick so I am very grateful
> to you that you shared your solution with me!

Thanks, I'm really pleased you like it! I've got a bunch of other
fragments I can post, if anyone is interested in stuff like a stupidly
over-engineered module system implementing pseudo-file-scoped
variables in pure GNU make...

Cheers,
Duane.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Duane Griffin
In reply to this post by Kaz Kylheku (gmake)
On Fri, May 3, 2019 at 2:48 PM Kaz Kylheku (gmake)
<[hidden email]> wrote:

> Let's try it in a project of mine:
>
>    ~/txr$ make --warn-undefined-variables --silent --dry-run clean 2>&1
>  > /dev/null
>    Makefile:32: warning: undefined variable `CFLAGS'
>    Makefile:33: warning: undefined variable `EXTRA_FLAGS'
>    Makefile:37: warning: undefined variable `LDFLAGS'
>    Makefile:38: warning: undefined variable `EXTRA_LDFLAGS'
>
> Good. These should be undefined; if the user sets these, we use them.
> Glad to see there are no others. :)

We had this sort of issue initially with "legitimate" undefined
variables. We added e.g. "CFLAGS ?=#" or "ifdef <blah>" blocks, which
eliminated them and allowed us to fail the build if others were
introduced. My experience is that if the build doesn't fail warnings
tend to be overlooked...

One other thing to keep in mind (I'm sure you know this, but for
others reading along at home): you might need to be careful about
which targets you give. In complex makefiles specifying different
targets may change which variables are defined/used, which is why in
our code it specified several targets, not just "clean".

Cheers,
Duane.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Paul Smith-20
In reply to this post by Sébastien Hinderer
On Thu, 2019-05-02 at 14:17 +0200, Sébastien Hinderer wrote:
> Am I correct that there is currently no way to achieve this and, if so,

There is no way to turn these warnings into errors.

> am I correct that it is a deliberate choice not to provide this featur?
> In that case I'd be curious about why this has been decided.

The creation of the warning option predates my maintenance of GNU make,
so I can't speak to whether it was a deliberate choice to not provide
an "error" form of the check.

I personally don't have any problems with an error version of this
option existing.

I wonder if it would be useful to implement something more similar to
GCC's warning options facility, to prepare for future warning/error
possibilities.


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Turning warning into errors

Sébastien Hinderer
Dear Paul,

Many thanks for having taken the time to respond!

Paul Smith (2019/05/04 14:57 -0400):

> On Thu, 2019-05-02 at 14:17 +0200, Sébastien Hinderer wrote:
> > Am I correct that there is currently no way to achieve this and, if so,
>
> There is no way to turn these warnings into errors.
>
> > am I correct that it is a deliberate choice not to provide this featur?
> > In that case I'd be curious about why this has been decided.
>
> The creation of the warning option predates my maintenance of GNU make,
> so I can't speak to whether it was a deliberate choice to not provide
> an "error" form of the check.
>
> I personally don't have any problems with an error version of this
> option existing.
>
> I wonder if it would be useful to implement something more similar to
> GCC's warning options facility, to prepare for future warning/error
> possibilities.

This second possibility definitely has my preference!

Willing to test patches.

Best wishes,

Sébastien.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make