|
1 | 1 | #!/usr/bin/env bash
|
2 |
| -# php-ast installation and configuration script, taken from Etsy/Phan |
| 2 | +# php-ast installation and configuration script, taken from https://github.com/phan/phan |
| 3 | +# NOTE: You may want to replace all of this with `pecl install ast` or `pecl install ast-0.1.7` |
| 4 | +# in your own scripts to ensure stable versions are installed instead of development versions. |
| 5 | +set -xeu |
| 6 | + |
| 7 | +if [[ "x$TRAVIS" == "x" ]]; then |
| 8 | + echo "This should only be run in travis" |
| 9 | + exit 1 |
| 10 | +fi |
3 | 11 |
|
4 |
| -function build { |
5 |
| - phpize |
6 |
| - ./configure |
7 |
| - make |
8 |
| -} |
| 12 | +# Ensure the build directory exist |
| 13 | +PHP_VERSION_ID=$(php -r "echo PHP_VERSION_ID;") |
| 14 | +PHAN_BUILD_DIR="$HOME/.cache/phan-ast-build" |
| 15 | +EXPECTED_AST_FILE="$PHAN_BUILD_DIR/build/php-ast-$PHP_VERSION_ID.so" |
9 | 16 |
|
10 |
| -function cleanBuild { |
11 |
| - make clean |
12 |
| - build |
13 |
| -} |
| 17 | +[[ -d "$PHAN_BUILD_DIR" ]] || mkdir -p "$PHAN_BUILD_DIR" |
14 | 18 |
|
15 |
| -function install { |
16 |
| - make install |
17 |
| - echo "extension=ast.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini |
18 |
| -} |
| 19 | +cd "$PHAN_BUILD_DIR" |
19 | 20 |
|
20 |
| -# Ensure the build directory exists |
21 |
| -[[ -d "build" ]] || mkdir build |
| 21 | +if [[ ! -e "$EXPECTED_AST_FILE" ]]; then |
| 22 | + echo "No cached extension found. Building..." |
| 23 | + rm -rf php-ast build |
| 24 | + mkdir build |
22 | 25 |
|
23 |
| -# Ensure that the PHP version hasn't changed under us. If it has, we'll have to |
24 |
| -# rebuild the extension. |
25 |
| -if [[ -e "build/phpversion.txt" ]]; then |
26 |
| - if ! diff -q build/phpversion.txt <(php -r "echo PHP_VERSION_ID;"); then |
27 |
| - # Something has changed, so nuke the build/ast directory if it exists. |
28 |
| - echo "New version of PHP detected. Removing build/ast so we can do a fresh build." |
29 |
| - rm -rf build/ast |
30 |
| - fi |
31 |
| -fi |
| 26 | + git clone --depth 1 https://github.com/nikic/php-ast.git php-ast |
32 | 27 |
|
33 |
| -# Ensure that we have a copy of the ast extension source code. |
34 |
| -if [[ ! -e "build/ast/config.m4" ]]; then |
35 |
| - # If build/ast exists, but build/ast/config.m4 doesn't, nuke it and start over. |
36 |
| - [[ ! -d "build/ast" ]] || rm -rf build/ast |
37 |
| - git clone --depth 1 https://github.com/nikic/php-ast.git build/ast |
38 |
| -fi |
| 28 | + pushd php-ast |
| 29 | + # Install the ast extension |
| 30 | + phpize |
| 31 | + ./configure |
| 32 | + make |
39 | 33 |
|
40 |
| -# Install the ast extension |
41 |
| -pushd ./build/ast |
42 |
| - # If we don't have ast.so, we have to build it. |
43 |
| - if [[ ! -e "modules/ast.so" ]]; then |
44 |
| - echo "No cached extension found. Building..." |
45 |
| - build |
46 |
| - else |
47 |
| - # If there are new commits, we need to rebuild the extension. |
48 |
| - git fetch origin master |
49 |
| - newCommits=$(git rev-list HEAD...origin/master --count) |
50 |
| - if [[ "$newCommits" != "0" ]]; then |
51 |
| - echo "New commits found upstream. Updating and rebuilding..." |
52 |
| - git pull origin master |
53 |
| - cleanBuild |
54 |
| - else |
55 |
| - echo "Using cached extension." |
56 |
| - fi |
57 |
| - fi |
| 34 | + cp modules/ast.so "$EXPECTED_AST_FILE" |
| 35 | + popd |
| 36 | +else |
| 37 | + echo "Using cached extension." |
| 38 | +fi |
58 | 39 |
|
59 |
| - # No matter what, we still have to move the .so into place and enable it. |
60 |
| - install |
61 |
| -popd |
| 40 | +php -r 'function_exists("ast\parse_code") || exit("Failed to enable php-ast");' |
62 | 41 |
|
63 |
| -# Note the PHP version for later builds. |
64 |
| -php -r "echo PHP_VERSION_ID;" > build/phpversion.txt |
| 42 | +echo "extension=$EXPECTED_AST_FILE" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini |
65 | 43 |
|
66 | 44 | # Disable xdebug, since we aren't currently gathering code coverage data and
|
67 | 45 | # having xdebug slows down Composer a bit.
|
|
0 commit comments