Skip to content

Commit 7e81480

Browse files
committed
Add flag to enable AST functionality, off by default
Closes #75
1 parent 77a1fa7 commit 7e81480

File tree

793 files changed

+1266
-419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

793 files changed

+1266
-419
lines changed

.ci/travis_php.sh

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
export LIBHANDLEBARS_VERSION=${LIBHANDLEBARS_VERSION:-master}
44
#export PHP_PSR_VERSION=${PHP_PSR_VERSION:-master}
5+
export AST=${AST:-false}
56
export COVERAGE=${COVERAGE:-true}
7+
export HARDENING=${HARDENING:-true}
68

79
export NO_INTERACTION=1
810
export REPORT_EXIT_STATUS=1
@@ -62,6 +64,12 @@ function install_php_handlebars() (
6264

6365
local extra_configure_flags=""
6466

67+
if [[ "${AST}" != "false" ]]; then
68+
extra_configure_flags="${extra_configure_flags} --enable-handlebars-ast"
69+
else
70+
extra_configure_flags="${extra_configure_flags} --disable-handlebars-ast"
71+
fi
72+
6573
if [[ "${HARDENING}" != "false" ]]; then
6674
extra_configure_flags="${extra_configure_flags} --enable-handlebars-hardening"
6775
else
@@ -112,6 +120,8 @@ function before_script() (
112120
function run_examples() (
113121
set -e -o pipefail
114122

123+
echo "Running examples"
124+
115125
for i in `find examples -name "*.php" -not -name benchmarks.php`; do
116126
printf "\nExecuting example ${i}:\n"
117127
php -d extension=modules/handlebars.so $i
@@ -120,6 +130,17 @@ function run_examples() (
120130
return 0
121131
)
122132

133+
function run_stubs() {
134+
set -e -o pipefail
135+
136+
echo "Running stubs"
137+
138+
php handlebars.stub.php
139+
php handlebars-ast.stub.php
140+
141+
return 0
142+
}
143+
123144
function script() (
124145
set -e -o pipefail
125146

@@ -133,7 +154,6 @@ function script() (
133154
${extra_flags} \
134155
-d extension=modules/handlebars.so
135156

136-
echo "Running examples"
137157
run_examples
138158

139159
echo "Running benchmarks"

.travis.yml

+25-6
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,43 @@ matrix:
99
fast_finish: true
1010
allow_failures:
1111
- php: 'master'
12-
- php: 'master'
13-
env:
14-
- PHP_PSR_VERSION=v1.0.0
1512
- language: nix
1613
env:
17-
- NIX_CHANNEL=unstable
18-
- NIX_PHP_ATTR=php
14+
- NIX_CHANNEL=unstable
15+
- NIX_PHP_ATTR=php
1916
include:
17+
# basic
2018
- language: php
2119
php: '7.2'
2220
- language: php
2321
php: '7.3'
2422
- language: php
2523
php: '7.4'
24+
- language: php
25+
php: 'master'
26+
# ast
27+
- language: php
28+
php: '7.2'
29+
env:
30+
- AST=true
31+
- language: php
32+
php: '7.3'
33+
env:
34+
- AST=true
2635
- language: php
2736
php: '7.4'
2837
env:
29-
- HARDENING=false
38+
- AST=true
3039
- language: php
3140
php: 'master'
41+
env:
42+
- AST=true
43+
# no hardening
44+
- language: php
45+
php: '7.4'
46+
env:
47+
- HARDENING=false
48+
# psr
3249
- language: php
3350
php: '7.2'
3451
env:
@@ -45,8 +62,10 @@ matrix:
4562
php: 'master'
4663
env:
4764
- PHP_PSR_VERSION=v1.0.0
65+
# fedora
4866
- env:
4967
- DOCKER_IMAGE=fedora31
68+
# nix
5069
- language: nix
5170
env:
5271
- NIX_CHANNEL=20.03

ci.nix

+15-3
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,31 @@ let
3030

3131
generateHandlebarsTestsForPlatform = { pkgs, path, phpAttr, phpHandlebarsSrc }:
3232
pkgs.recurseIntoAttrs {
33-
handlebars = let
33+
# std
34+
std = let
3435
php = pkgs.${phpAttr};
3536
in pkgs.callPackage ./default.nix {
3637
inherit phpHandlebarsSrc;
3738
php = pkgs.${phpAttr};
3839
buildPecl = pkgs.callPackage "${path}/pkgs/build-support/build-pecl.nix" { inherit php; };
40+
astSupport = false;
3941
};
40-
# cross-compile for 32bit
41-
handlebars32bit = let
42+
# i686
43+
i686 = let
4244
php = pkgs.pkgsi686Linux.${phpAttr};
4345
in pkgs.pkgsi686Linux.callPackage ./default.nix {
4446
inherit phpHandlebarsSrc;
4547
buildPecl = pkgs.pkgsi686Linux.callPackage "${path}/pkgs/build-support/build-pecl.nix" { inherit php; };
48+
astSupport = true;
49+
};
50+
# ast
51+
ast = let
52+
php = pkgs.${phpAttr};
53+
in pkgs.callPackage ./default.nix {
54+
inherit phpHandlebarsSrc;
55+
php = pkgs.${phpAttr};
56+
buildPecl = pkgs.callPackage "${path}/pkgs/build-support/build-pecl.nix" { inherit php; };
57+
astSupport = true;
4658
};
4759
};
4860
in

config.m4

+15-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ m4_define(AM_LDFLAGS, [LDFLAGS])
1919
PHP_ARG_ENABLE(handlebars, whether to enable handlebars support,
2020
[ --enable-handlebars Enable handlebars support])
2121

22+
PHP_ARG_ENABLE(handlebars-ast, whether to enable handlebars AST support,
23+
[ --enable-handlebars-ast Enable handlebars AST support], [no], [no])
24+
2225
PHP_ARG_ENABLE(handlebars-psr, whether to enable handlebars PSR support,
2326
[ --enable-handlebars-psr Enable handlebars PSR support], [no], [no])
2427

@@ -113,20 +116,26 @@ if test "$PHP_HANDLEBARS" != "no"; then
113116
PHP_HANDLEBARS_ADD_SOURCES([
114117
src/php_handlebars.c
115118
src/impl.c
116-
src/compiler.c
117119
src/exceptions.c
118-
src/opcode.c
119120
src/options.c
120-
src/parser.c
121-
src/program.c
122121
src/registry.c
123122
src/safe_string.c
124-
src/token.c
125-
src/tokenizer.c
126123
src/utils.c
127124
src/vm.c
128125
src/value.c
129126
])
127+
if test "$PHP_HANDLEBARS_AST" == "yes"; then
128+
AC_DEFINE([PHP_HANDLEBARS_ENABLE_AST], [1], [Whether to enable AST support])
129+
PHP_HANDLEBARS_ADD_SOURCES([
130+
src/compiler.c
131+
src/opcode.c
132+
src/parser.c
133+
src/program.c
134+
src/token.c
135+
src/tokenizer.c
136+
])
137+
fi
138+
130139
PHP_ADD_BUILD_DIR(src)
131140
PHP_ADD_INCLUDE([vendor])
132141
PHP_INSTALL_HEADERS([ext/handlebars], [php_handlebars.h])

default.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
phpHandlebarsSha256 ? null,
2323
phpHandlebarsAllTheTests ? false,
2424

25+
astSupport ? false,
2526
hardeningSupport ? true,
2627

2728
mustache_spec ? pkgs.callPackage (import ((fetchTarball {
@@ -47,6 +48,6 @@
4748

4849
pkgs.callPackage ./derivation.nix {
4950
inherit buildPecl mustache_spec handlebars_spec handlebarsc php_psr phpHandlebarsVersion phpHandlebarsSrc phpHandlebarsSha256 phpHandlebarsAllTheTests;
50-
inherit hardeningSupport;
51+
inherit astSupport hardeningSupport;
5152
}
5253

derivation.nix

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
phpHandlebarsSha256 ? null,
99
phpHandlebarsAllTheTests ? false,
1010

11+
astSupport ? false,
1112
hardeningSupport ? true
1213
}:
1314

@@ -28,6 +29,8 @@ buildPecl rec {
2829
nativeBuildInputs = [ mustache_spec handlebars_spec ];
2930

3031
configureFlags = []
32+
++ lib.optional astSupport "--enable-handlebars-ast"
33+
++ lib.optional (!astSupport) "--disable-handlebars-ast"
3134
++ lib.optional hardeningSupport "--enable-handlebars-hardening"
3235
++ lib.optional (!hardeningSupport) "--disable-handlebars-hardening"
3336
;

generate-tests.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
}
1212
if( !extension_loaded('handlebars') ) {
1313
require 'handlebars.stub.php';
14+
require 'handlebars-ast.stub.php';
1415
}
1516

1617
$startTime = microtime(true);
@@ -234,6 +235,13 @@ function hbs_generate_test_head(array &$test) {
234235
if (!empty($test['number'])) {
235236
$testName .= ' - ' . $test['number'];
236237
}
238+
$extraSkip = '';
239+
240+
if( $test['suiteType'] == 'export' || $test['suiteName'] == 'parser' || $test['suiteName'] == 'tokenizer' ) {
241+
$extraSkip .= <<<EOF
242+
if( !class_exists('Handlebars\\Compiler') ) die('skip handlebars AST not enabled');
243+
EOF;
244+
}
237245

238246
switch( $test['description'] . ' - ' . $test['it'] ) {
239247
case 'Standalone Indentation - Each line of the partial should be indented before rendering.':
@@ -316,10 +324,8 @@ function hbs_generate_test_head(array &$test) {
316324
}
317325
}
318326

319-
$extraSkip = null;
320327
if ($test['suiteType'] === 'mustache' && $test['suiteName'] === 'lambdas') {
321-
$extraSkip = <<<EOF
322-
328+
$extraSkip .= <<<EOF
323329
if( !defined('Handlebars\\Compiler::MUSTACHE_STYLE_LAMBDAS') ) die('skip configured libhandlebars version has no lambda support');
324330
EOF;
325331
}

0 commit comments

Comments
 (0)