run-phan.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. MW_PREFIX="/vagrant/mediawiki"
  3. PHAN_DIR="/vagrant/srv/phan"
  4. CIRRUS="extensions/CirrusSearch/includes/ extensions/CirrusSearch/maintenance/ extensions/CirrusSearch/profiles"
  5. DEPS="extensions/Elastica/ extensions/BetaFeatures includes vendor/ maintenance/ languages/ extensions/CirrusSearch/vendor"
  6. PACKAGES="php7.0-cli php7.0-bz2 php7.0-dev php7.0-json php7.0-mbstring php7.0-curl php7.0-sqlite3 php7.0-xml php7.0-zip php7.0-mysql \
  7. php5.6-cli php5.6-bz2 php5.6-dev php5.6-json php5.6-mbstring php5.6-curl php5.6-sqlite3 php5.6-xml php5.6-zip php5.6-mysql \
  8. php-redis php-igbinary"
  9. set -e
  10. if [ ! -d /vagrant ]; then
  11. echo "This script must be run inside a mediawiki vagrant box"
  12. exit 1
  13. fi
  14. if [ ! -f /etc/apt/sources.list.d/ondrej-php-trusty.list ]; then
  15. echo "Adding ppa:ondrej/php which contains php7"
  16. # apt has an issue with onrej's name if utf-8 isn't used
  17. export LC_ALL=en_US.UTF-8
  18. export LANG=en_US.UTF-8
  19. sudo add-apt-repository -y ppa:ondrej/php
  20. fi
  21. for i in $PACKAGES; do
  22. PACKAGE_MATCHER="$PACKAGE_MATCHER|^$i\$"
  23. done
  24. PACKAGE_MATCHER="${PACKAGE_MATCHER:1}"
  25. if ! dpkg --get-selections | cut -d ' ' -f 1 | egrep "$PACKAGE_MATCHER" > /dev/null; then
  26. echo "Didn't find all required packages, installing..."
  27. sudo apt-get update
  28. sudo apt-get install -y $PACKAGES
  29. fi
  30. if ! which php5 > /dev/null; then
  31. # Sadly the php7 packages also require installing a new version of php5, and
  32. # it doesn't include a BC symlink from php5 -> php5.6. So lets just make one
  33. sudo ln -s "$(which php5.6)" /usr/local/bin/php5
  34. fi
  35. if ! dpkg -s php-ast > /dev/null 2>&1; then
  36. echo "Installing php-ast extension"
  37. sudo apt-get install -y php-ast
  38. fi
  39. if [ ! -f /etc/php/7.0/cli/conf.d/20-ast.ini ]; then
  40. # can't use phpenmod, it will also install a symlink for php5 which doesn't work
  41. echo "Enabling usage of php-ast in php7"
  42. sudo ln -s /etc/php/7.0/mods-available/ast.ini /etc/php/7.0/cli/conf.d/20-ast.ini
  43. fi
  44. if [ ! -d "$PHAN_DIR" ]; then
  45. echo "Didn't find phan, cloning"
  46. git clone https://github.com/etsy/phan.git "$PHAN_DIR"
  47. fi
  48. if [ ! -f "$PHAN_DIR/vendor/autoload.php" ]; then
  49. echo "Installing phan dependencies"
  50. pushd "$PHAN_DIR"
  51. php7.0 $(which composer) install
  52. popd
  53. if [ ! -f "$PHAN_DIR/vendor/autoload.php" ]; then
  54. echo "Failed initializing composer for phan"
  55. exit 1
  56. fi
  57. fi
  58. echo "Collecting files to run phan against..."
  59. for i in $CIRRUS; do
  60. ALL_DIRS="$ALL_DIRS $MW_PREFIX/$i"
  61. done
  62. for i in $DEPS; do
  63. SKIP_ANALYSIS="$SKIP_ANALYSIS,$MW_PREFIX/$i"
  64. ALL_DIRS="$ALL_DIRS $MW_PREFIX/$i"
  65. done
  66. # Strip leading comma
  67. SKIP_ANALYSIS="${SKIP_ANALYSIS:1}"
  68. # Build list of files
  69. echo "Sourcing files from: $ALL_DIRS"
  70. PHAN_IN=/tmp/phan.in.$$
  71. find $ALL_DIRS -iname '*.php' > "$PHAN_IN"
  72. echo "/vagrant/mediawiki/extensions/CirrusSearch/scripts/phan.stubs.php" >> "$PHAN_IN"
  73. # Run phan
  74. echo "Running phan..."
  75. echo "Parsing but not analyzing: $SKIP_ANALYSIS"
  76. echo "Number of files to handle: " $(wc -l < "$PHAN_IN")
  77. php7.0 "$PHAN_DIR/phan" -f "$PHAN_IN" -3 "$SKIP_ANALYSIS" -o /tmp/phan.out -p
  78. rm "$PHAN_IN"
  79. echo
  80. echo "Done. Results are in /tmp/phan.out"