Commit 1344c1ca authored by Ben Avison's avatar Ben Avison
Browse files

Allow additional flags to be passed to cppcheck

These can be specified in the `.gitlab-ci.yml` file (or if launching a
pipeline manually, via `CI/CD` -> `Pipelines` -> `Run pipeline`) using the
`CPPCHECK_EXTRA` variable. It is anticipated that this will be most useful
for specifying additional `--suppress` arguments.

Because library components routinely feature functions that are not called
from elsewhere within the library itself, the `unusedFunction` warning is
very commonly encountered in these components. To reduce the number of times
this needs to be specified in `.gitlab-ci.yml` files, `CPPCHECK_EXTRA`
defaults to `--suppress-unusedFunction` if it is unset for a library.

Because libraries are often listed as type `C` in `ModuleDB`, we instead
inspect the component name to see if it ends with `Lib` in order to activate
this functionality.
parent 671f57a1
Pipeline #3565 passed with stage
in 3 seconds
...@@ -577,11 +577,14 @@ BEGIN { ...@@ -577,11 +577,14 @@ BEGIN {
# globally, by file, or file and line number) is to pass it an XML file. We generate suitable XML # globally, by file, or file and line number) is to pass it an XML file. We generate suitable XML
# during "make standalone" above, with a standardised filename, so if it exists, use it. # during "make standalone" above, with a standardised filename, so if it exists, use it.
print " - CMHG_XML=$(test -f objs/cmhg-cppcheck-suppress.xml && echo --suppress-xml=objs/cmhg-cppcheck-suppress.xml || true)" >> out print " - CMHG_XML=$(test -f objs/cmhg-cppcheck-suppress.xml && echo --suppress-xml=objs/cmhg-cppcheck-suppress.xml || true)" >> out
# For projects whose name ends in "Lib", make CPPCHECK_EXTRA default to "--suppress=unusedFunction"
if (project ~ /Lib$/)
print " - CPPCHECK_EXTRA=${CPPCHECK_EXTRA:---suppress=unusedFunction}" >> out
# Enable all warnings except those marked inline, plus shiftNegativeLHS (used in _swix macros and # Enable all warnings except those marked inline, plus shiftNegativeLHS (used in _swix macros and
# therefore ubiquitous) and purgedConfiguration (we don't care if a build switch has no effect). # therefore ubiquitous) and purgedConfiguration (we don't care if a build switch has no effect).
# cppcheck's --error-exitcode option appears to be too eager to report failure, so synthesise it by # cppcheck's --error-exitcode option appears to be too eager to report failure, so synthesise it by
# counting the number of lines printed to stderr. # counting the number of lines printed to stderr.
print " - test ! -d c || { { { { cppcheck --enable=all --suppress=shiftNegativeLHS --suppress=purgedConfiguration --inline-suppr $CMHG_XML --std=c99 $CFLAGS -UNAMESPACE_OSLIB -U__swi --verbose --max-configs=100 objs/*.c; } 3>&1 1>&2 2>&3; } | tee >( grep -v '^[^ ]* information[:] ' | grep -v '^$' | wc -l >&3 ); } 3>&1 1>&2; } | { read lines; exit $lines; }" >> out print " - test ! -d c || { { { { cppcheck --enable=all --suppress=shiftNegativeLHS --suppress=purgedConfiguration --inline-suppr $CMHG_XML $CPPCHECK_EXTRA --std=c99 $CFLAGS -UNAMESPACE_OSLIB -U__swi --verbose --max-configs=100 objs/*.c; } 3>&1 1>&2 2>&3; } | tee >( grep -v '^[^ ]* information[:] ' | grep -v '^$' | wc -l >&3 ); } 3>&1 1>&2; } | { read lines; exit $lines; }" >> out
print " allow_failure: true" >> out print " allow_failure: true" >> out
print "" >> out print "" >> out
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment