1
0

checker-buildbot.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. # Install Clang (you already have it on Mac OS X, apt-get install clang
  6. # on Ubuntu, etc),
  7. # or download checker at http://clang-analyzer.llvm.org/ and unpack it in
  8. # /usr/local ... update CHECKERDIR as appropriate.
  9. FINALDIR="$1"
  10. CHECKERDIR="/usr/local/checker-279"
  11. if [ ! -d "$CHECKERDIR" ]; then
  12. echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
  13. CHECKERDIR="/usr/share/clang/scan-build"
  14. fi
  15. if [ ! -d "$CHECKERDIR" ]; then
  16. echo "$CHECKERDIR not found. Giving up." 1>&2
  17. exit 1
  18. fi
  19. if [ -z "$MAKE" ]; then
  20. OSTYPE=`uname -s`
  21. if [ "$OSTYPE" == "Linux" ]; then
  22. NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
  23. let NCPU=$NCPU+1
  24. elif [ "$OSTYPE" = "Darwin" ]; then
  25. NCPU=`sysctl -n hw.ncpu`
  26. elif [ "$OSTYPE" = "SunOS" ]; then
  27. NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
  28. else
  29. NCPU=1
  30. fi
  31. if [ -z "$NCPU" ]; then
  32. NCPU=1
  33. elif [ "$NCPU" = "0" ]; then
  34. NCPU=1
  35. fi
  36. MAKE="make -j$NCPU"
  37. fi
  38. echo "\$MAKE is '$MAKE'"
  39. set -x
  40. set -e
  41. cd `dirname "$0"`
  42. cd ..
  43. rm -rf checker-buildbot analysis
  44. if [ ! -z "$FINALDIR" ]; then
  45. rm -rf "$FINALDIR"
  46. fi
  47. mkdir checker-buildbot
  48. cd checker-buildbot
  49. # You might want to do this for CMake-backed builds instead...
  50. PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis cmake -DCMAKE_BUILD_TYPE=Debug -DASSERTIONS=enabled ..
  51. # ...or run configure without the scan-build wrapper...
  52. #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure --enable-assertions=enabled
  53. # ...but this works for our buildbots just fine (EXCEPT ON LATEST MAC OS X).
  54. #CFLAGS="-O0" PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis ../configure --enable-assertions=enabled
  55. rm -rf analysis
  56. PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis $MAKE
  57. if [ `ls -A analysis |wc -l` == 0 ] ; then
  58. mkdir analysis/zarro
  59. echo '<html><head><title>Zarro boogs</title></head><body>Static analysis: no issues to report.</body></html>' >analysis/zarro/index.html
  60. fi
  61. mv analysis/* ../analysis
  62. rmdir analysis # Make sure this is empty.
  63. cd ..
  64. chmod -R a+r analysis
  65. chmod -R go-w analysis
  66. find analysis -type d -exec chmod a+x {} \;
  67. if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
  68. if [ ! -z "$FINALDIR" ]; then
  69. mv analysis "$FINALDIR"
  70. else
  71. FINALDIR=analysis
  72. fi
  73. rm -rf checker-buildbot
  74. echo "Done. Final output is in '$FINALDIR' ..."
  75. # end of checker-buildbot.sh ...