From 60a33af3c40221c007418c17e2d270fa06e7c26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 31 Oct 2023 11:54:12 +0100 Subject: [PATCH] Fix validation of CLI arguments when a target manual directory has to be provided Additionally, let's make sure that we don't try to process the stub files in the manual target directory. This comes with a slight performance benefit. --- build/gen_stub.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 2747c53d486..eaf4af0a6ac 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -5143,23 +5143,33 @@ $generateOptimizerInfo = isset($options["generate-optimizer-info"]); $context->forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]); $context->forceParse = $context->forceRegeneration || $printParameterStats || $verify || $verifyManual || $replacePredefinedConstants || $generateClassSynopses || $generateOptimizerInfo || $replaceClassSynopses || $generateMethodSynopses || $replaceMethodSynopses; -$manualTarget = $argv[$argc - 1] ?? null; -if (($replacePredefinedConstants || $verifyManual) && $manualTarget === null) { - die("A target manual directory must be provided.\n"); -} -if (($replaceClassSynopses || $verifyManual) && $manualTarget === null) { - die("A target manual directory must be provided.\n"); -} -if (($replaceMethodSynopses || $verifyManual) && $manualTarget === null) { - die("A target manual directory must be provided.\n"); -} - if (isset($options["h"]) || isset($options["help"])) { die("\nUsage: gen_stub.php [ -f | --force-regeneration ] [ --replace-predefined-constants ] [ --generate-classsynopses ] [ --replace-classsynopses ] [ --generate-methodsynopses ] [ --replace-methodsynopses ] [ --parameter-stats ] [ --verify ] [ --verify-manual ] [ --generate-optimizer-info ] [ -h | --help ] [ name.stub.php | directory ] [ directory ]\n\n"); } +$locations = array_slice($argv, $optind); +$locationCount = count($locations); +if ($replacePredefinedConstants && $locationCount < 2) { + die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-predefined-constants ./ ../doc-en/\n"); +} +if ($replaceClassSynopses && $locationCount < 2) { + die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-classsynopses ./ ../doc-en/\n"); +} +if ($replaceMethodSynopses && $locationCount < 2) { + die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-methodsynopses ./ ../doc-en/\n"); +} +if ($verifyManual && $locationCount < 2) { + die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --verify-manual ./ ../doc-en/\n"); +} +$manualTarget = null; +if ($replacePredefinedConstants || $replaceClassSynopses || $replaceMethodSynopses || $verifyManual) { + $manualTarget = array_pop($locations); +} +if ($locations === []) { + $locations = ['.']; +} + $fileInfos = []; -$locations = array_slice($argv, $optind) ?: ['.']; foreach (array_unique($locations) as $location) { if (is_file($location)) { // Generate single file.