#!/usr/bin/env php generate(); } catch (GenerationError $e) { foreach ($e->errors as $error) { fwrite(STDERR, "error: $error\n"); } exit(1); } $problems = []; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($stubsDir, FilesystemIterator::SKIP_DOTS) ); foreach ($iterator as $entry) { if ($entry->isFile() && str_ends_with($entry->getFilename(), '.php')) { $relative = substr($entry->getPathname(), strlen($stubsDir) + 1); if (!isset($files[$relative])) { $problems[] = "stale stub not covered by targets.list: $stubsDir/$relative"; } } } // The Rust side embeds every stub with include_str!; the two lists must not drift apart. $libRsText = (string) file_get_contents($libRs); foreach ($files as $relative => $_) { if (!str_contains($libRsText, "include_str!(\"../php/stubs/$relative\")")) { $problems[] = "STUB_FILES in $libRs does not embed $relative"; } } if ($check) { foreach ($files as $relative => $content) { $current = @file_get_contents("$stubsDir/$relative"); if ($current === false) { $problems[] = "missing stub (regenerate): $stubsDir/$relative"; } elseif ($current !== $content) { $problems[] = "stale stub (regenerate): $stubsDir/$relative"; } } } else { foreach ($files as $relative => $content) { $path = "$stubsDir/$relative"; if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } file_put_contents($path, $content); } fwrite(STDERR, count($files) . " stubs written to $stubsDir\n"); } foreach ($problems as $problem) { fwrite(STDERR, "error: $problem\n"); } exit($problems === [] ? 0 : 1);