From 85228fd1785ce64faf7420945712f550d1faf8e1 Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Fri, 16 Dec 2016 17:16:04 -0800 Subject: [PATCH] Adjust phan script to run sub-projects Rather than duplicating the phan and postprocess-phan.php scripts into extensions, this allows passing the path to the extension (or skin, or whichever) to the phan script and it will run the analysis for that project. Individual projects will need a tests/phan/config.php file that defines how the analysis will run in their project. Bug: T153040 Change-Id: I58ad44f6a8769088e87d5d6cf1079e633c082f88 --- tests/phan/bin/phan | 51 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/tests/phan/bin/phan b/tests/phan/bin/phan index bed8c69147..5d42cf5914 100755 --- a/tests/phan/bin/phan +++ b/tests/phan/bin/phan @@ -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" -- 2.20.1