diff options
author | Remi Collet <remi@remirepo.net> | 2020-10-05 15:20:16 +0200 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2020-10-05 15:41:08 +0200 |
commit | dba6715598a94cdf10880a0dc0a1de03e8e4362d (patch) | |
tree | 2da0ab1ce93f9bf41cc30cb6fb62be497a391727 /build | |
parent | 6ea870f5fb94c251cf201fb2955a93ba70edaa89 (diff) | |
download | php-git-dba6715598a94cdf10880a0dc0a1de03e8e4362d.tar.gz |
Improve gen_stub.php - drop --legacy option, generate file is exists - add --help option - add debug "Saved ..." message
Diffstat (limited to 'build')
-rwxr-xr-x | build/gen_stub.php | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/build/gen_stub.php b/build/gen_stub.php index 56106dec90..fba1b0a94e 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -31,8 +31,9 @@ function processStubFile(string $stubFile, Context $context) { throw new Exception("File $stubFile does not exist"); } - $arginfoFile = str_replace('.stub.php', '', $stubFile) - . ($context->legacy ? '_legacy' : '') . '_arginfo.h'; + $arginfoFile = str_replace('.stub.php', '_arginfo.h', $stubFile); + $legacyFile = str_replace('.stub.php', '_legacy_arginfo.h', $stubFile); + $stubCode = file_get_contents($stubFile); $stubHash = computeStubHash($stubCode); $oldStubHash = extractStubHash($arginfoFile); @@ -43,14 +44,20 @@ function processStubFile(string $stubFile, Context $context) { initPhpParser(); $fileInfo = parseStubFile($stubCode); - if ($context->legacy) { + $arginfoCode = generateArgInfoCode($fileInfo, $stubHash); + if (file_put_contents($arginfoFile, $arginfoCode)) { + echo "Saved $arginfoFile\n"; + } + + if (file_exists($legacyFile)) { foreach ($fileInfo->getAllFuncInfos() as $funcInfo) { $funcInfo->discardInfoForOldPhpVersions(); } - } - - $arginfoCode = generateArgInfoCode($fileInfo, $stubHash); - file_put_contents($arginfoFile, $arginfoCode); + $arginfoCode = generateArgInfoCode($fileInfo, $stubHash); + if (file_put_contents($legacyFile, $arginfoCode)) { + echo "Saved $legacyFile\n"; + } + } // Collect parameter name statistics. foreach ($fileInfo->getAllFuncInfos() as $funcInfo) { @@ -1220,14 +1227,17 @@ function initPhpParser() { } $optind = null; -$options = getopt("f", ["force-regeneration", "parameter-stats", "legacy"], $optind); +$options = getopt("fh", ["force-regeneration", "parameter-stats", "help"], $optind); $context = new Context; $printParameterStats = isset($options["parameter-stats"]); -$context->legacy = isset($options["legacy"]); $context->forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]) || $printParameterStats; +if (isset($options["h"]) || isset($options["help"])) { + die("\nusage: gen-stub.php [ -f | --force-regeneration ] [ --parameter-stats ] [ -h | --help ] [ name.stub.php | directory ]\n\n"); +} + $location = $argv[$optind] ?? "."; if (is_file($location)) { // Generate single file. |