From 3226eb40869e46933984bfa41bb7406bced293ac Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 19 Oct 2019 12:28:45 +0200 Subject: [PATCH] Accept KMYACC env var in rebuildParsers.php --- grammar/rebuildParsers.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/grammar/rebuildParsers.php b/grammar/rebuildParsers.php index 9438fd2..ce155e2 100644 --- a/grammar/rebuildParsers.php +++ b/grammar/rebuildParsers.php @@ -13,13 +13,16 @@ $tmpResultFile = __DIR__ . '/tmp_parser.php'; $resultDir = __DIR__ . '/../lib/PhpParser/Parser'; $tokensResultsFile = $resultDir . '/Tokens.php'; -// check for kmyacc binary in this directory, otherwise fall back to global name -if (file_exists(__DIR__ . '/kmyacc.exe')) { - $kmyacc = __DIR__ . '/kmyacc.exe'; -} else if (file_exists(__DIR__ . '/kmyacc')) { - $kmyacc = __DIR__ . '/kmyacc'; -} else { - $kmyacc = 'kmyacc'; +$kmyacc = getenv('KMYACC'); +if (!$kmyacc) { + // Check for kmyacc binary in this directory, otherwise fall back to global name + if (file_exists(__DIR__ . '/kmyacc.exe')) { + $kmyacc = __DIR__ . '/kmyacc.exe'; + } else if (file_exists(__DIR__ . '/kmyacc')) { + $kmyacc = __DIR__ . '/kmyacc'; + } else { + $kmyacc = 'kmyacc'; + } } $options = array_flip($argv); @@ -62,8 +65,7 @@ foreach ($grammarFileToName as $grammarFile => $name) { $additionalArgs = $optionDebug ? '-t -v' : ''; echo "Building $name parser.\n"; - $output = trim(shell_exec("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile 2>&1")); - echo "Output: \"$output\"\n"; + $output = execCmd("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile"); $resultCode = file_get_contents($tmpResultFile); $resultCode = removeTrailingWhitespace($resultCode); @@ -73,8 +75,7 @@ foreach ($grammarFileToName as $grammarFile => $name) { unlink($tmpResultFile); echo "Building token definition.\n"; - $output = trim(shell_exec("$kmyacc -l -m $tokensTemplate $tmpGrammarFile 2>&1")); - assert($output === ''); + $output = execCmd("$kmyacc -m $tokensTemplate $tmpGrammarFile"); rename($tmpResultFile, $tokensResultsFile); if (!$optionKeepTmpGrammar) { @@ -234,6 +235,15 @@ function ensureDirExists($dir) { } } +function execCmd($cmd) { + $output = trim(shell_exec("$cmd 2>&1")); + if ($output !== "") { + echo "> " . $cmd . "\n"; + echo $output; + } + return $output; +} + ////////////////////////////// /// Regex helper functions /// //////////////////////////////