jenkins-bot has submitted this change and it was merged.

Change subject: Simplify run-phan.sh by using cloudflare/docker-phan
......................................................................


Simplify run-phan.sh by using cloudflare/docker-phan

Our current solution just felt hacky and had problems with the php7
installations conflicting with the primary php5 installation. Lets just
skip that whole kerfuffle and use a docker container that has phan built
in instead. This container is ~20M and is pretty simple to use. It does
take a few minutes to build the first time around though.

Also adjusts the script to not output random extra data, and instead
output the error given by phan. The exit code is now 0 if everything is
happy, or 1 if there are problems. This makes the script easier to
integrate into cindy for auto-running static analysis.

Change-Id: I9384648d15c5692f3d85f85705bc88ea2aa80b37
---
M scripts/run-phan.sh
1 file changed, 63 insertions(+), 71 deletions(-)

Approvals:
  Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
  DCausse: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/run-phan.sh b/scripts/run-phan.sh
index 6d769dc..a47e182 100755
--- a/scripts/run-phan.sh
+++ b/scripts/run-phan.sh
@@ -1,93 +1,85 @@
 #!/bin/bash
 
-MW_PREFIX="/vagrant/mediawiki"
-PHAN_DIR="/vagrant/srv/phan"
+# Some systems, like mediawiki-vagrant, don't have realpath
+if ! which realpath > /dev/null; then
+       realpath() {
+               php -r "echo realpath('$*');"
+       }
+fi
+
+MW_PREFIX=$(realpath "${MW_PREFIX:-$(dirname "$0")/../../..}")
 CIRRUS="extensions/CirrusSearch/includes/ extensions/CirrusSearch/maintenance/ 
extensions/CirrusSearch/profiles"
 DEPS="extensions/Elastica/ extensions/BetaFeatures includes vendor/ 
maintenance/ languages/ extensions/CirrusSearch/vendor"
-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 \
-          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 \
-          php-redis php-igbinary"
 
 set -e
 
-if [ ! -d /vagrant ]; then
-       echo "This script must be run inside a mediawiki vagrant box"
+if [ ! -f "$MW_PREFIX/includes/MediaWiki.php" ]; then
+       echo "Could not find MediaWiki installation at $MW_PREFIX"
+       echo "Please specify with MW_PREFIX environment variable"
+       echo
        exit 1
 fi
 
-if [ ! -f /etc/apt/sources.list.d/ondrej-php-trusty.list ]; then
-       echo "Adding ppa:ondrej/php which contains php7"
-       # apt has an issue with onrej's name if utf-8 isn't used
-       export LC_ALL=en_US.UTF-8
-       export LANG=en_US.UTF-8
-       sudo add-apt-repository -y ppa:ondrej/php
-fi
-
-for i in $PACKAGES; do
-       PACKAGE_MATCHER="$PACKAGE_MATCHER|^$i\$"
-done
-PACKAGE_MATCHER="${PACKAGE_MATCHER:1}"
-
-if ! dpkg --get-selections | cut -d '  ' -f 1 | egrep "$PACKAGE_MATCHER" > 
/dev/null; then
-       echo "Didn't find all required packages, installing..."
-       sudo apt-get update
-       sudo apt-get install -y $PACKAGES
-fi
-
-if ! which php5 > /dev/null; then
-       # Sadly the php7 packages also require installing a new version of 
php5, and
-       # it doesn't include a BC symlink from php5 -> php5.6. So lets just 
make one
-       sudo ln -s "$(which php5.6)" /usr/local/bin/php5
-fi
-
-if ! dpkg -s php-ast > /dev/null 2>&1; then
-       echo "Installing php-ast extension"
-       sudo apt-get install -y php-ast
-fi
-
-if [ ! -f /etc/php/7.0/cli/conf.d/20-ast.ini ]; then
-       # can't use phpenmod, it will also install a symlink for php5 which 
doesn't work
-       echo "Enabling usage of php-ast in php7"
-       sudo ln -s /etc/php/7.0/mods-available/ast.ini 
/etc/php/7.0/cli/conf.d/20-ast.ini
-fi
-
-if [ ! -d "$PHAN_DIR" ]; then
-       echo "Didn't find phan, cloning"
-       git clone https://github.com/etsy/phan.git "$PHAN_DIR"
-fi
-
-if [ ! -f "$PHAN_DIR/vendor/autoload.php" ]; then
-       echo "Installing phan dependencies"
-       pushd "$PHAN_DIR"
-       php7.0 $(which composer) install
-       popd
-       if [ ! -f "$PHAN_DIR/vendor/autoload.php" ]; then
-               echo "Failed initializing composer for phan"
-               exit 1
+if ! which docker > /dev/null; then
+       echo "Docker not installed. Press any key to install docker or Ctrl-C 
to quit"
+       read -n 1
+       sudo apt-get -y install docker.io 
+       if [ -d /vagrant ]; then
+               # May also be required elsewhere..but not comfortable just 
installing
+               # cgroup-lite to random peoples machines.
+               sudo apt-get -y install cgroup-lite
        fi
 fi
 
-echo "Collecting files to run phan against..."
+if ! id -Gn | grep docker > /dev/null; then
+       sudo adduser $(id -un) docker
+       echo "User added to docker group. You need to log out and log back in 
to continue."
+       echo
+       exit 1
+fi
+
+if ! docker images | grep cloudflare/phan > /dev/null; then
+       git clone https://github.com/cloudflare/docker-phan.git 
/tmp/docker-phan.$$
+       pushd /tmp/docker-phan.$$
+       ./build
+       popd
+       # Once build we can safely remove this repo
+       rm -rf /tmp/docker-phan.$$
+fi
+
 for i in $CIRRUS; do
   ALL_DIRS="$ALL_DIRS $MW_PREFIX/$i"
 done
 for i in $DEPS; do
-  SKIP_ANALYSIS="$SKIP_ANALYSIS,$MW_PREFIX/$i"
+  SKIP_ANALYSIS="$SKIP_ANALYSIS,/mnt/src/$i"
   ALL_DIRS="$ALL_DIRS $MW_PREFIX/$i"
 done
 # Strip leading comma
 SKIP_ANALYSIS="${SKIP_ANALYSIS:1}"
 
-# Build list of files
-echo "Sourcing files from: $ALL_DIRS"
-PHAN_IN=/tmp/phan.in.$$
-find $ALL_DIRS -iname '*.php' > "$PHAN_IN"
-echo "/vagrant/mediawiki/extensions/CirrusSearch/scripts/phan.stubs.php" >> 
"$PHAN_IN"
-# Run phan
-echo "Running phan..."
-echo "Parsing but not analyzing: $SKIP_ANALYSIS"
-echo "Number of files to handle: " $(wc -l < "$PHAN_IN")
-php7.0 "$PHAN_DIR/phan" -f "$PHAN_IN" -3 "$SKIP_ANALYSIS" -o /tmp/phan.out -p
-rm "$PHAN_IN"
-echo
-echo "Done. Results are in /tmp/phan.out"
+PHAN_IN=$MW_PREFIX/phan.in.$$
+SED_PATTERN=$(echo $MW_PREFIX | sed 's/[\/&]/\\&/g')
+find $ALL_DIRS -iname '*.php' | sed "s/${SED_PATTERN}/\/mnt\/src/" > $PHAN_IN
+echo "/mnt/src/extensions/CirrusSearch/scripts/phan.stubs.php" >> $PHAN_IN
+
+docker run \
+       --volume="$MW_PREFIX:/mnt/src" \
+       --rm \
+       --user "$(id -u):$(id -g)" \
+       cloudflare/phan:latest \
+       --file-list "/mnt/src/phan.in.$$" \
+       --exclude-directory-list "$SKIP_ANALYSIS" \
+       --output "php://stdout" \
+       | sed "s/\/mnt\/src/$SED_PATTERN/" \
+       > /tmp/phan.out
+
+
+RETVAL=0
+if [ "$(wc -l < /tmp/phan.out)" -ne 0 ]; then
+       RETVAL=1
+fi
+
+cat /tmp/phan.out
+rm "$PHAN_IN" /tmp/phan.out
+exit $RETVAL
+

-- 
To view, visit https://gerrit.wikimedia.org/r/291355
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9384648d15c5692f3d85f85705bc88ea2aa80b37
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Cindy-the-browser-test-bot <bernhardsone...@gmail.com>
Gerrit-Reviewer: DCausse <dcau...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Gehel <gleder...@wikimedia.org>
Gerrit-Reviewer: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to