checker-buildbot.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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-276"
  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:$PATH" scan-build -o analysis cmake -DCMAKE_BUILD_TYPE=Debug ..
  51. # ...or run configure without the scan-build wrapper...
  52. #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure
  53. # ...but this works for our buildbots just fine (EXCEPT ON LATEST MAC OS X).
  54. #CFLAGS="-O0" PATH="$CHECKERDIR:$PATH" scan-build -o analysis ../configure
  55. rm -rf analysis
  56. PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
  57. mv analysis/* ../analysis
  58. rmdir analysis # Make sure this is empty.
  59. cd ..
  60. chmod -R a+r analysis
  61. chmod -R go-w analysis
  62. find analysis -type d -exec chmod a+x {} \;
  63. if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
  64. if [ ! -z "$FINALDIR" ]; then
  65. mv analysis "$FINALDIR"
  66. else
  67. FINALDIR=analysis
  68. fi
  69. rm -rf checker-buildbot
  70. echo "Done. Final output is in '$FINALDIR' ..."
  71. # end of checker-buildbot.sh ...