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