checker-buildbot.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # This is a script used by some Buildbot buildslaves to push the project
  3. # through Clang's static analyzer and prepare the output to be uploaded
  4. # back to the buildmaster. You might find it useful too.
  5. # To use: get CMake from http://cmake.org/ or "apt-get install cmake" or whatever.
  6. # And download checker at http://clang-analyzer.llvm.org/ and unpack it in
  7. # /usr/local ... update CHECKERDIR as appropriate.
  8. FINALDIR="$1"
  9. CHECKERDIR="/usr/local/checker-276"
  10. if [ ! -d "$CHECKERDIR" ]; then
  11. echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
  12. CHECKERDIR="/usr/share/clang/scan-build"
  13. fi
  14. if [ ! -d "$CHECKERDIR" ]; then
  15. echo "$CHECKERDIR not found. Giving up." 1>&2
  16. exit 1
  17. fi
  18. if [ -z "$MAKE" ]; then
  19. OSTYPE=`uname -s`
  20. if [ "$OSTYPE" == "Linux" ]; then
  21. NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
  22. let NCPU=$NCPU+1
  23. elif [ "$OSTYPE" = "Darwin" ]; then
  24. NCPU=`sysctl -n hw.ncpu`
  25. elif [ "$OSTYPE" = "SunOS" ]; then
  26. NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
  27. else
  28. NCPU=1
  29. fi
  30. if [ -z "$NCPU" ]; then
  31. NCPU=1
  32. elif [ "$NCPU" = "0" ]; then
  33. NCPU=1
  34. fi
  35. MAKE="make -j$NCPU"
  36. fi
  37. echo "\$MAKE is '$MAKE'"
  38. set -x
  39. set -e
  40. cd `dirname "$0"`
  41. cd ..
  42. rm -rf checker-buildbot analysis
  43. if [ ! -z "$FINALDIR" ]; then
  44. rm -rf "$FINALDIR"
  45. fi
  46. mkdir checker-buildbot
  47. cd checker-buildbot
  48. #cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="$CHECKERDIR/libexec/ccc-analyzer" -DSDL_STATIC=OFF ..
  49. #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure
  50. CFLAGS="-O0" PATH="$CHECKERDIR:$PATH" scan-build -o analysis ../configure
  51. rm -rf analysis
  52. PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
  53. mv analysis/* ../analysis
  54. rmdir analysis # Make sure this is empty.
  55. cd ..
  56. chmod -R a+r analysis
  57. chmod -R go-w analysis
  58. find analysis -type d -exec chmod a+x {} \;
  59. if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
  60. if [ ! -z "$FINALDIR" ]; then
  61. mv analysis "$FINALDIR"
  62. else
  63. FINALDIR=analysis
  64. fi
  65. rm -rf checker-buildbot
  66. echo "Done. Final output is in '$FINALDIR' ..."
  67. # end of checker-buildbot.sh ...