Skip to content

Commit dba6715

Browse files
committed
Improve gen_stub.php - drop --legacy option, generate file is exists - add --help option - add debug "Saved ..." message
1 parent 6ea870f commit dba6715

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

build/gen_stub.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ function processStubFile(string $stubFile, Context $context) {
3131
throw new Exception("File $stubFile does not exist");
3232
}
3333

34-
$arginfoFile = str_replace('.stub.php', '', $stubFile)
35-
. ($context->legacy ? '_legacy' : '') . '_arginfo.h';
34+
$arginfoFile = str_replace('.stub.php', '_arginfo.h', $stubFile);
35+
$legacyFile = str_replace('.stub.php', '_legacy_arginfo.h', $stubFile);
36+
3637
$stubCode = file_get_contents($stubFile);
3738
$stubHash = computeStubHash($stubCode);
3839
$oldStubHash = extractStubHash($arginfoFile);
@@ -43,14 +44,20 @@ function processStubFile(string $stubFile, Context $context) {
4344

4445
initPhpParser();
4546
$fileInfo = parseStubFile($stubCode);
46-
if ($context->legacy) {
47+
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
48+
if (file_put_contents($arginfoFile, $arginfoCode)) {
49+
echo "Saved $arginfoFile\n";
50+
}
51+
52+
if (file_exists($legacyFile)) {
4753
foreach ($fileInfo->getAllFuncInfos() as $funcInfo) {
4854
$funcInfo->discardInfoForOldPhpVersions();
4955
}
50-
}
51-
52-
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
53-
file_put_contents($arginfoFile, $arginfoCode);
56+
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
57+
if (file_put_contents($legacyFile, $arginfoCode)) {
58+
echo "Saved $legacyFile\n";
59+
}
60+
}
5461

5562
// Collect parameter name statistics.
5663
foreach ($fileInfo->getAllFuncInfos() as $funcInfo) {
@@ -1220,14 +1227,17 @@ function initPhpParser() {
12201227
}
12211228

12221229
$optind = null;
1223-
$options = getopt("f", ["force-regeneration", "parameter-stats", "legacy"], $optind);
1230+
$options = getopt("fh", ["force-regeneration", "parameter-stats", "help"], $optind);
12241231

12251232
$context = new Context;
12261233
$printParameterStats = isset($options["parameter-stats"]);
1227-
$context->legacy = isset($options["legacy"]);
12281234
$context->forceRegeneration =
12291235
isset($options["f"]) || isset($options["force-regeneration"]) || $printParameterStats;
12301236

1237+
if (isset($options["h"]) || isset($options["help"])) {
1238+
die("\nusage: gen-stub.php [ -f | --force-regeneration ] [ --parameter-stats ] [ -h | --help ] [ name.stub.php | directory ]\n\n");
1239+
}
1240+
12311241
$location = $argv[$optind] ?? ".";
12321242
if (is_file($location)) {
12331243
// Generate single file.

0 commit comments

Comments
 (0)