Skip to content
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

gen_stub: various simplifications and clean up (3) #17886

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
39 changes: 17 additions & 22 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
PHP_85_VERSION_ID,
];

// file_put_contents() but with a success message printed after saving
function report_file_put_contents(string $filename, string $content) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function reportFilePutContents(string $filename, string $content): void {

or something similar

if (file_put_contents($filename, $content)) {
echo "Saved $filename\n";
}
}

/**
* @return FileInfo[]
*/
Expand Down Expand Up @@ -121,8 +128,8 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
$context->allConstInfos,
$stubHash
);
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($arginfoFile, $arginfoCode)) {
echo "Saved $arginfoFile\n";
if ($context->forceRegeneration || $stubHash !== $oldStubHash) {
report_file_put_contents($arginfoFile, $arginfoCode);
}

if ($fileInfo->shouldGenerateLegacyArginfo()) {
Expand All @@ -146,8 +153,8 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
$context->allConstInfos,
$stubHash
);
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($legacyFile, $arginfoCode)) {
echo "Saved $legacyFile\n";
if ($context->forceRegeneration || $stubHash !== $oldStubHash) {
report_file_put_contents($legacyFile, $arginfoCode);
}
}

Expand Down Expand Up @@ -6289,9 +6296,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc

if ($replacePredefinedConstants) {
foreach ($predefinedConstants as $filename => $content) {
if (file_put_contents($filename, $content)) {
echo "Saved $filename\n";
}
report_file_put_contents($filename, $content);
}
}
}
Expand All @@ -6306,9 +6311,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
}

foreach ($classSynopses as $filename => $content) {
if (file_put_contents("$classSynopsesDirectory/$filename", $content)) {
echo "Saved $filename\n";
}
report_file_put_contents("$classSynopsesDirectory/$filename", $content);
}
}
}
Expand All @@ -6318,9 +6321,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc

if ($replaceClassSynopses) {
foreach ($classSynopses as $filename => $content) {
if (file_put_contents($filename, $content)) {
echo "Saved $filename\n";
}
report_file_put_contents($filename, $content);
}
}
}
Expand All @@ -6339,9 +6340,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
mkdir(dirname($path));
}

if (file_put_contents($path, $content)) {
echo "Saved $filename\n";
}
report_file_put_contents($path, $content);
}
}
}
Expand All @@ -6351,9 +6350,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc

if ($replaceMethodSynopses) {
foreach ($methodSynopses as $filename => $content) {
if (file_put_contents($filename, $content)) {
echo "Saved $filename\n";
}
report_file_put_contents($filename, $content);
}
}
}
Expand All @@ -6362,9 +6359,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
$filename = dirname(__FILE__, 2) . "/Zend/Optimizer/zend_func_infos.h";
$optimizerInfo = generateOptimizerInfo($funcMap);

if (file_put_contents($filename, $optimizerInfo)) {
echo "Saved $filename\n";
}
report_file_put_contents($filename, $optimizerInfo);
}

if ($verifyManual) {
Expand Down