diff --git a/.travis.install.cppcheck b/.travis.install.cppcheck new file mode 100755 index 0000000000000000000000000000000000000000..aa8383441424e692a5b975cedcb06a92ad14513a --- /dev/null +++ b/.travis.install.cppcheck @@ -0,0 +1,23 @@ +#! /bin/bash + +set -e +set -x + + +git clone https://github.com/danmar/cppcheck.git +cd cppcheck + +if [ -n "$1" ] ; then + echo "installing cppcheck $version" + version=$1 +else + echo "installing latest doxygen" + version=$(git tag | tail -n 1) +fi + + +git checkout $tag +sudo make -j 4 install CFGDIR=/usr/share/cppcheck/ +cd ../ + + diff --git a/.travis.yml b/.travis.yml index ff9d7137a5de2fa27faad8d6b1599042cd6a6a81..acc7f5122648cb4960ade0c52de7e1314f8783c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,13 @@ env: - PLUMED_CC=clang PLUMED_CXX=clang++ PLUMED_CXXFLAGS=-O3 LAPACK=yes - PLUMED_CC=gcc PLUMED_CXX=g++ PLUMED_CXXFLAGS=-O3 LAPACK=yes - PLUMED_CC=mpicc PLUMED_CXX=mpic++ PLUMED_CXXFLAGS=-O3 LAPACK=yes +# cppcheck +# in principle we should make only "cppcheck" here +# to avoid to many if's below, I also make a quick test with -O0 here + - PLUMED_CC=gcc PLUMED_CXX=g++ PLUMED_CXXFLAGS=-O0 CPPCHECK=yes +matrix: + allow_failures: + - env: PLUMED_CC=gcc PLUMED_CXX=g++ PLUMED_CXXFLAGS=-O0 CPPCHECK=yes # Possible additional variables: # VALGRIND=yes to make valgrind tests, only when log contains string [valgrind] install: @@ -26,10 +33,11 @@ install: # install some package - these are fast, we install them anyway - sudo apt-get update -qq - sudo apt-get install -y libmatheval-dev -# this is not needed (will be used in 2.2) - ./.travis.install.xdrfile - LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib" - LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" +# cppcheck: + - test "$CPPCHECK" == yes && ./.travis.install.cppcheck 1.69 || true # installation of these packages takes a lot of time # we do it only when needed - test "$PLUMED_CXX" == "mpic++" && sudo apt-get install -y libopenmpi1.5-dev openmpi1.5-bin || true @@ -56,10 +64,12 @@ script: - make -j 2 # we install plumed so that it is in the path - sudo make install +# run static analyzer - test "$VALGRIND" == yes && OPT=valgrind || OPT="" - make -C regtest $OPT - test "$MAKEDOC" == yes && make -C regtest copytodoc || true - test "$MAKEDOC" == yes && make doc >/dev/null || true - make -C regtest checkfail + - if test "$CPPCHECK" == yes ; then make cppcheck ; fi after_success: - test "$MAKEDOC" == yes && ./.travis.pushdoc diff --git a/Makefile b/Makefile index 973ec2e60b8ff71584a755f86be2a89fb14d95a0..6436ff591ac2b577b3dca703aaf99262a13680d6 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ SUBDIRS := $(SRCDIRS) user-doc developer-doc regtest SUBDIRSCLEAN:=$(addsuffix .clean,$(SUBDIRS)) -.PHONY: all lib clean $(SRCDIRS) doc docclean check +.PHONY: all lib clean $(SRCDIRS) doc docclean check cppcheck # if machine dependent configuration has been found: ifdef GCCDEP @@ -67,5 +67,8 @@ docclean: cd user-doc && make clean cd developer-doc && make clean +cppcheck: + $(MAKE) -C src cppcheck + diff --git a/src/Makefile b/src/Makefile index 02c87d7e4da335f550402223ce8d42b118bff978..be1c7bb5ffdc18f1e6830fdfbf1b6d9b4e4a4439 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,13 +20,14 @@ SUBDIRSCLEAN :=$(addsuffix .clean,$(SUBDIRS)) # this is cleaning all subdirectories clean: $(SUBDIRSCLEAN) + rm -f cppcheck.log cppcheck.fatal $(SUBDIRSCLEAN): %.clean: $(MAKE) -C $* clean .PHONY: cppcheck cppcheck: - cppcheck --std=c++03 --std=posix -j 4 --platform=unix64 -q --enable=all --force */*.{h,cpp} + maketools/cppcheck .PHONY: mod-light mod-heavy mod-reset mod-light: diff --git a/src/lib/Makefile b/src/lib/Makefile index 8cef825130226af76caa2a51430ce8149de132f9..a54b9121666196998bda80e91b20ad3b725b7144 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -98,7 +98,7 @@ install-do: # copy inc files changing the path for file in Plumed.inc* Plumed.cmake* ; do sed "s| $(realpath ../../)| $(PLUMED_INSTALL_ROOT)/|g" $$file > $(PLUMED_INSTALL_ROOT)/src/lib/$$file ; done # modulefile - @sed "s|@_PREFIX_@|$(PLUMED_INSTALL_PREFIX)|" modulefile.in | sed "s|@_SOEXT_@|$(SOEXT)|"> $(PLUMED_INSTALL_ROOT)/src/lib/modulefile + @sed "s|@_PREFIX_@|$(PLUMED_INSTALL_PREFIX)|" modulefile.in | sed "s|@_SOEXT_@|$(SOEXT)|" | sed "s|@_SUFFIX_@|$(PLUMED_INSTALL_LIBSUFFIX)|" > $(PLUMED_INSTALL_ROOT)/src/lib/modulefile # install links ln -s $(PLUMED_INSTALL_ROOT)/src/lib/plumed $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX) for file in $(PLUMED_SCRIPTS) ; do ln -s $(PLUMED_INSTALL_ROOT)/src/lib/plumed-$$file $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX)-$$file ; done diff --git a/src/lib/modulefile.in b/src/lib/modulefile.in index 24ca2f3d1e8a6f978ebaffa10b756951b3202d87..51a97665cf78dcf62a78a196e8afec224da9a7bc 100644 --- a/src/lib/modulefile.in +++ b/src/lib/modulefile.in @@ -7,6 +7,9 @@ set prefix "@_PREFIX_@" # this is the extension for dynamic libraries # if set to empty, switches off plumed library set soext "@_SOEXT_@" +# this is the suffix to plumed executable and library +# could be set to plumed version, but is usually blank +set suffix "@_SUFFIX_@" # everything past this line should not need any editing @@ -36,5 +39,5 @@ if { [module-info mode load] && [ info exists ::env(PLUMED_KERNEL) ] } { prepend-path LIBRARY_PATH $prefix/lib/ prepend-path LD_LIBRARY_PATH $prefix/lib/ prepend-path DYLD_LIBRARY_PATH $prefix/lib/ -setenv PLUMED_KERNEL $prefix/lib/libplumedKernel.$soext +setenv PLUMED_KERNEL $prefix/lib/libplumed${suffix}Kernel.$soext } diff --git a/src/maketools/cppcheck b/src/maketools/cppcheck new file mode 100755 index 0000000000000000000000000000000000000000..297f2758efa5be5eddfe2078a1266325dba8f637 --- /dev/null +++ b/src/maketools/cppcheck @@ -0,0 +1,50 @@ +#! /bin/bash + +set -e + +# I use a "tee" here so that errors qre written both immediately (to see progress) +# and on a file (for later report) + +cppcheck --std=c++03 --std=posix -j 4 --platform=unix64 -q \ + --template='[{file}:{line}] ({severity}) :{id}: {message}' --enable=all --inline-suppr --force \ + */*.{h,cpp} 2> >(tee cppcheck.log >&2) + +## this part could be useful to clean the code +# echo "+++++++ THIS IS A COMPLETE LIST OF ERRORS +++++++" +# cat cppcheck.log +# echo "+++++++++++++++++++++++++++++++++++++" +# echo "summary from cppcheck report: +# for t in error warning performance portability style +# do +# echo "$t: $(cat cppcheck.log | grep "($t)" | wc -l)" +# done +# echo "+++++++++++++++++++++++++++++++++++++" + + +## I exclude src/molfile which is full of warnings +## I also exclude (style) messages +## perhaps we could keep some of them to make to code cleaner at some point +## +## (the "true" command is necessary so that the script does not fail if some string is not found) +grep -v "(style)" cppcheck.log | grep -v "\[molfile/" > cppcheck.fatal || true +count=$(cat cppcheck.fatal | wc -l) +echo +echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" +if ((count==0)) +then + echo " cppcheck did not find any fatal error" + echo " (fatal here means: excluding style and excluding molfile/)" +echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + exit 0 +fi + +echo " cppcheck reported the following fatal errors:" +echo " (fatal here means: excluding style and excluding molfile/)" +echo +cat cppcheck.fatal +echo +echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" +echo + +exit 1 +