runtests.sh: refactoring and cleanups (#4029)

* runtests.sh: avoid redundant `pkg-config` checks and simplified the check

* runtests.sh: write a message when something is completely missing

* runtests.sh: derive paths from script location

* runtests.sh: improved readability by using individual functions for each file

* runtests.sh: added helper function `get_pkg_config_cflags()` to clean up cflag lookup from `pkg-config`

* runtests.sh: simplified `xmlstarlet` calls
This commit is contained in:
Oliver Stöneberg 2022-04-20 17:27:12 +02:00 committed by GitHub
parent 8b90b2d0fd
commit 4ddd7e562d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 379 additions and 325 deletions

View File

@ -43,8 +43,7 @@ if (BUILD_TESTS)
# TODO: get rid of the copy # TODO: get rid of the copy
add_custom_target(checkcfg ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cppcheck> ${CMAKE_SOURCE_DIR} add_custom_target(checkcfg ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cppcheck> ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cfg/runtests.sh COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cfg/runtests.sh
DEPENDS cppcheck validateCFG DEPENDS cppcheck validateCFG)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cfg)
endif() endif()
if (REGISTER_TESTS) if (REGISTER_TESTS)

View File

@ -2,16 +2,19 @@
set -e # abort on error set -e # abort on error
#set -x # be verbose #set -x # be verbose
if [[ $(pwd) == */test/cfg ]] ; then # we are in test/cfg echo "Checking for pkg-config..."
CPPCHECK="../../cppcheck" if pkg-config --version; then
DIR="" HAS_PKG_CONFIG=1
CFG="../../cfg/" echo "pkg-config found."
else # assume we are in repo root else
CPPCHECK="./cppcheck" HAS_PKG_CONFIG=0
DIR=test/cfg/ echo "pkg-config is not available, skipping all syntax checks."
CFG="cfg/"
fi fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/
CPPCHECK="$DIR"../../cppcheck
CFG="$DIR"../../cfg
# Cppcheck options # Cppcheck options
CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitcode=-1 --suppress=missingIncludeSystem --inline-suppr --template="{file}:{line}:{severity}:{id}:{message}"' CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitcode=-1 --suppress=missingIncludeSystem --inline-suppr --template="{file}:{line}:{severity}:{id}:{message}"'
@ -21,401 +24,455 @@ CXX_OPT='-fsyntax-only -std=c++0x -Wno-format -Wno-format-security -Wno-deprecat
CC=gcc CC=gcc
CC_OPT='-Wno-format -Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -Wno-nonnull -fsyntax-only' CC_OPT='-Wno-format -Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -Wno-nonnull -fsyntax-only'
function get_pkg_config_cflags {
set +e
PKGCONFIG=$(pkg-config --cflags $1)
PKGCONFIG_RETURNCODE=$?
set -e
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
PKGCONFIG=
else
# make sure the config is not empty when no flags were found - happens with e.g. libssl and sqlite3
if [ -z "$PKGCONFIG" ]; then
PKGCONFIG=" "
fi
fi
echo "$PKGCONFIG"
}
# posix.c # posix.c
${CC} ${CC_OPT} ${DIR}posix.c function posix_fn {
${CPPCHECK} ${CPPCHECK_OPT} --library=posix ${DIR}posix.c ${CC} ${CC_OPT} ${DIR}posix.c
}
# gnu.c # gnu.c
${CC} ${CC_OPT} -D_GNU_SOURCE ${DIR}gnu.c function gnu_fn {
${CPPCHECK} ${CPPCHECK_OPT} --library=posix,gnu ${DIR}gnu.c ${CC} ${CC_OPT} -D_GNU_SOURCE ${DIR}gnu.c
}
# qt.cpp # qt.cpp
set +e function qt_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? QTCONFIG=$(get_pkg_config_cflags Qt5Core)
set -e if [ -n "$QTCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt5Core)
echo "pkg-config needed to retrieve Qt configuration is not available, skipping syntax check." [[ $QTBUILDCONFIG =~ (^|[[:space:]])reduce_relocations($|[[:space:]]) ]] && QTCONFIG="${QTCONFIG} -fPIC"
else set +e
set +e echo -e "#include <QString>" | ${CXX} ${CXX_OPT} ${QTCONFIG} -x c++ -
QTCONFIG=$(pkg-config --cflags Qt5Core) QTCHECK_RETURNCODE=$?
QTCONFIG_RETURNCODE=$? set -e
set -e if [ $QTCHECK_RETURNCODE -ne 0 ]; then
if [ $QTCONFIG_RETURNCODE -eq 0 ]; then echo "Qt not completely present or not working, skipping syntax check with ${CXX}."
QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt5Core) else
[[ $QTBUILDCONFIG =~ (^|[[:space:]])reduce_relocations($|[[:space:]]) ]] && QTCONFIG="${QTCONFIG} -fPIC" echo "Qt found and working, checking syntax with ${CXX} now."
set +e ${CXX} ${CXX_OPT} ${QTCONFIG} ${DIR}qt.cpp
echo -e "#include <QString>" | ${CXX} ${CXX_OPT} ${QTCONFIG} -x c++ - fi
QTCHECK_RETURNCODE=$?
set -e
if [ $QTCHECK_RETURNCODE -ne 0 ]; then
echo "Qt not completely present or not working, skipping syntax check with ${CXX}."
else else
echo "Qt found and working, checking syntax with ${CXX} now." echo "Qt not present, skipping syntax check with ${CXX}."
${CXX} ${CXX_OPT} ${QTCONFIG} ${DIR}qt.cpp
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=qt ${DIR}qt.cpp
# bsd.c # bsd.c
${CPPCHECK} ${CPPCHECK_OPT} --library=bsd ${DIR}bsd.c function bsd_fn {
true
}
# std.c # std.c
${CC} ${CC_OPT} ${DIR}std.c function std_c_fn {
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive ${DIR}std.c ${CC} ${CC_OPT} ${DIR}std.c
${CXX} ${CXX_OPT} ${DIR}std.cpp }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive ${DIR}std.cpp
# std.cpp
function std_cpp_fn {
${CXX} ${CXX_OPT} ${DIR}std.cpp
}
# windows.cpp # windows.cpp
# Syntax check via g++ does not work because it can not find a valid windows.h function windows_fn {
#${CXX} ${CXX_OPT} ${DIR}windows.cpp # TODO: Syntax check via g++ does not work because it can not find a valid windows.h
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32A --library=windows ${DIR}windows.cpp #${CXX} ${CXX_OPT} ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32W --library=windows ${DIR}windows.cpp true
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win64 --library=windows ${DIR}windows.cpp }
# wxwidgets.cpp # wxwidgets.cpp
set +e function wxwidgets_fn {
WXCONFIG=$(wx-config --cxxflags)
WXCONFIG_RETURNCODE=$?
set -e
if [ $WXCONFIG_RETURNCODE -ne 0 ]; then
echo "wx-config does not work, skipping syntax check for wxWidgets tests."
else
set +e set +e
echo -e "#include <wx/filefn.h>\n#include <wx/app.h>\n#include <wx/artprov.h>\n#include <wx/version.h>\n#if wxVERSION_NUMBER<2950\n#error \"Old version\"\n#endif" | ${CXX} ${CXX_OPT} ${WXCONFIG} -x c++ - WXCONFIG=$(wx-config --cxxflags)
WXCHECK_RETURNCODE=$? WXCONFIG_RETURNCODE=$?
set -e set -e
if [ $WXCHECK_RETURNCODE -ne 0 ]; then if [ $WXCONFIG_RETURNCODE -ne 0 ]; then
echo "wxWidgets not completely present (with GUI classes) or not working, skipping syntax check with ${CXX}." echo "wx-config does not work, skipping syntax check for wxWidgets tests."
else else
echo "wxWidgets found, checking syntax with ${CXX} now." set +e
${CXX} ${CXX_OPT} ${WXCONFIG} -Wno-deprecated-declarations ${DIR}wxwidgets.cpp echo -e "#include <wx/filefn.h>\n#include <wx/app.h>\n#include <wx/artprov.h>\n#include <wx/version.h>\n#if wxVERSION_NUMBER<2950\n#error \"Old version\"\n#endif" | ${CXX} ${CXX_OPT} ${WXCONFIG} -x c++ -
WXCHECK_RETURNCODE=$?
set -e
if [ $WXCHECK_RETURNCODE -ne 0 ]; then
echo "wxWidgets not completely present (with GUI classes) or not working, skipping syntax check with ${CXX}."
else
echo "wxWidgets found, checking syntax with ${CXX} now."
${CXX} ${CXX_OPT} ${WXCONFIG} -Wno-deprecated-declarations ${DIR}wxwidgets.cpp
fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=wxwidgets,windows -f ${DIR}wxwidgets.cpp
# gtk.c # gtk.c
set +e function gtk_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? GTKCONFIG=$(get_pkg_config_cflags gtk+-3.0)
set -e if [ -z "$GTKCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then GTKCONFIG=$(get_pkg_config_cflags gtk+-2.0)
echo "pkg-config needed to retrieve GTK+ configuration is not available, skipping syntax check." fi
else if [ -n "$GTKCONFIG" ]; then
set +e set +e
GTKCONFIG=$(pkg-config --cflags gtk+-3.0) echo -e "#include <gtk/gtk.h>" | ${CC} ${CC_OPT} ${GTKCONFIG} -x c -
GTKCONFIG_RETURNCODE=$? GTKCHECK_RETURNCODE=$?
set -e set -e
if [ $GTKCONFIG_RETURNCODE -ne 0 ]; then if [ $GTKCHECK_RETURNCODE -ne 0 ]; then
set +e echo "GTK+ not completely present or not working, skipping syntax check with ${CXX}."
GTKCONFIG=$(pkg-config --cflags gtk+-2.0) else
GTKCONFIG_RETURNCODE=$? echo "GTK+ found and working, checking syntax with ${CXX} now."
set -e ${CC} ${CC_OPT} ${GTKCONFIG} ${DIR}gtk.c
fi fi
if [ $GTKCONFIG_RETURNCODE -eq 0 ]; then
set +e
echo -e "#include <gtk/gtk.h>" | ${CC} ${CC_OPT} ${GTKCONFIG} -x c -
GTKCHECK_RETURNCODE=$?
set -e
if [ $GTKCHECK_RETURNCODE -ne 0 ]; then
echo "GTK+ not completely present or not working, skipping syntax check with ${CXX}."
else else
echo "GTK+ found and working, checking syntax with ${CXX} now." echo "GTK+ not present, skipping syntax check with ${CXX}."
${CC} ${CC_OPT} ${GTKCONFIG} ${DIR}gtk.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=gtk -f ${DIR}gtk.c
# boost.cpp # boost.cpp
set +e function boost_fn {
echo -e "#include <boost/config.hpp>" | ${CXX} ${CXX_OPT} -x c++ - set +e
BOOSTCHECK_RETURNCODE=$? echo -e "#include <boost/config.hpp>" | ${CXX} ${CXX_OPT} -x c++ -
set -e BOOSTCHECK_RETURNCODE=$?
if [ ${BOOSTCHECK_RETURNCODE} -ne 0 ]; then set -e
echo "Boost not completely present or not working, skipping syntax check with ${CXX}." if [ ${BOOSTCHECK_RETURNCODE} -ne 0 ]; then
else echo "Boost not completely present or not working, skipping syntax check with ${CXX}."
echo "Boost found and working, checking syntax with ${CXX} now." else
${CXX} ${CXX_OPT} ${DIR}boost.cpp echo "Boost found and working, checking syntax with ${CXX} now."
fi ${CXX} ${CXX_OPT} ${DIR}boost.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=boost ${DIR}boost.cpp fi
}
# sqlite3.c # sqlite3.c
set +e function sqlite3_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? SQLITE3CONFIG=$(get_pkg_config_cflags sqlite3)
set -e if [ -n "$SQLITE3CONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve SQLite3 configuration is not available, skipping syntax check." echo -e "#include <sqlite3.h>" | ${CC} ${CC_OPT} ${SQLITE3CONFIG} -x c -
else SQLITE3CHECK_RETURNCODE=$?
set +e set -e
SQLITE3CONFIG=$(pkg-config --cflags sqlite3) if [ $SQLITE3CHECK_RETURNCODE -ne 0 ]; then
SQLITE3CONFIG_RETURNCODE=$? echo "SQLite3 not completely present or not working, skipping syntax check with ${CC}."
set -e else
if [ $SQLITE3CONFIG_RETURNCODE -eq 0 ]; then echo "SQLite3 found and working, checking syntax with ${CC} now."
set +e ${CC} ${CC_OPT} ${SQLITE3CONFIG} ${DIR}sqlite3.c
echo -e "#include <sqlite3.h>" | ${CC} ${CC_OPT} ${SQLITE3CONFIG} -x c - fi
SQLITE3CHECK_RETURNCODE=$?
set -e
if [ $SQLITE3CHECK_RETURNCODE -ne 0 ]; then
echo "SQLite3 not completely present or not working, skipping syntax check with ${CC}."
else else
echo "SQLite3 found and working, checking syntax with ${CC} now." echo "SQLite3 not present, skipping syntax check with ${CC}."
${CC} ${CC_OPT} ${SQLITE3CONFIG} ${DIR}sqlite3.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=sqlite3 ${DIR}sqlite3.c
# openmp.c # openmp.c
${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c function openmp_fn {
${CPPCHECK} ${CPPCHECK_OPT} --library=openmp ${DIR}openmp.c ${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c
}
# python.c # python.c
set +e function python_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? PYTHON3CONFIG=$(get_pkg_config_cflags python3)
set -e if [ -n "$PYTHON3CONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve Python 3 configuration is not available, skipping syntax check." echo -e "#include <Python.h>" | ${CC} ${CC_OPT} ${PYTHON3CONFIG} -x c -
else PYTHON3CONFIG_RETURNCODE=$?
set +e set -e
PYTHON3CONFIG=$(pkg-config --cflags python3) if [ $PYTHON3CONFIG_RETURNCODE -ne 0 ]; then
PYTHON3CONFIG_RETURNCODE=$? echo "Python 3 not completely present or not working, skipping syntax check with ${CC}."
set -e else
if [ $PYTHON3CONFIG_RETURNCODE -eq 0 ]; then echo "Python 3 found and working, checking syntax with ${CC} now."
set +e ${CC} ${CC_OPT} ${PYTHON3CONFIG} ${DIR}python.c
echo -e "#include <Python.h>" | ${CC} ${CC_OPT} ${PYTHON3CONFIG} -x c - fi
PYTHON3CONFIG_RETURNCODE=$?
set -e
if [ $PYTHON3CONFIG_RETURNCODE -ne 0 ]; then
echo "Python 3 not completely present or not working, skipping syntax check with ${CC}."
else else
echo "Python 3 found and working, checking syntax with ${CC} now." echo "Python 3 not present, skipping syntax check with ${CC}."
${CC} ${CC_OPT} ${PYTHON3CONFIG} ${DIR}python.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=python ${DIR}python.c
# lua.c # lua.c
set +e function lua_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? LUACONFIG=$(get_pkg_config_cflags lua-5.3)
set -e if [ -n "$LUACONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve Lua configuration is not available, skipping syntax check." echo -e "#include <lua.h>" | ${CC} ${CC_OPT} ${LUACONFIG} -x c -
else LUACONFIG_RETURNCODE=$?
set +e set -e
LUACONFIG=$(pkg-config --cflags lua-5.3) if [ $LUACONFIG_RETURNCODE -ne 0 ]; then
LUACONFIG_RETURNCODE=$? echo "Lua not completely present or not working, skipping syntax check with ${CC}."
set -e else
if [ $LUACONFIG_RETURNCODE -eq 0 ]; then echo "Lua found and working, checking syntax with ${CC} now."
set +e ${CC} ${CC_OPT} ${LUACONFIG} ${DIR}lua.c
echo -e "#include <lua.h>" | ${CC} ${CC_OPT} ${LUACONFIG} -x c - fi
LUACONFIG_RETURNCODE=$?
set -e
if [ $LUACONFIG_RETURNCODE -ne 0 ]; then
echo "Lua not completely present or not working, skipping syntax check with ${CC}."
else else
echo "Lua found and working, checking syntax with ${CC} now." echo "Lua not present, skipping syntax check with ${CC}."
${CC} ${CC_OPT} ${LUACONFIG} ${DIR}lua.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=lua ${DIR}lua.c
# libcurl.c # libcurl.c
set +e function libcurl_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? LIBCURLCONFIG=$(get_pkg_config_cflags libcurl)
set -e if [ -n "$LIBCURLCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve libcurl configuration is not available, skipping syntax check." echo -e "#include <curl/curl.h>" | ${CC} ${CC_OPT} ${LIBCURLCONFIG} -x c -
else LIBCURLCONFIG_RETURNCODE=$?
set +e set -e
LIBCURLCONFIG=$(pkg-config --cflags libcurl) if [ $LIBCURLCONFIG_RETURNCODE -ne 0 ]; then
LIBCURLCONFIG_RETURNCODE=$? echo "libcurl not completely present or not working, skipping syntax check with ${CC}."
set -e else
if [ $LIBCURLCONFIG_RETURNCODE -eq 0 ]; then echo "libcurl found and working, checking syntax with ${CC} now."
set +e ${CC} ${CC_OPT} ${LIBCURLCONFIG} ${DIR}libcurl.c
echo -e "#include <curl/curl.h>" | ${CC} ${CC_OPT} ${LIBCURLCONFIG} -x c - fi
LIBCURLCONFIG_RETURNCODE=$?
set -e
if [ $LIBCURLCONFIG_RETURNCODE -ne 0 ]; then
echo "libcurl not completely present or not working, skipping syntax check with ${CC}."
else else
echo "libcurl found and working, checking syntax with ${CC} now." echo "libcurl not present, skipping syntax check with ${CC}."
${CC} ${CC_OPT} ${LIBCURLCONFIG} ${DIR}libcurl.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=libcurl ${DIR}libcurl.c
# cairo.c # cairo.c
set +e function cairo_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? CAIROCONFIG=$(get_pkg_config_cflags cairo)
set -e if [ -n "$CAIROCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve cairo configuration is not available, skipping syntax check." echo -e "#include <cairo.h>" | ${CC} ${CC_OPT} ${CAIROCONFIG} -x c -
else CAIROCONFIG_RETURNCODE=$?
set +e set -e
CAIROCONFIG=$(pkg-config --cflags cairo) if [ $CAIROCONFIG_RETURNCODE -ne 0 ]; then
CAIROCONFIG_RETURNCODE=$? echo "cairo not completely present or not working, skipping syntax check with ${CC}."
set -e else
if [ $CAIROCONFIG_RETURNCODE -eq 0 ]; then echo "cairo found and working, checking syntax with ${CC} now."
set +e ${CC} ${CC_OPT} ${CAIROCONFIG} ${DIR}cairo.c
echo -e "#include <cairo.h>" | ${CC} ${CC_OPT} ${CAIROCONFIG} -x c - fi
CAIROCONFIG_RETURNCODE=$?
set -e
if [ $CAIROCONFIG_RETURNCODE -ne 0 ]; then
echo "cairo not completely present or not working, skipping syntax check with ${CC}."
else else
echo "cairo found and working, checking syntax with ${CC} now." echo "cairo not present, skipping syntax check with ${CC}."
${CC} ${CC_OPT} ${CAIROCONFIG} ${DIR}cairo.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=cairo ${DIR}cairo.c
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=googletest ${DIR}googletest.cpp # googletest.cpp
function googletest_fn {
true
}
# kde.cpp # kde.cpp
set +e function kde_fn {
KDECONFIG=$(kde4-config --path include)
KDECONFIG_RETURNCODE=$?
set -e
if [ $KDECONFIG_RETURNCODE -ne 0 ]; then
echo "kde4-config does not work, skipping syntax check."
else
set +e set +e
KDEQTCONFIG=$(pkg-config --cflags QtCore) KDECONFIG=$(kde4-config --path include)
KDEQTCONFIG_RETURNCODE=$? KDECONFIG_RETURNCODE=$?
set -e set -e
if [ $KDEQTCONFIG_RETURNCODE -ne 0 ]; then if [ $KDECONFIG_RETURNCODE -ne 0 ]; then
echo "Suitable Qt not present, Qt is necessary for KDE. Skipping syntax check." echo "kde4-config does not work, skipping syntax check."
else else
set +e KDEQTCONFIG=$(get_pkg_config_cflags QtCore)
echo -e "#include <KDE/KGlobal>\n" | ${CXX} ${CXX_OPT} -I${KDECONFIG} ${KDEQTCONFIG} -x c++ - if [ -n "$KDEQTCONFIG" ]; then
KDECHECK_RETURNCODE=$? echo "Suitable Qt not present, Qt is necessary for KDE. Skipping syntax check."
set -e
if [ $KDECHECK_RETURNCODE -ne 0 ]; then
echo "KDE headers not completely present or not working, skipping syntax check with ${CXX}."
else else
echo "KDE found, checking syntax with ${CXX} now." set +e
${CXX} ${CXX_OPT} -I${KDECONFIG} ${KDEQTCONFIG} ${DIR}kde.cpp echo -e "#include <KDE/KGlobal>\n" | ${CXX} ${CXX_OPT} -I${KDECONFIG} ${KDEQTCONFIG} -x c++ -
KDECHECK_RETURNCODE=$?
set -e
if [ $KDECHECK_RETURNCODE -ne 0 ]; then
echo "KDE headers not completely present or not working, skipping syntax check with ${CXX}."
else
echo "KDE found, checking syntax with ${CXX} now."
${CXX} ${CXX_OPT} -I${KDECONFIG} ${KDEQTCONFIG} ${DIR}kde.cpp
fi
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=kde ${DIR}kde.cpp
# libsigc++.cpp # libsigc++.cpp
set +e function libsigcpp_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? LIBSIGCPPCONFIG=$(get_pkg_config_cflags sigc++-2.0)
set -e if [ -n "$LIBSIGCPPCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve libsigc++ configuration is not available, skipping syntax check." echo -e "#include <sigc++/sigc++.h>\n" | ${CXX} ${CXX_OPT} ${LIBSIGCPPCONFIG} -x c++ -
else LIBSIGCPPCONFIG_RETURNCODE=$?
set +e set -e
LIBSIGCPPCONFIG=$(pkg-config --cflags sigc++-2.0) if [ $LIBSIGCPPCONFIG_RETURNCODE -ne 0 ]; then
LIBSIGCPPCONFIG_RETURNCODE=$? echo "libsigc++ not completely present or not working, skipping syntax check with ${CXX}."
set -e else
if [ $LIBSIGCPPCONFIG_RETURNCODE -eq 0 ]; then echo "libsigc++ found and working, checking syntax with ${CXX} now."
set +e ${CXX} ${CXX_OPT} ${LIBSIGCPPCONFIG} ${DIR}libsigc++.cpp
echo -e "#include <sigc++/sigc++.h>\n" | ${CXX} ${CXX_OPT} ${LIBSIGCPPCONFIG} -x c++ - fi
LIBSIGCPPCONFIG_RETURNCODE=$?
set -e
if [ $LIBSIGCPPCONFIG_RETURNCODE -ne 0 ]; then
echo "libsigc++ not completely present or not working, skipping syntax check with ${CXX}."
else else
echo "libsigc++ found and working, checking syntax with ${CXX} now." echo "libsigc++ not present, skipping syntax check with ${CXX}."
${CXX} ${CXX_OPT} ${LIBSIGCPPCONFIG} ${DIR}libsigc++.cpp
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=libsigc++ ${DIR}libsigc++.cpp
# openssl.c # openssl.c
set +e function openssl_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? OPENSSLCONFIG=$(get_pkg_config_cflags libssl)
set -e if [ -n "$OPENSSLCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve OpenSSL configuration is not available, skipping syntax check." echo -e "#include <openssl/ssl.h>" | ${CC} ${CC_OPT} ${OPENSSLCONFIG} -x c -
else OPENSSLCONFIG_RETURNCODE=$?
set +e set -e
OPENSSLCONFIG=$(pkg-config --cflags libssl) if [ $OPENSSLCONFIG_RETURNCODE -ne 0 ]; then
OPENSSLCONFIG_RETURNCODE=$? echo "OpenSSL not completely present or not working, skipping syntax check with ${CC}."
set -e else
if [ $OPENSSLCONFIG_RETURNCODE -eq 0 ]; then echo "OpenSSL found and working, checking syntax with ${CC} now."
set +e ${CC} ${CC_OPT} ${OPENSSLCONFIG} ${DIR}openssl.c
echo -e "#include <openssl/ssl.h>" | ${CC} ${CC_OPT} ${OPENSSLCONFIG} -x c - fi
OPENSSLCONFIG_RETURNCODE=$?
set -e
if [ $OPENSSLCONFIG_RETURNCODE -ne 0 ]; then
echo "OpenSSL not completely present or not working, skipping syntax check with ${CC}."
else else
echo "OpenSSL found and working, checking syntax with ${CC} now." echo "OpenSSL not present, skipping syntax check with ${CC}."
${CC} ${CC_OPT} ${OPENSSLCONFIG} ${DIR}openssl.c
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=openssl ${DIR}openssl.c
# opencv2.cpp # opencv2.cpp
set +e function opencv2_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? OPENCVCONFIG=$(get_pkg_config_cflags opencv)
set -e if [ -n "$OPENCVCONFIG" ]; then
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then set +e
echo "pkg-config needed to retrieve OpenCV configuration is not available, skipping syntax check." echo -e "#include <opencv2/opencv.hpp>\n" | ${CXX} ${CXX_OPT} ${OPENCVCONFIG} -x c++ -
else OPENCVCONFIG_RETURNCODE=$?
set +e set -e
OPENCVCONFIG=$(pkg-config --cflags opencv) if [ $OPENCVCONFIG_RETURNCODE -ne 0 ]; then
OPENCVCONFIG_RETURNCODE=$? echo "OpenCV not completely present or not working, skipping syntax check with ${CXX}."
set -e else
if [ $OPENCVCONFIG_RETURNCODE -eq 0 ]; then echo "OpenCV found and working, checking syntax with ${CXX} now."
set +e ${CXX} ${CXX_OPT} ${OPENCVCONFIG} ${DIR}opencv2.cpp
echo -e "#include <opencv2/opencv.hpp>\n" | ${CXX} ${CXX_OPT} ${OPENCVCONFIG} -x c++ - fi
OPENCVCONFIG_RETURNCODE=$?
set -e
if [ $OPENCVCONFIG_RETURNCODE -ne 0 ]; then
echo "OpenCV not completely present or not working, skipping syntax check with ${CXX}."
else else
echo "OpenCV found and working, checking syntax with ${CXX} now." echo "OpenCV not present, skipping syntax check with ${CXX}."
${CXX} ${CXX_OPT} ${OPENCVCONFIG} ${DIR}opencv2.cpp
fi fi
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --library=opencv2 ${DIR}opencv2.cpp
# cppunit.cpp # cppunit.cpp
set +e function cppunit_fn {
pkg-config --version if [ $HAS_PKG_CONFIG -eq 1 ]; then
PKGCONFIG_RETURNCODE=$? if ! pkg-config cppunit; then
set -e echo "cppunit not found, skipping syntax check for cppunit"
else
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then echo "cppunit found, checking syntax with ${CXX} now."
echo "pkg-config needed to retrieve cppunit configuration is not available, skipping syntax check." ${CXX} ${CXX_OPT} -Wno-deprecated-declarations ${DIR}cppunit.cpp
else fi
if ! pkg-config cppunit; then
echo "cppunit not found, skipping syntax check for cppunit"
else
echo "cppunit found, checking syntax with ${CXX} now."
${CXX} ${CXX_OPT} -Wno-deprecated-declarations ${DIR}cppunit.cpp
fi fi
fi }
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=cppunit -f ${DIR}cppunit.cpp
for f in "${DIR}"*.{c,cpp}
do
f=$(basename $f)
case $f in
boost.cpp)
boost_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=boost ${DIR}boost.cpp
;;
bsd.c)
bsd_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=bsd ${DIR}bsd.c
;;
cairo.c)
cairo_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=cairo ${DIR}cairo.c
;;
cppunit.cpp)
cppunit_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=cppunit -f ${DIR}cppunit.cpp
;;
gnu.c)
gnu_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=posix,gnu ${DIR}gnu.c
;;
googletest.cpp)
googletest_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=googletest ${DIR}googletest.cpp
;;
gtk.c)
gtk_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=gtk -f ${DIR}gtk.c
;;
kde.cpp)
kde_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=kde ${DIR}kde.cpp
;;
libcurl.c)
libcurl_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=libcurl ${DIR}libcurl.c
;;
libsigc++.cpp)
libsigcpp_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=libsigc++ ${DIR}libsigc++.cpp
;;
lua.c)
lua_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=lua ${DIR}lua.c
;;
opencv2.cpp)
opencv2_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=opencv2 ${DIR}opencv2.cpp
;;
openmp.c)
openmp_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=openmp ${DIR}openmp.c
;;
openssl.c)
openssl_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=openssl ${DIR}openssl.c
;;
posix.c)
posix_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=posix ${DIR}posix.c
;;
python.c)
python_fn
${CPPCHECK} ${CPPCHECK_OPT} --library=python ${DIR}python.c
;;
qt.cpp)
qt_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=qt ${DIR}qt.cpp
;;
sqlite3.c)
sqlite3_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=sqlite3 ${DIR}sqlite3.c
;;
std.c)
std_c_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive ${DIR}std.c
;;
std.cpp)
std_cpp_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive ${DIR}std.cpp
;;
windows.cpp)
windows_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32A --library=windows ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32W --library=windows ${DIR}windows.cpp
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win64 --library=windows ${DIR}windows.cpp
;;
wxwidgets.cpp)
wxwidgets_fn
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=wxwidgets,windows -f ${DIR}wxwidgets.cpp
;;
*)
echo "Unhandled file $f"
esac
done
# Check the syntax of the defines in the configuration files # Check the syntax of the defines in the configuration files
set +e if ! xmlstarlet --version; then
xmlstarlet --version
XMLSTARLET_RETURNCODE=$?
set -e
if [ $XMLSTARLET_RETURNCODE -ne 0 ]; then
echo "xmlstarlet needed to extract defines, skipping defines check." echo "xmlstarlet needed to extract defines, skipping defines check."
else else
for configfile in ${CFG}*.cfg; do for configfile in ${CFG}*.cfg; do
@ -423,9 +480,7 @@ else
# Disable debugging output temporarily since there could be many defines # Disable debugging output temporarily since there could be many defines
set +x set +x
# XMLStarlet returns 1 if no elements were found which is no problem here # XMLStarlet returns 1 if no elements were found which is no problem here
set +e EXTRACTED_DEFINES=$(xmlstarlet sel -t -m '//define' -c . -n <$configfile || true)
EXTRACTED_DEFINES=$(xmlstarlet sel -t -m '//define' -c . -n <$configfile)
set -e
EXTRACTED_DEFINES=$(echo "$EXTRACTED_DEFINES" | sed 's/<define name="/#define /g' | sed 's/" value="/ /g' | sed 's/"\/>//g') EXTRACTED_DEFINES=$(echo "$EXTRACTED_DEFINES" | sed 's/<define name="/#define /g' | sed 's/" value="/ /g' | sed 's/"\/>//g')
echo "$EXTRACTED_DEFINES" | gcc -fsyntax-only -xc -Werror - echo "$EXTRACTED_DEFINES" | gcc -fsyntax-only -xc -Werror -
done done