From 7c4995176916697bbc84f854f844b2ead7f5fa0c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 12 Aug 2019 10:27:08 +0200 Subject: Support regenerating all stubs --- scripts/dev/gen_stub.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/dev/gen_stub.php b/scripts/dev/gen_stub.php index 48b89da113..6caffda14d 100755 --- a/scripts/dev/gen_stub.php +++ b/scripts/dev/gen_stub.php @@ -13,20 +13,34 @@ try { exit(1); } -if ($argc < 2) { - die("Usage: php gen_stub.php foobar.stub.php\n"); +if ($argc >= 2) { + // Generate single file. + processStubFile($argv[1]); +} else { + // Regenerate all stub files we can find. + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator('.'), + RecursiveIteratorIterator::LEAVES_ONLY + ); + foreach ($it as $file) { + $pathName = $file->getPathName(); + if (preg_match('/\.stub\.php$/', $pathName)) { + processStubFile($pathName); + } + } } -$stubFile = $argv[1]; -$arginfoFile = str_replace('.stub.php', '', $stubFile) . '_arginfo.h'; +function processStubFile(string $stubFile) { + $arginfoFile = str_replace('.stub.php', '', $stubFile) . '_arginfo.h'; -try { - $funcInfos = parseStubFile($stubFile); - $arginfoCode = generateArgInfoCode($funcInfos); - file_put_contents($arginfoFile, $arginfoCode); -} catch (Exception $e) { - echo "Caught {$e->getMessage()} while processing $stubFile\n"; - exit(1); + try { + $funcInfos = parseStubFile($stubFile); + $arginfoCode = generateArgInfoCode($funcInfos); + file_put_contents($arginfoFile, $arginfoCode); + } catch (Exception $e) { + echo "Caught {$e->getMessage()} while processing $stubFile\n"; + exit(1); + } } class Type { -- cgit v1.2.1