Skip to content

Commit d8dfb21

Browse files
committed
Add support for forcing regeneration of arginfo files
Closes GH-5795
1 parent fe9b5ce commit d8dfb21

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

build/gen_stub.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313
error_reporting(E_ALL);
1414

15-
function processDirectory(string $dir) {
15+
function processDirectory(string $dir, bool $forceRegeneration) {
1616
$it = new RecursiveIteratorIterator(
1717
new RecursiveDirectoryIterator($dir),
1818
RecursiveIteratorIterator::LEAVES_ONLY
1919
);
2020
foreach ($it as $file) {
2121
$pathName = $file->getPathName();
2222
if (preg_match('/\.stub\.php$/', $pathName)) {
23-
processStubFile($pathName);
23+
processStubFile($pathName, $forceRegeneration);
2424
}
2525
}
2626
}
2727

28-
function processStubFile(string $stubFile) {
28+
function processStubFile(string $stubFile, bool $forceRegeneration) {
2929
try {
3030
if (!file_exists($stubFile)) {
3131
throw new Exception("File $stubFile does not exist");
@@ -35,7 +35,7 @@ function processStubFile(string $stubFile) {
3535
$stubCode = file_get_contents($stubFile);
3636
$stubHash = computeStubHash($stubCode);
3737
$oldStubHash = extractStubHash($arginfoFile);
38-
if ($stubHash === $oldStubHash) {
38+
if ($stubHash === $oldStubHash && $forceRegeneration === false) {
3939
/* Stub file did not change, do not regenerate. */
4040
return;
4141
}
@@ -1093,17 +1093,17 @@ function initPhpParser() {
10931093
});
10941094
}
10951095

1096-
if ($argc >= 2) {
1097-
if (is_file($argv[1])) {
1098-
// Generate single file.
1099-
processStubFile($argv[1]);
1100-
} else if (is_dir($argv[1])) {
1101-
processDirectory($argv[1]);
1102-
} else {
1103-
echo "$argv[1] is neither a file nor a directory.\n";
1104-
exit(1);
1105-
}
1096+
$optind = null;
1097+
$options = getopt("f", ["force-regeneration"], $optind);
1098+
$forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
1099+
$location = $argv[$optind + 1] ?? ".";
1100+
1101+
if (is_file($location)) {
1102+
// Generate single file.
1103+
processStubFile($location, $forceRegeneration);
1104+
} else if (is_dir($location)) {
1105+
processDirectory($location, $forceRegeneration);
11061106
} else {
1107-
// Regenerate all stub files we can find.
1108-
processDirectory('.');
1107+
echo "$location is neither a file nor a directory.\n";
1108+
exit(1);
11091109
}

0 commit comments

Comments
 (0)