NOAA-EMC / WW3

WAVEWATCH III
Other
262 stars 530 forks source link

Opportunistic grep finds build error when none exist #185

Closed vkbo closed 3 years ago

vkbo commented 4 years ago

Hi,

I just started using WW3, and I've spent the better part of a day trying to debug why my local test build fails. It turns out that the grep command that counts the number of errors reported in the .err file for one of the generated source files, wmgridmd.F90 when using the Ifremer1 switches, produces a false positive.

The line detected as an error is the following:

wmgridmd.F90:2619:5:

  1021 FORMAT (/' *** WAVEWATCH III ERROR IN WMGHGH : *** '/           &
     1
Warning: Label 1021 at (1) defined but not used [-Wunused-label]

This is obviously incorrect, and caused by the following two lines in the generated comp script (I used Gnu_debug):

    nr_err="$(grep -i error $name.err | wc -l | awk '{ print $1 }')"
    nr_war="$(grep -i warning $name.err | wc -l | awk '{ print $1 }')"

This picks up the word ERROR in the echoed source code and counts it as a build error, causing an exit.

Modifying the regex by requiring the keyword to be at the beginning of the line, solves this:

    nr_err="$(grep -i ^error $name.err | wc -l | awk '{ print $1 }')"
    nr_war="$(grep -i ^warning $name.err | wc -l | awk '{ print $1 }')"

With this, the build completes with no error.

This form of error detection seems very fragile.

aliabdolali commented 3 years ago

@vkbo is this still an issue?

ukmo-ccbunney commented 3 years ago

PR #419 addresses this for the GNU compiler and provides a method to do so for other compilers to cia the err_pattern and warn_pattern variables in cmplr.env

It is not feasible to set the grep to ^error for all instances as some compilers produce messages that don't match that pattern.

vkbo commented 3 years ago

I no longer use WaveWatch and I'm leaving the field in a couple of months, so for me it's no longer relevant. Whether the fix changes it or not, I can't say.

In any case, this strikes me as a very fragile solution for detecting compiler errors. A build system using for instance CMake would be the optimal solution, but I know from experience how much work it is to make such a change on a large Fortran code base. I've done it before.

aliabdolali commented 3 years ago

@vkbo Thanks, we are moving towards CMake, so WW3 will be equipped with CMake build. I close the issue now.