Merge "Adjust phan script to run sub-projects"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 17 Dec 2016 03:17:06 +0000 (03:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 17 Dec 2016 03:17:06 +0000 (03:17 +0000)
tests/phan/bin/phan

index bed8c69..5d42cf5 100755 (executable)
@@ -1,4 +1,11 @@
-#!/bin/sh
+#!/bin/bash
+
+# mediawiki-vagrant installs dont have realpath by default
+if ! which realpath > /dev/null; then
+       realpath() {
+               php -r "echo realpath('$*');"
+       }
+fi
 
 # Note that this isn't loaded in via composer because then composer can
 # only be run with php7.0
@@ -8,35 +15,57 @@ if [ ! -f "$PHAN" ]; then
        exit 1
 fi
 
-cd "$(dirname "$0")"
+if [ -z "$MW_INSTALL_PATH" ]; then
+       # Figure out where mediawiki is based on the location of this script
+       pushd "$(dirname "$0")" > /dev/null
+       export MW_INSTALL_PATH="$(git rev-parse --show-toplevel)"
+       popd >/dev/null
+fi
+
+# If the first argument doesn't start with a -, then it's a path
+# to another project (extension, skin, etc.) to analyze
+if [[ "$1" != "-"* ]]; then
+       cd $1
+       shift
+else
+       cd "$(dirname "$0")"
+fi
 
 # Root directory of project
 export ROOT="$(git rev-parse --show-toplevel)"
 
-# Phan's issues directory
-export ISSUES="${ROOT}/tests/phan/issues"
-
 # Go to the root of this git repo
 cd "$ROOT"
 
+export CONFIG_FILE="$ROOT/tests/phan/config.php"
+if [ ! -f "$CONFIG_FILE" ]; then
+       echo "Could not find a phan config file to apply in"
+       echo "$CONFIG_FILE"
+       exit 1
+fi
+
+# Phan's issues directory
+export ISSUES="${ROOT}/tests/phan/issues"
+mkdir -p "$ISSUES"
+
 # Get the current hash of HEAD
 export REV="$(git rev-parse HEAD)"
 
 # Destination for issues found
 export RUN="${ISSUES}/issues-${REV}"
 
+
 # Run the analysis, emitting output to the
 # issues file.
 php7.0 $PHAN \
        --project-root-directory "$ROOT" \
-       --config-file "$ROOT/tests/phan/config.php" \
-       --output "$RUN" \
-       "${@}"
-
+       --config-file "$CONFIG_FILE" \
+       --output "php://stdout" \
+       "${@}" \
+       | php "$MW_INSTALL_PATH/tests/phan/bin/postprocess-phan.php" "${@}" \
+       > $RUN
 
-cat "${RUN}" | php "$ROOT/tests/phan/bin/postprocess-phan.php" "${@}" > /tmp/phan.$$
 EXIT_CODE="$?"
-mv /tmp/phan.$$ "${RUN}"
 
 # Re-link the latest file
 rm -f "${ISSUES}/latest"