Special case opus mime detction
[mediawiki.git] / tests / phan / bin / phan
blobad06823abf79180a541522467ec926612c8627fe
1 #!/bin/bash
3 # mediawiki-vagrant installs dont have realpath by default
4 if ! which realpath > /dev/null; then
5 realpath() {
6 php -r "echo realpath('$*');"
8 fi
10 if hash php7.0 2>/dev/null; then
11 export PHP="php7.0"
12 else
13 export PHP="php"
16 # Note that this isn't loaded in via composer because then composer can
17 # only be run with php7.0
18 if [ ! -f "$PHAN" ]; then
19 # If no PHAN is specified then try to get location from PATH
20 export PHAN="$(which phan)"
21 if [ ! -f "$PHAN" ]; then
22 echo "The environment variable PHAN must point to the 'phan' file"
23 echo "in a checkout of https://github.com/etsy/phan.git"
24 echo "Or phan must be included in your PATH"
25 exit 1
27 else
28 export PHAN="$PHP $PHAN"
31 if [ -z "$MW_INSTALL_PATH" ]; then
32 # Figure out where mediawiki is based on the location of this script
33 pushd "$(dirname "$0")" > /dev/null
34 export MW_INSTALL_PATH="$(git rev-parse --show-toplevel)"
35 popd >/dev/null
38 # If the first argument doesn't start with a -, then it's a path
39 # to another project (extension, skin, etc.) to analyze
40 if [[ -n "$1" && "$1" != "-"* ]]; then
41 cd $1
42 shift
43 else
44 cd "$(dirname "$0")"
47 # Root directory of project
48 export ROOT="$(git rev-parse --show-toplevel)"
50 # Go to the root of this git repo
51 cd "$ROOT"
53 export CONFIG_FILE="$ROOT/tests/phan/config.php"
54 if [ ! -f "$CONFIG_FILE" ]; then
55 echo "Could not find a phan config file to apply in"
56 echo "$CONFIG_FILE"
57 exit 1
60 # Phan's issues directory
61 export ISSUES="${ROOT}/tests/phan/issues"
62 mkdir -p "$ISSUES"
64 # Get the current hash of HEAD
65 export REV="$(git rev-parse HEAD)"
67 # Destination for issues found
68 export RUN="${ISSUES}/issues-${REV}"
71 # Run the analysis, emitting output to the
72 # issues file.
73 $PHAN \
74 --project-root-directory "$ROOT" \
75 --config-file "$CONFIG_FILE" \
76 --output "php://stdout" \
77 "${@}" \
78 | php "$MW_INSTALL_PATH/tests/phan/bin/postprocess-phan.php" "${@}" \
79 > $RUN
81 EXIT_CODE="$?"
83 # Re-link the latest file
84 rm -f "${ISSUES}/latest"
85 ln -s "${RUN}" "${ISSUES}/latest"
87 # Output any issues that were found
88 cat "${RUN}"
90 exit $EXIT_CODE