Skip to content

Add support for forcing regeneration of arginfo files #5795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

error_reporting(E_ALL);

function processDirectory(string $dir) {
function processDirectory(string $dir, bool $forceRegeneration) {
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($it as $file) {
$pathName = $file->getPathName();
if (preg_match('/\.stub\.php$/', $pathName)) {
processStubFile($pathName);
processStubFile($pathName, $forceRegeneration);
}
}
}

function processStubFile(string $stubFile) {
function processStubFile(string $stubFile, bool $forceRegeneration) {
try {
if (!file_exists($stubFile)) {
throw new Exception("File $stubFile does not exist");
Expand All @@ -35,7 +35,7 @@ function processStubFile(string $stubFile) {
$stubCode = file_get_contents($stubFile);
$stubHash = computeStubHash($stubCode);
$oldStubHash = extractStubHash($arginfoFile);
if ($stubHash === $oldStubHash) {
if ($stubHash === $oldStubHash && $forceRegeneration === false) {
/* Stub file did not change, do not regenerate. */
return;
}
Expand Down Expand Up @@ -1093,17 +1093,17 @@ function initPhpParser() {
});
}

if ($argc >= 2) {
if (is_file($argv[1])) {
// Generate single file.
processStubFile($argv[1]);
} else if (is_dir($argv[1])) {
processDirectory($argv[1]);
} else {
echo "$argv[1] is neither a file nor a directory.\n";
exit(1);
}
$optind = null;
$options = getopt("f", ["force-regeneration"], $optind);
$forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
$location = $argv[$optind + 1] ?? ".";

if (is_file($location)) {
// Generate single file.
processStubFile($location, $forceRegeneration);
} else if (is_dir($location)) {
processDirectory($location, $forceRegeneration);
} else {
// Regenerate all stub files we can find.
processDirectory('.');
echo "$location is neither a file nor a directory.\n";
exit(1);
}