From 386e3655b3f561d78d6b016086e2f3b048fb1b8e Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 5 Dec 2024 13:31:11 +0000 Subject: [PATCH] Generate files for multiple versions --- composer.json | 6 +++-- generator/src/FileCreator.php | 24 +++++++++++++++++ generator/src/GenerateCommand.php | 45 ++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 18a794bf..91733259 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "generated/ftp.php", "generated/funchand.php", "generated/gettext.php", + "generated/gmp.php", "generated/gnupg.php", "generated/hash.php", "generated/ibase.php", @@ -60,6 +61,7 @@ "generated/mbstring.php", "generated/misc.php", "generated/mysql.php", + "generated/mysqli.php", "generated/network.php", "generated/oci8.php", "generated/opcache.php", @@ -72,7 +74,6 @@ "generated/ps.php", "generated/pspell.php", "generated/readline.php", - "generated/rnp.php", "generated/rpminfo.php", "generated/rrd.php", "generated/sem.php", @@ -98,7 +99,8 @@ "generated/yaml.php", "generated/yaz.php", "generated/zip.php", - "generated/zlib.php" + "generated/zlib.php", + "generated/rnp.php" ] }, "require": { diff --git a/generator/src/FileCreator.php b/generator/src/FileCreator.php index bc90f12e..9c8d6e5f 100644 --- a/generator/src/FileCreator.php +++ b/generator/src/FileCreator.php @@ -28,6 +28,9 @@ public function generatePhpFile(array $functions, string $path): void foreach ($phpFunctionsByModule as $module => $phpFunctions) { $lcModule = \lcfirst($module); + if (!is_dir($path)) { + \mkdir($path); + } $stream = \fopen($path.$lcModule.'.php', 'w'); if ($stream === false) { throw new \RuntimeException('Unable to write to '.$path); @@ -43,6 +46,27 @@ public function generatePhpFile(array $functions, string $path): void } } + /** + * @param string[] $versions + */ + public function generateVersionSplitters(string $module, string $path, array $versions): void + { + $lcModule = \lcfirst($module); + $stream = \fopen($path.$lcModule.'.php', 'w'); + if ($stream === false) { + throw new \RuntimeException('Unable to write to '.$path); + } + \fwrite($stream, "rmGenerated(); // Let's build the DTD necessary to load the XML files. DocPage::buildEntities(); - $scanner = new Scanner(__DIR__ . '/../doc/doc-en/en/reference/'); - $paths = $scanner->getFunctionsPaths(); + $versions = [ + "8.1" => "9097ea48f608dbbbf795235a31af82b85bd94430", + "8.2" => "8f4e8cf3de08208e71eb0117f1c970c27e9120c9", + "8.3" => "7453a50321f0834421cebea8edade14deef5466b", + "8.4" => "d553fa36940639b0889ec4358fa3bbb92f123b69", + "8.5" => "master", + ]; + $modules = []; - $res = $scanner->getMethods($paths); - $functions = $res->methods; - $overloadedFunctions = $res->overloadedFunctions; + foreach ($versions as $version => $commit) { + $process = new Process(['git', "checkout", $commit], __DIR__ . '/../doc/doc-en/en/reference/'); + $process->run(); + $scanner = new Scanner(__DIR__ . '/../doc/doc-en/en/reference/'); - $output->writeln('These functions have been ignored and must be dealt with manually: '.\implode(', ', $overloadedFunctions)); + $paths = $scanner->getFunctionsPaths(); - $fileCreator = new FileCreator(); - $fileCreator->generatePhpFile($functions, __DIR__ . '/../../generated/'); - $fileCreator->generateFunctionsList($functions, __DIR__ . '/../../generated/functionsList.php'); - $fileCreator->generateRectorFile($functions, __DIR__ . '/../../rector-migrate.php'); + $res = $scanner->getMethods($paths); + $functions = $res->methods; + $overloadedFunctions = $res->overloadedFunctions; + $output->writeln('These functions have been ignored and must be dealt with manually: '.\implode(', ', $overloadedFunctions)); - $modules = []; - foreach ($functions as $function) { - $moduleName = $function->getModuleName(); - $modules[$moduleName] = $moduleName; + $fileCreator = new FileCreator(); + $fileCreator->generatePhpFile($functions, __DIR__ . "/../../generated/$version/"); + $fileCreator->generateFunctionsList($functions, __DIR__ . "/../../generated/$version/functionsList.php"); + $fileCreator->generateRectorFile($functions, __DIR__ . "/../../generated/$version/rector-migrate.php"); + + foreach ($functions as $function) { + $moduleName = $function->getModuleName(); + $modules[$moduleName] = $moduleName; + } } foreach ($modules as $moduleName => $foo) { + $fileCreator->generateVersionSplitters($moduleName, __DIR__ . "/../../generated/", array_keys($versions)); $fileCreator->createExceptionFile((string) $moduleName); } $this->runCsFix($output); // Let's require the generated file to check there is no error. - $files = \glob(__DIR__.'/../../generated/*.php'); + $files = \glob(__DIR__."/../../generated/8.1/*.php"); if ($files === false) { throw new \RuntimeException('Failed to require the generated file'); } @@ -91,7 +104,7 @@ private function rmGenerated(): void \unlink($exception); } - $files = \glob(__DIR__.'/../../generated/*.php'); + $files = \glob(__DIR__.'/../../generated/*/*.php'); if ($files === false) { throw new \RuntimeException('Failed to require the generated files'); }