diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.frag | 1 | ||||
-rwxr-xr-x | scripts/dev/bless_tests.php | 171 | ||||
-rwxr-xr-x | scripts/dev/check_parameters.php | 2 | ||||
-rwxr-xr-x | scripts/dev/genfiles | 4 | ||||
-rwxr-xr-x | scripts/dev/search_underscores.php | 2 | ||||
-rw-r--r-- | scripts/dev/tidy.php | 12 | ||||
-rw-r--r-- | scripts/phpize.in | 3 |
7 files changed, 178 insertions, 17 deletions
diff --git a/scripts/Makefile.frag b/scripts/Makefile.frag index bfbac62ab3..1049832145 100644 --- a/scripts/Makefile.frag +++ b/scripts/Makefile.frag @@ -15,6 +15,7 @@ BUILD_FILES = \ build/pkg.m4 \ build/Makefile.global \ build/php.m4 \ + build/gen_stub.php \ run-tests.php BUILD_FILES_EXEC = \ diff --git a/scripts/dev/bless_tests.php b/scripts/dev/bless_tests.php index e28efc9c0d..49160d0cc9 100755 --- a/scripts/dev/bless_tests.php +++ b/scripts/dev/bless_tests.php @@ -19,13 +19,26 @@ foreach ($files as $path) { } $phpt = file_get_contents($path); + $out = file_get_contents($outPath); + if (false !== strpos($phpt, '--XFAIL--')) { // Don't modify expected output of XFAIL tests continue; } - $out = file_get_contents($outPath); - $out = normalizeOutput($out); + // Don't update EXPECTREGEX tests + if (!preg_match('/--EXPECT(F?)--(.*)$/s', $phpt, $matches)) { + continue; + } + + $oldExpect = trim($matches[2]); + $isFormat = $matches[1] == 'F'; + if ($isFormat) { + $out = generateMinimallyDifferingOutput($out, $oldExpect); + } else { + $out = normalizeOutput($out); + } + $phpt = insertOutput($phpt, $out); file_put_contents($path, $phpt); } @@ -62,9 +75,161 @@ function normalizeOutput(string $out): string { return $out; } +function formatToRegex(string $format): string { + $result = preg_quote($format, '/'); + $result = str_replace('%d', '\d+', $result); + $result = str_replace('%s', '[^\r\n]+', $result); + return "/^$result$/s"; +} + +function generateMinimallyDifferingOutput(string $out, string $oldExpect) { + $outLines = explode("\n", $out); + $oldExpectLines = explode("\n", $oldExpect); + $differ = new Differ(function($oldExpect, $new) { + if (strpos($oldExpect, '%') === false) { + return $oldExpect === $new; + } + return preg_match(formatToRegex($oldExpect), $new); + }); + $diff = $differ->diff($oldExpectLines, $outLines); + + $result = []; + foreach ($diff as $elem) { + if ($elem->type == DiffElem::TYPE_KEEP) { + $result[] = $elem->old; + } else if ($elem->type == DiffElem::TYPE_ADD) { + $result[] = normalizeOutput($elem->new); + } + } + return implode("\n", $result); +} + function insertOutput(string $phpt, string $out): string { return preg_replace_callback('/--EXPECTF?--.*$/s', function($matches) use($out) { - $F = strpos($out, '%') !== false ? 'F' : ''; + $hasWildcard = preg_match('/%[resSaAwidxfc]/', $out); + $F = $hasWildcard ? 'F' : ''; return "--EXPECT$F--\n" . $out . "\n"; }, $phpt); } + +/** + * Implementation of the the Myers diff algorithm. + * + * Myers, Eugene W. "An O (ND) difference algorithm and its variations." + * Algorithmica 1.1 (1986): 251-266. + */ + +class DiffElem +{ + const TYPE_KEEP = 0; + const TYPE_REMOVE = 1; + const TYPE_ADD = 2; + + /** @var int One of the TYPE_* constants */ + public $type; + /** @var mixed Is null for add operations */ + public $old; + /** @var mixed Is null for remove operations */ + public $new; + + public function __construct(int $type, $old, $new) { + $this->type = $type; + $this->old = $old; + $this->new = $new; + } +} + +class Differ +{ + private $isEqual; + + /** + * Create differ over the given equality relation. + * + * @param callable $isEqual Equality relation with signature function($a, $b) : bool + */ + public function __construct(callable $isEqual) { + $this->isEqual = $isEqual; + } + + /** + * Calculate diff (edit script) from $old to $new. + * + * @param array $old Original array + * @param array $new New array + * + * @return DiffElem[] Diff (edit script) + */ + public function diff(array $old, array $new) { + list($trace, $x, $y) = $this->calculateTrace($old, $new); + return $this->extractDiff($trace, $x, $y, $old, $new); + } + + private function calculateTrace(array $a, array $b) { + $n = \count($a); + $m = \count($b); + $max = $n + $m; + $v = [1 => 0]; + $trace = []; + for ($d = 0; $d <= $max; $d++) { + $trace[] = $v; + for ($k = -$d; $k <= $d; $k += 2) { + if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) { + $x = $v[$k+1]; + } else { + $x = $v[$k-1] + 1; + } + + $y = $x - $k; + while ($x < $n && $y < $m && ($this->isEqual)($a[$x], $b[$y])) { + $x++; + $y++; + } + + $v[$k] = $x; + if ($x >= $n && $y >= $m) { + return [$trace, $x, $y]; + } + } + } + throw new \Exception('Should not happen'); + } + + private function extractDiff(array $trace, int $x, int $y, array $a, array $b) { + $result = []; + for ($d = \count($trace) - 1; $d >= 0; $d--) { + $v = $trace[$d]; + $k = $x - $y; + + if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) { + $prevK = $k + 1; + } else { + $prevK = $k - 1; + } + + $prevX = $v[$prevK]; + $prevY = $prevX - $prevK; + + while ($x > $prevX && $y > $prevY) { + $result[] = new DiffElem(DiffElem::TYPE_KEEP, $a[$x-1], $b[$y-1]); + $x--; + $y--; + } + + if ($d === 0) { + break; + } + + while ($x > $prevX) { + $result[] = new DiffElem(DiffElem::TYPE_REMOVE, $a[$x-1], null); + $x--; + } + + while ($y > $prevY) { + $result[] = new DiffElem(DiffElem::TYPE_ADD, null, $b[$y-1]); + $y--; + } + } + return array_reverse($result); + } +} diff --git a/scripts/dev/check_parameters.php b/scripts/dev/check_parameters.php index e779d3daee..52424def1e 100755 --- a/scripts/dev/check_parameters.php +++ b/scripts/dev/check_parameters.php @@ -2,8 +2,6 @@ <?php /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | diff --git a/scripts/dev/genfiles b/scripts/dev/genfiles index d29c0d778a..3e085c3e53 100755 --- a/scripts/dev/genfiles +++ b/scripts/dev/genfiles @@ -1,8 +1,6 @@ #!/bin/sh # # +----------------------------------------------------------------------+ -# | PHP Version 7 | -# +----------------------------------------------------------------------+ # | Copyright (c) The PHP Group | # +----------------------------------------------------------------------+ # | This source file is subject to version 3.01 of the PHP license, | @@ -115,7 +113,7 @@ $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=sapi/phpdbg buil sapi/phpdbg/phpdbg_parser.c \ sapi/phpdbg/phpdbg_lexer.c -echo "genfiles: enerating json extension parser and lexer files" +echo "genfiles: Generating json extension parser and lexer files" $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=ext/json builddir=ext/json top_srcdir=. \ -f ext/json/Makefile.frag \ ext/json/json_parser.tab.c \ diff --git a/scripts/dev/search_underscores.php b/scripts/dev/search_underscores.php index ff766bcf1f..bd74ea2af7 100755 --- a/scripts/dev/search_underscores.php +++ b/scripts/dev/search_underscores.php @@ -3,8 +3,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | diff --git a/scripts/dev/tidy.php b/scripts/dev/tidy.php index 267f838a61..3829f9092e 100644 --- a/scripts/dev/tidy.php +++ b/scripts/dev/tidy.php @@ -22,9 +22,11 @@ $excludes = [ 'ext/hash/php_hash_whirlpool_tables.h', 'ext/mbstring/libmbfl/', 'ext/mbstring/unicode_data.h', + 'ext/opcache/jit/dynasm', + 'ext/opcache/jit/libudis86', + 'ext/opcache/jit/vtune', 'ext/pcre/pcre2lib/', 'ext/standard/html_tables/html_table_gen.php', - 'ext/xmlrpc/libxmlrpc/', 'sapi/cli/php_http_parser.c', 'sapi/cli/php_http_parser.h', 'sapi/litespeed/', @@ -62,12 +64,11 @@ foreach ($it as $file) { $code = stripTrailingWhitespace($code); $code = reindentToSpaces($code); } else if ($lang === 'phpt') { - // TODO: Don't reformat .phpt on PHP-7.4. - /*$code = transformTestCode($code, function(string $code) { + $code = transformTestCode($code, function(string $code) { $code = stripTrailingWhitespace($code); $code = reindentToSpaces($code); return $code; - });*/ + }); } if ($origCode !== $code) { @@ -134,8 +135,7 @@ function getLanguageFromExtension(string $ext): ?string { case 're': return 'c'; case 'php': - // TODO: Reformat .inc files. - //case 'inc': + case 'inc': return 'php'; case 'phpt': return 'phpt'; diff --git a/scripts/phpize.in b/scripts/phpize.in index 04864733ae..7d9c1df14c 100644 --- a/scripts/phpize.in +++ b/scripts/phpize.in @@ -9,7 +9,8 @@ includedir="`eval echo @includedir@`/php" builddir="`pwd`" SED="@SED@" -FILES_BUILD="php.m4 shtool libtool.m4 ax_check_compile_flag.m4 ax_gcc_func_attribute.m4 php_cxx_compile_stdcxx.m4 pkg.m4 config.guess config.sub ltmain.sh Makefile.global" +FILES_BUILD="php.m4 shtool libtool.m4 ax_check_compile_flag.m4 ax_gcc_func_attribute.m4 php_cxx_compile_stdcxx.m4 pkg.m4 \ + config.guess config.sub ltmain.sh Makefile.global gen_stub.php" FILES="run-tests*.php" CLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ \ config.nice configure configure.ac \ |